This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-779]Add DLPack Transformation API #12047
Merged
Merged
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
822706e
add dlpack convertor api
wkcn 8aac3da
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
wkcn ab6fa85
add to_dlpack and from_dlpack for NDArray
wkcn 8c6e9d2
fix dlpack deleter and add unittest for dlpack
wkcn 9fdfa7d
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
wkcn 1142787
update 3rdparty
wkcn 16df8d5
fix for cpplint
wkcn bfcffa2
fix pylint and add destructor for dlpack
wkcn f5c2552
fix pylint in base.py
wkcn 98b5d11
fix lint in base.py
wkcn 7bdde8f
add document for DLPack transformation API
wkcn f225d27
add to_dlpack_for_read and to_dlpack_for_write
wkcn afc1518
fix lint for ndarray.py and fix typo in c_api.h
wkcn 8b397fd
fix function name error in c_api
wkcn d48074a
update code indent in tensor_blob.h ans c_api.cc, remove unused type …
wkcn 58c5d87
use MXNDArrayToDLPack in c_api and add compactness check in TBlob
wkcn 72edbf8
merge master and fix merge conflict
wkcn ef8ffcd
use python function as destructor of DLPack
wkcn afa1898
remove unused PyObjectHandle and update DLDataTypeTransform
wkcn a4d3aee
update from_dlpack code
wkcn 493deb0
fix pylint in ndarray.py
wkcn adf36ef
rename dlpack after using it
wkcn 26db4d0
merge master
wkcn dec838d
DLManagedTensor manages itself
wkcn 850c3dc
add deleter for TBlob and Chunk in NDArray
wkcn fc99323
remove used code in python/mxnet/base.py
wkcn ffe60c6
retrigger CI
wkcn cbb17c3
add deleter for shared_ptr<Chunk>
wkcn e56be1f
Merge branch 'master' into DLPack-convertor-API
wkcn b1204bc
compilation okay
wkcn fe1387f
fix cpplint
wkcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,10 @@ | |
|
||
class NDArrayBase(object): | ||
"""Base data structure for ndarray""" | ||
__slots__ = ["handle", "writable"] | ||
__slots__ = ["handle", "writable", "dlpack_handle"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not put dlpack_handle inside it, instead directly return a pycapsule that contains the handle |
||
# pylint: disable= no-member | ||
|
||
def __init__(self, handle, writable=True): | ||
def __init__(self, handle, writable=True, dlpack_handle=None): | ||
"""initialize a new NDArray | ||
|
||
Parameters | ||
|
@@ -46,9 +46,12 @@ def __init__(self, handle, writable=True): | |
assert isinstance(handle, NDArrayHandle) | ||
self.handle = handle | ||
self.writable = writable | ||
self.dlpack_handle = dlpack_handle | ||
|
||
def __del__(self): | ||
check_call(_LIB.MXNDArrayFree(self.handle)) | ||
if self.dlpack_handle is not None: | ||
check_call(_LIB.MXNDArrayCallDLPackDeleter(self.dlpack_handle)) | ||
|
||
def __reduce__(self): | ||
return (_ndarray_cls, (None,), self.__getstate__()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ cdef class NDArrayBase: | |
# handle for symbolic operator. | ||
cdef NDArrayHandle chandle | ||
cdef int cwritable | ||
cdef DLPackHandle cdlpack_handle | ||
|
||
cdef _set_handle(self, handle): | ||
cdef unsigned long long ptr | ||
|
@@ -52,12 +53,15 @@ cdef class NDArrayBase: | |
def __get__(self): | ||
return bool(self.cwritable) | ||
|
||
def __init__(self, handle, writable=True): | ||
def __init__(self, handle, writable=True, dlpack_handle=None): | ||
self._set_handle(handle) | ||
self.cwritable = writable | ||
self.cdlpack_handle = dlpack_handle | ||
|
||
def __dealloc__(self): | ||
CALL(MXNDArrayFree(self.chandle)) | ||
if self.cdlpack_handle: | ||
CALL(MXNDArrayCallDLPackDeleter(self.cdlpack_handle)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not put dlpack_handle inside the object |
||
|
||
def __reduce__(self): | ||
return (_ndarray_cls, (None,), self.__getstate__()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add compactness check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, TBlob only support compact tensors, need to check strides == null or the strides reflect a compact setting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I will move the strides check from ndarray.cpp to tensor_blob.h.