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] add necessary const qualifier for NDArray container of function parameters #4590

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ typedef DLDataType TVMType;
typedef DLContext TVMContext;

/*!
* \brief The tensor array stucture to TVM API.
* \brief The tensor array structure to TVM API.
*/
typedef DLTensor TVMArray;

Expand Down
14 changes: 7 additions & 7 deletions include/tvm/runtime/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class NDArray {
* \note The copy may happen asynchrously if it involves a GPU context.
* TVMSynchronize is necessary.
*/
inline void CopyFrom(DLTensor* other);
inline void CopyFrom(const DLTensor* other);
inline void CopyFrom(const NDArray& other);
/*!
* \brief Copy data content into another array.
Expand Down Expand Up @@ -188,7 +188,7 @@ class NDArray {
* \param stream The stream used in copy.
*/
TVM_DLL static void CopyFromTo(
DLTensor* from, DLTensor* to, TVMStreamHandle stream = nullptr);
const DLTensor* from, DLTensor* to, TVMStreamHandle stream = nullptr);

TVM_DLL std::vector<int64_t> Shape() const;

Expand Down Expand Up @@ -228,7 +228,7 @@ struct array_type_info<NDArray> {
* \param strm The outpu stream
* \param tensor The tensor to be saved.
*/
inline bool SaveDLTensor(dmlc::Stream* strm, DLTensor* tensor);
inline bool SaveDLTensor(dmlc::Stream* strm, const DLTensor* tensor);

/*!
* \brief Reference counted Container object used to back NDArray.
Expand Down Expand Up @@ -369,7 +369,7 @@ inline size_t GetDataSize(const DLTensor& arr) {
return size;
}

inline void NDArray::CopyFrom(DLTensor* other) {
inline void NDArray::CopyFrom(const DLTensor* other) {
CHECK(data_ != nullptr);
CopyFromTo(other, &(data_->dl_tensor));
}
Expand Down Expand Up @@ -413,7 +413,7 @@ inline const DLTensor* NDArray::operator->() const {
constexpr uint64_t kTVMNDArrayMagic = 0xDD5E40F096B4A13F;

inline bool SaveDLTensor(dmlc::Stream* strm,
DLTensor* tensor) {
const DLTensor* tensor) {
uint64_t header = kTVMNDArrayMagic, reserved = 0;
strm->Write(header);
strm->Write(reserved);
Expand Down Expand Up @@ -451,7 +451,7 @@ inline bool SaveDLTensor(dmlc::Stream* strm,
} else {
std::vector<uint8_t> bytes(data_byte_size);
CHECK_EQ(TVMArrayCopyToBytes(
tensor, dmlc::BeginPtr(bytes), data_byte_size), 0)
const_cast<DLTensor*>(tensor), dmlc::BeginPtr(bytes), data_byte_size), 0)
<< TVMGetLastError();
if (!DMLC_IO_NO_ENDIAN_SWAP) {
dmlc::ByteSwap(dmlc::BeginPtr(bytes), type_bytes, num_elems);
Expand All @@ -462,7 +462,7 @@ inline bool SaveDLTensor(dmlc::Stream* strm,
}

inline void NDArray::Save(dmlc::Stream* strm) const {
SaveDLTensor(strm, const_cast<DLTensor*>(operator->()));
SaveDLTensor(strm, operator->());
}

inline bool NDArray::Load(dmlc::Stream* strm) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ NDArray NDArray::FromDLPack(DLManagedTensor* tensor) {
return NDArray(data);
}

void NDArray::CopyFromTo(DLTensor* from,
void NDArray::CopyFromTo(const DLTensor* from,
DLTensor* to,
TVMStreamHandle stream) {
size_t from_size = GetDataSize(*from);
Expand Down