quic-sanirudh commented on code in PR #15178:
URL: https://github.com/apache/tvm/pull/15178#discussion_r1247996799


##########
src/runtime/relax_vm/nd_allocator.h:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tvm/runtime/relax_vm/nd_allocator.h
+ */
+#ifndef TVM_RUNTIME_RELAX_VM_ND_ALLOCATOR_H_
+#define TVM_RUNTIME_RELAX_VM_ND_ALLOCATOR_H_
+
+#include <tvm/runtime/device_api.h>
+#include <tvm/runtime/relax_vm/memory_manager.h>
+
+#include <atomic>
+
+namespace tvm {
+namespace runtime {
+namespace relax_vm {
+
+class NDAllocator final : public Allocator {
+ public:
+  explicit NDAllocator(Device dev) : Allocator(kNd), used_memory_(0), 
device_(dev) {}
+
+  Buffer Alloc(ShapeTuple shape, DLDataType type_hint, String mem_scope) 
override {
+    DLTensor temp;
+    temp.data = nullptr;
+    temp.device = device_;
+    temp.ndim = shape.size();
+    temp.dtype = type_hint;
+    temp.shape = const_cast<int64_t*>(shape.data());
+    temp.strides = nullptr;
+    temp.byte_offset = 0;
+    size_t nbytes = GetDataSize(temp);
+
+    Buffer buf;
+    buf.device = device_;
+    buf.size = nbytes;
+    buf.data = runtime::DeviceAPI::Get(device_)->AllocDataSpace(device_, 
shape.size(), shape.data(),
+                                                                type_hint, 
mem_scope);
+    used_memory_.fetch_add(nbytes, std::memory_order_relaxed);
+    DLOG(INFO) << "allocate " << nbytes << " B, used memory " << used_memory_ 
<< " B";
+    return buf;
+  }
+
+  Buffer Alloc(size_t nbytes, size_t alignment, DLDataType type_hint) override 
{
+    Buffer buf;
+    buf.device = device_;

Review Comment:
   Could you please explain a little bit about this comment. Are you suggesting 
that we don't implement this version and just redirect to the naive allocator 
version?
   
   I can perhaps have this version of `Alloc` directly implemented in the base 
class and just call that version for both here and in the 
`NaiveAllocator::Alloc`. But that would mean that the `Alloc` virtual function 
would no longer be a pure virtual function, and I wasn't sure if it was okay to 
do that.



-- 
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