adstraw commented on a change in pull request #10558:
URL: https://github.com/apache/tvm/pull/10558#discussion_r825151649
##########
File path: src/runtime/hexagon/hexagon/hexagon_device_api_v2.cc
##########
@@ -163,6 +170,63 @@
TVM_REGISTER_GLOBAL("device_api.hexagon.mem_copy").set_body([](TVMArgs args, TVM
*rv = static_cast<int32_t>(0);
});
+std::map<void*, HexagonBuffer*> vtcmallocs;
+
+TVM_REGISTER_GLOBAL("device_api.hexagon.AllocNd").set_body([](TVMArgs args,
TVMRetValue* rv) {
+ int32_t device_type = args[0];
+ int32_t device_id = args[1];
+ int32_t dtype_code_hint = args[2];
+ int32_t dtype_bits_hint = args[3];
+ std::string scope = args[4];
+ CHECK(scope.find("vtcm") != std::string::npos);
+ int64_t ndim = args[5];
+ // Forcing contiguous allocation, for now
+ // TODO(Straw): Enable discontiguous allocation after RFC 39 lands
+ CHECK_EQ(ndim, 1);
+ std::vector<int64_t> shape;
+ for (int i = 0; i < ndim; ++i) {
+ shape.push_back(args[6 + i]);
+ }
+
+ Device dev;
+ dev.device_type = static_cast<DLDeviceType>(device_type);
+ dev.device_id = device_id;
+
+ DLDataType type_hint;
+ type_hint.code = static_cast<decltype(type_hint.code)>(dtype_code_hint);
+ type_hint.bits = static_cast<decltype(type_hint.bits)>(dtype_bits_hint);
+ type_hint.lanes = 1;
+
+ HexagonDeviceAPIv2* hexapi = HexagonDeviceAPIv2::Global();
+ HexagonBuffer* hexbuf = reinterpret_cast<HexagonBuffer*>(
+ hexapi->AllocVtcmWorkspace(dev, ndim, shape.data(), type_hint,
String(scope)));
+
+ // Assumes a single contiguous allocation
+ // TODO(Straw): Enable discontiguous allocation after RFC 39 lands
+ void* ptr = hexbuf->GetPointer()[0];
+ vtcmallocs[ptr] = hexbuf;
+ *rv = ptr;
+});
+
+TVM_REGISTER_GLOBAL("device_api.hexagon.FreeNd").set_body([](TVMArgs args,
TVMRetValue* rv) {
Review comment:
Same comment as above.
--
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]