Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RUNTIME] Enable NDArray type extension #2598

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions include/tvm/runtime/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace runtime {
class NDArray {
public:
// internal container type
struct Container;
class Container;
/*! \brief default constructor */
NDArray() {}
/*!
Expand Down Expand Up @@ -173,7 +173,7 @@ class NDArray {

// internal namespace
struct Internal;
private:
protected:
/*! \brief Internal Data content */
Container* data_{nullptr};
// enable internal functions
Expand All @@ -198,7 +198,7 @@ inline bool SaveDLTensor(dmlc::Stream* strm, const DLTensor* tensor);
*
* \note: do not use this function directly, use NDArray.
*/
struct NDArray::Container {
class NDArray::Container {
public:
// NOTE: the first part of this structure is the same as
// DLManagedTensor, note that, however, the deleter
Expand All @@ -225,6 +225,28 @@ struct NDArray::Container {
* currently defined by the system.
*/
void (*deleter)(Container* self) = nullptr;

protected:
friend class NDArray;
friend class RPCWrappedFunc;
/*!
* \brief Type flag used to indicate subclass.
* Default value 0 means normal NDArray::Conatainer.
*
* We can extend a more specialized NDArray::Container
* and use the array_type_index_ to indicate
* the specific array subclass.
*/
uint32_t array_type_index_{0};
/*! \brief The internal reference counter */
std::atomic<int> ref_counter_{0};
/*!
* \brief The shape container,
* can be used used for shape data.
*/
std::vector<int64_t> shape_;

public:
/*! \brief default constructor */
Container() {
dl_tensor.data = nullptr;
Expand All @@ -246,17 +268,6 @@ struct NDArray::Container {
}
}
}

private:
friend class NDArray;
friend class RPCWrappedFunc;
/*!
* \brief The shape container,
* can be used used for shape data.
*/
std::vector<int64_t> shape_;
/*! \brief The internal array object */
std::atomic<int> ref_counter_{0};
};

// implementations of inline functions
Expand Down