Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add boolean ndarray #15940

Merged
merged 4 commits into from Oct 8, 2019
Merged

Add boolean ndarray #15940

merged 4 commits into from Oct 8, 2019

Conversation

reminisce
Copy link
Contributor

@reminisce reminisce commented Aug 19, 2019

Description

  • Added boolean ndarray infra in mshadow.
  • Implemented comparison operators: equal, not_equal, greater, greater_equal, less, and less_equal to use np.bool_ as their output tensors' dtype.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Comments

Follow-up work includes:

  • More operators that can consume boolean ndarrays. To list a few that must be finished before the next release:
    • sum
    • cast
    • boolean_mask
  • ndarray boolean indexing

Thank @yzhliu @hzfan for the help on debugging.

values[0].v_handle = const_cast<DLTensor*>(&(tblobs[0].dltensor()));

// scalar param
type_codes[1] = kDLFloat;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yzhliu Since I need to pass a double param to the op func generated by TVM, I cannot use the Call function defined in the TVMOpModule. I moved the logic of preparing TVMArgs up here from the Call function to MXNet op's FCompute function and added an independent CallEx in TVMOpModule to just invoke the kernel. We can discuss the change of the API to cater for more use cases.

@reminisce reminisce added this to In progress in numpy via automation Aug 19, 2019
@reminisce reminisce force-pushed the add_boolean_ndarray branch 2 times, most recently from 4b372cc to 595e2f7 Compare August 28, 2019 06:22
@reminisce reminisce force-pushed the add_boolean_ndarray branch 2 times, most recently from 88e63b4 to 127b036 Compare September 26, 2019 21:49
@reminisce reminisce force-pushed the add_boolean_ndarray branch 2 times, most recently from d7f2963 to 327e0f7 Compare October 2, 2019 22:06
Makefile Outdated
@@ -473,11 +473,13 @@ CFLAGS += -I$(TVM_PATH)/include -DMXNET_USE_TVM_OP=1
LDFLAGS += -L$(ROOTDIR)/lib -ltvm_runtime -Wl,-rpath,'$${ORIGIN}'

TVM_USE_CUDA := OFF
TVM_OP_CUDA_ARCH := NONE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason you are introducing a second set instead of using the arch set variable we already have? In which use case would these two differ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted. Thanks for the suggestion.

numpy automation moved this from In progress to Needs review Oct 3, 2019
__macro$(__VA_ARGS__, int32_t); \
__macro$(__VA_ARGS__, int64_t); \
__macro$(__VA_ARGS__, bool)

#define IMPLEMENT_WORKLOAD_VALUE_FOR_TYPE(__op$, __typ$) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a comment to this macro to clarify?

@@ -240,27 +236,38 @@ def is_int(dtype):
in_data_dim = random.choice([2, 3, 4])
shape = rand_shape_nd(in_data_dim, dim=3)
acc_type = {'float16': 'float32', 'float32': 'float64', 'float64': 'float64',
'int8': 'int32', 'int32': 'int64', 'int64': 'int64'}
'int8': 'int32', 'int32': 'int64', 'int64': 'int64', 'bool': 'int64'}
for hybridize in [False, True]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would using https://docs.python.org/3.7/library/itertools.html#itertools.product help readability of the code and make it less nested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Will consider refactoring it in the following PRs.

numpy automation moved this from Needs review to Reviewer approved Oct 5, 2019
Copy link
Contributor

@marcoabreu marcoabreu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve for build system

Add np.equal implemented using tvmop

Fix setting DLDataType conversion for boolean ndarray

Add equal_gpu

Fix inputs with different ndims

Fix copying boolean ndarrays across devices

Refactor binary logic op impl by tvm

Add more logic ops

Refactor TVMOpModule::Call to CallEx

Add binary scalar logic op expr and schedule

Add binary scalar logic ops

Add free functions for logic ops

Rebase with master to fix SetDLTensor bug

Fix pylint

Add sum op for boolean ndarrays using tvm op module

Add sum boolean gpu compute

Add bool type support to boolean_mask

Boolean indexing working

Clean up

Fix merge

Sync Makefile

Rebase

Add boolean indexing test

Fix sanity

Fix gpu and add autograd test

Rebase

Fix test for windows

Fix tests

Try to fix cuda arch missing error in ci

Fix ci

Fix windows build

Try to fix cmake

Fix cmake

Fix

Revert config.mk
Copy link
Contributor

@haojin2 haojin2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@haojin2 haojin2 merged commit 15ea40d into apache:master Oct 8, 2019
numpy automation moved this from Reviewer approved to Done Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
No open projects
numpy
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants