tqchen commented on code in PR #15058: URL: https://github.com/apache/tvm/pull/15058#discussion_r1228228724
########## src/runtime/opencl/memory_pool.cc: ########## @@ -0,0 +1,186 @@ +/* + * 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 memory_pool.h + * \brief OpenCL Workspace pool utility. + */ +#include "memory_pool.h" + +#include <memory> + +#include "opencl_common.h" + +#define ALIGN_UP(num, align) (((num) + ((align)-1)) & ~((align)-1)) + +namespace tvm { +namespace runtime { +namespace cl { + +void* Pool::Alloc(Device dev, DeviceAPI* device, size_t nbytes) { + Entry e; + DLDataType type; + type.code = kDLUInt; + type.bits = 8; + type.lanes = 1; + if (free_list_.size() == 2) { + e = free_list_.back(); + free_list_.pop_back(); + if (e.size < nbytes) { + // resize the page + OpenCLWorkspace::Global()->FreeCLBuffer(dev, e.data); + e.data = OpenCLWorkspace::Global()->AllocCLBuffer(dev, nbytes, kTempAllocaAlignment, type); + e.size = nbytes; Review Comment: Reading the set of changes, I feel we are pushing the memory management logic a bit too into the DeviceAPI and NDArray. I wonder if in this case what we want is an alternative memory allocator. ########## include/tvm/runtime/device_api.h: ########## @@ -124,12 +125,33 @@ class TVM_DLL DeviceAPI { */ virtual void* AllocDataSpace(Device dev, int ndim, const int64_t* shape, DLDataType dtype, Optional<String> mem_scope = NullOpt); + + /*! + * \brief Create a new view with given spec over existing tensor. + * \param dev The device device to perform operation. + * \param data The source array. + * \param ndim The number of dimension of allocated tensor. + * \param shape The shape of allocated tensor. + * \param dtype The type of elements. + * \param mem_scope The memory scope of allocated tensor. + * \return The allocated device pointer. + */ Review Comment: Looking at this set of changes. I feel that maybe we need something different that makes the memory allocator more explicit. Let me elaborate in reply -- 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]
