srkreddy1238 commented on code in PR #14922: URL: https://github.com/apache/tvm/pull/14922#discussion_r1211181219
########## src/runtime/contrib/clml/clml_utils.cc: ########## @@ -0,0 +1,258 @@ +/* + * 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 src/runtime/contrib/clml/clml_utils.cc + * \brief Utilities. + */ +#ifdef TVM_GRAPH_EXECUTOR_CLML +#include "clml_utils.h" + +namespace tvm { +namespace runtime { +namespace contrib { + +using namespace tvm::runtime::json; +using JSONGraphNode = tvm::runtime::json::JSONGraphNode; + +/*! + * \brief Copy utility to CLML Tensor. + * + * \param tensor CLML tensor descriptor + * \param data pointer to host data + * \param layout host data layout + */ +void CopyDataToCLMLTensor(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> tensor, void* data, + cl_ml_tensor_layout_qcom layout) { + cl_int result = 0; + cl_event evt = nullptr; + result = CLML_INTF->clEnqueueWriteMLTensorDataQCOM(CLML_QUEUE, data, layout, tensor->tensor, + tensor->memory, + 0, // n waitlist + nullptr, // waitlist + &evt); // event + ICHECK((evt != nullptr) && result == CL_SUCCESS) << "clEnqueueWriteMLTensorDataQCOM:" << result; +} + +/*! + * \brief Copy utility from CLML tensor. + * + * \param tensor CLML tensor descriptor + * \param data pointer to host data + * \param layout expectred host data layout + */ +void CopyDataFromCLMLTensor(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> tensor, void* data, + cl_ml_tensor_layout_qcom layout) { + cl_int result = 0; + cl_event readEvent = nullptr; + // Read the output tensor + result = CLML_INTF->clEnqueueReadMLTensorDataQCOM(CLML_QUEUE, tensor->tensor, tensor->memory, + data, layout, + 0, // n waitlist + nullptr, // waitlist + &readEvent); // event + ICHECK(result == CL_SUCCESS) << "clEnqueueReadMLTensorDataQCOM:" << result; + + result = clWaitForEvents(1, &readEvent); + ICHECK(result == CL_SUCCESS) << "clWaitForEvents:" << result; +} + +/*! + * \brief Make a CLML tensor given it's attributes + * + * \param context OpenCL context + * \param dims Tensor dimensions + * \param layout CLML tensor layout of tensor + * \param dtype Tensor data type + * \return CLML tensor + */ +cl_ml_tensor_qcom DeviceMakeCLMLTensor(cl_context context, tensor_dims_t dims, + cl_ml_tensor_layout_qcom layout, cl_channel_type dtype) { + cl_ml_tensor_qcom tensor; + cl_int result = CL_OUT_OF_RESOURCES; + + cl_ml_tensor_desc_qcom desc = { + dtype, layout, dims.n, dims.c, dims.h, dims.w, 0, CL_TENSOR_DIMENSIONS_4D_QCOM, {0}}; + result = CLML_INTF->clCreateMLTensorQCOM(CLML_CTX, nullptr, &desc, &tensor); + ICHECK(tensor && result == CL_SUCCESS) << "clCreateMLTensorQCOM:" << result; + (void)result; Review Comment: typo . Removing. -- 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]
