From 07679d9850ede328f477a07ee97e2439f735bf23 Mon Sep 17 00:00:00 2001 From: Janet Schneider Date: Thu, 23 Mar 2023 08:11:53 -0700 Subject: [PATCH 1/2] [Hexagon] Allow scalar tensors to have null shape during allocation. --- src/runtime/hexagon/hexagon_device_api.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/hexagon/hexagon_device_api.cc b/src/runtime/hexagon/hexagon_device_api.cc index 16e67aa9650f..27e4eb29cc7a 100644 --- a/src/runtime/hexagon/hexagon_device_api.cc +++ b/src/runtime/hexagon/hexagon_device_api.cc @@ -52,7 +52,7 @@ void HexagonDeviceAPI::GetAttr(Device dev, DeviceAttrKind kind, TVMRetValue* rv) // DataSpace: static allocations for Hexagon void* HexagonDeviceAPI::AllocDataSpace(Device dev, int ndim, const int64_t* shape, DLDataType dtype, Optional mem_scope) { - CHECK(shape) << "shape array is null"; + CHECK(shape || ndim == 0) << "shape array is null for a non-scalar tensor, ndim = " << ndim; CHECK(IsValidDevice(dev)) << "dev.device_type: " << dev.device_type; // IMPORTANT NOTE! From 9504ee4fce885bf1ff3b8bccd08eecdeabe6a07e Mon Sep 17 00:00:00 2001 From: Janet Schneider Date: Thu, 23 Mar 2023 08:49:45 -0700 Subject: [PATCH 2/2] Add unit test for new case (scalar and null shape) --- tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc b/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc index 0d193042a950..d7d306ff6568 100644 --- a/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc +++ b/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc @@ -134,6 +134,9 @@ TEST_F(HexagonDeviceAPITest, alloc_scalar) { void* hexscalar = hexapi->AllocDataSpace(hex_dev, 0, new int64_t, int8, global_vtcm_scope); CHECK(hexscalar != nullptr); + + hexscalar = hexapi->AllocDataSpace(hex_dev, 0, nullptr, int8, global_vtcm_scope); + CHECK(hexscalar != nullptr); } // alloc and free of the same buffer on different devices should throw