adstraw commented on a change in pull request #9525:
URL: https://github.com/apache/tvm/pull/9525#discussion_r751661227



##########
File path: src/runtime/hexagon/hexagon/hexagon_buffer.cc
##########
@@ -110,11 +182,77 @@ void HexagonBuffer::SetStorageScope(Optional<String> 
scope) {
   }
 }
 
-HexagonBuffer* IsHexagonBuffer(DLTensor* tensor) {
-  if (TVMDeviceExtType(tensor->device.device_type) == kDLHexagon) {
-    return static_cast<HexagonBuffer*>(tensor->data);
+void HexagonBuffer::CopyTo(void *data, size_t nbytes)
+{
+  CHECK(nbytes_ == nbytes);
+  size_t offset = 0;
+  for (size_t i = 0; i < ndim_; ++i) {
+    CHECK(nbytes / ndim_ == managed_allocations_[i]->nbytes_);
+
+    memcpy(static_cast<char*>(data) + offset,
+           static_cast<const char*>(managed_allocations_[i]->data_),  
+           managed_allocations_[i]->nbytes_);
+
+    offset += managed_allocations_[i]->nbytes_;
+  }
+}
+
+void HexagonBuffer::CopyFrom(void *data, size_t nbytes)
+{
+  CHECK(nbytes_ == nbytes);
+  size_t offset = 0;
+  for (size_t i = 0; i < ndim_; ++i) {
+    CHECK(nbytes / ndim_ == managed_allocations_[i]->nbytes_);
+
+    memcpy(static_cast<char*>(managed_allocations_[i]->data_), 
+           static_cast<const char*>(data) + offset, 
+           managed_allocations_[i]->nbytes_);
+
+    offset += managed_allocations_[i]->nbytes_;
+  }
+}
+
+void HexagonBuffer::CopyFrom(const HexagonBuffer& other)
+{
+  CHECK(nbytes_ == other.nbytes_);
+
+  if(ndim_ == other.ndim_) {
+    for (size_t i = 0; i < ndim_; ++i) {
+      CHECK(managed_allocations_[i]->nbytes_ == 
other.managed_allocations_[i]->nbytes_);
+
+      memcpy(static_cast<char*>(managed_allocations_[i]->data_),
+             static_cast<const char*>(other.managed_allocations_[i]->data_),
+             managed_allocations_[i]->nbytes_);
+    }
+  }
+  else if (ndim_ == 1) {
+    size_t offset = 0;
+    for (size_t i = 0; i < other.ndim_; ++i) {
+      CHECK(nbytes_ / other.ndim_ == other.managed_allocations_[i]->nbytes_);
+
+      memcpy(static_cast<char*>(managed_allocations_[0]->data_) + offset,
+             static_cast<const char*>(other.managed_allocations_[i]->data_),
+             other.managed_allocations_[i]->nbytes_);
+
+      offset += other.managed_allocations_[i]->nbytes_;
+    }
+  }
+  else if (other.ndim_ == 1) {
+    size_t offset = 0;
+    for (size_t i = 0; i < ndim_; ++i) {
+      CHECK(other.nbytes_ / ndim_ == managed_allocations_[i]->nbytes_);
+
+      memcpy(static_cast<char*>(managed_allocations_[i]->data_),
+             static_cast<const char*>(other.managed_allocations_[0]->data_) + 
offset,
+             managed_allocations_[i]->nbytes_);
+
+      offset += managed_allocations_[i]->nbytes_;
+    }
+  }
+  else {
+    // TODO: Add error string

Review comment:
       Will clean this up shortly.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to