Large Index Support for Slice#15593
Conversation
c5705c8 to
a0014ed
Compare
|
@mxnet-label-bot add [pr-work-in-progress] |
| check_call(_LIB.MXNDArrayCreateEx( | ||
| c_array_buf(mx_uint, native_array('I', shape)), | ||
| mx_uint(len(shape)), | ||
| c_array_buf(mx_int64, native_array('q', shape)), |
There was a problem hiding this comment.
need to check python version if 'q' is supported
| #if MXNET_USE_INT64_TENSOR_SIZE == 1 | ||
| return MXNDArrayCreateExInt<int64_t>(shape, ndim, dev_type, dev_id, delay_alloc, dtype, out); | ||
| #else | ||
| return MXNDArrayCreateExInt<int32_t>(shape, ndim, dev_type, dev_id, delay_alloc, dtype, out); |
There was a problem hiding this comment.
It may not work. You can't just cast a mx_int64 pointer to int32_t pointer.
| API_END(); | ||
| } | ||
|
|
||
| int MXNDArrayCreateEx(const mx_int64 *shape, |
There was a problem hiding this comment.
Also you are directly changing this C API which might break other language bindings that use this C API.
| MXNET_DLL int MXNDArrayGetShapeEx(NDArrayHandle handle, | ||
| int *out_dim, | ||
| const int **out_pdata); | ||
| const int64_t **out_pdata); |
There was a problem hiding this comment.
You are directly modifying C API which may break other language bindings. As we have agreed, it may be safer to create additional 64bit APIs instead.
|
|
||
| /*! \brief manually define unsigned int */ | ||
| typedef unsigned int mx_uint; | ||
| typedef int64_t mx_int64; |
There was a problem hiding this comment.
Just a nit but,
As per the comment
/*! \brief manually define unsigned int */
Line
typedef int64_t mx_int64; should be above it I guess, as it is not unsigned.
| * \return 0 when success, -1 when failure happens | ||
| */ | ||
| MXNET_DLL int MXNDArrayCreateEx(const mx_uint *shape, | ||
| MXNET_DLL int MXNDArrayCreateEx(const mx_int64 *shape, |
There was a problem hiding this comment.
Sorry if this is a stupid question, but why are we replacing mx_uint (unsigned) with mx_int64 (signed)?
I would assume shape is always positive, shouldn't it be mx_uint64?
There was a problem hiding this comment.
Two reasons:
(1) According to Google C++ style guide: "Do not use an unsigned type merely to assert that a variable is non-negative." https://google.github.io/styleguide/cppguide.html#Integer_Types
(2) We intentionally changed to int because we may reserve the index -1 for supporting empty tensor.
There was a problem hiding this comment.
Oh. Thank You for the explanation.
8fcde44 to
2d31323
Compare
| } | ||
|
|
||
| int MXNDArrayGetShapeExInt64(NDArrayHandle handle, | ||
| int *out_dim, |
9cebf08 to
fb9540e
Compare
|
|
||
| MXNET_DLL int MXNDArrayGetShapeExInt64(NDArrayHandle handle, | ||
| int *out_dim, | ||
| const int64_t **out_pdata); |
There was a problem hiding this comment.
use mx_int64 to be consistent?
|
@mxnet-label-bot add [pr-awaiting-review] |
ChaiBapchya
left a comment
There was a problem hiding this comment.
Minor changes!
Also, c_api_common.h and c_api_symbolic.cc still use int64_t (simple find for int64_t shows there are 22 places it's being used currently in the PR. Wanted clarity on what's the norm? When to use int64_t and when to use mx_int64? Is it even needed?)
|
@ChaiBapchya mx_uint is used for maintaining consistency with language bindings. For example python uses |
| MXAPIThreadLocalEntry *ret = MXAPIThreadLocalStore::Get(); | ||
| API_BEGIN(); | ||
| template<typename dtype, typename stype, typename itype> | ||
| inline void SymbolInferShapeImpl(const char** keys, |
There was a problem hiding this comment.
Also renaming this to SymbolInferShape if you are renaming others too.
| const int **aux_shape_ndim, | ||
| const int64_t ***aux_shape_data, | ||
| int *complete) { | ||
| int succ; |
961de43 to
124a282
Compare
|
@mxnet-label-bot add[pr-awaiting-merge] |
| _NDARRAY_ADVANCED_INDEXING = 1 | ||
|
|
||
| # Caching whether MXNet was built with INT64 support or not | ||
| _INT64_TENSOR_SIZE_ENABLED = Features().is_enabled('INT64_TENSOR_SIZE') |
There was a problem hiding this comment.
This is still not efficient as Features() is still called everytime this variable is evaluated. There is no const variable in Python as in C++
e5e382a to
458b1ae
Compare
7c9f02b to
7ca3d32
Compare
7ca3d32 to
1d4f263
Compare
| const mx_int64 **out_pdata) { | ||
| MXAPIThreadLocalEntry<int64_t> *ret = MXAPIThreadLocalStore<int64_t>::Get(); | ||
| API_BEGIN(); | ||
| GetShape<mx_int64>(handle, out_pdata, out_dim, ret); |
There was a problem hiding this comment.
mx_int64 and int64_t are mixed here. Please consolidate them in your next PR.
Description
Ops Supported: Slice
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.