Skip to content

Commit

Permalink
[RUNTIME] Enable NDArray type extension (apache#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored and libing4752 committed Feb 18, 2019
1 parent 843c6ce commit f58a397
Showing 1 changed file with 25 additions and 14 deletions.
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

0 comments on commit f58a397

Please sign in to comment.