Skip to content

Commit

Permalink
* version compatilibility changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
srkreddy1238 committed Dec 29, 2022
1 parent 32ce3bf commit e84da6b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
12 changes: 11 additions & 1 deletion cmake/modules/contrib/CLML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ if(USE_CLML)
if(NOT USE_CLML_GRAPH_EXECUTOR)
list(APPEND COMPILER_SRCS ${CLML_RUNTIME_MODULE})
endif()
message(STATUS "Build with CLML support...")
message(STATUS "Build with CLML support : " ${USE_CLML})
if (NOT USE_CLML STREQUAL "ON")
set(CLML_VERSION_HEADER "${USE_CLML}/CL/cl_qcom_ml_ops.h")
file(READ ${CLML_VERSION_HEADER} ver)
string(REGEX MATCH "CL_QCOM_ML_OPS_H_MAJOR_VERSION ([0-9]*)" _ ${ver})
set(CLML_VERSION_MAJOR ${CMAKE_MATCH_1})
else()
set(CLML_VERSION_MAJOR "2")
endif()
add_definitions(-DTVM_CLML_VERSION=${CLML_VERSION_MAJOR})
message(STATUS "CLML SDK Version :" ${CLML_VERSION_MAJOR})
endif()

if(USE_CLML_GRAPH_EXECUTOR)
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/relay/op/contrib/clml.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
from ..strategy.generic import is_depthwise_conv2d


def clml_sdk_version():
"""Utility function to get clml version version"""

return tvm.support.libinfo().get("TVM_CLML_VERSION", 2)


def is_clml_runtime_enabled():
"""Check if the CLML graph runtime is present.
Expand Down
32 changes: 21 additions & 11 deletions src/runtime/contrib/clml/clml_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,23 @@ class CLMLRuntime : public JSONRuntimeBase {
ICHECK(result == CL_SUCCESS) << "clQueryMLInterfaceVersionsQCOM:" << result;

for (cl_uint i = 0; i < numVersions; ++i) {
#if CL_QCOM_ML_OPS_H_MAJOR_VERSION == 2
if (majorVersions[i] == 2) {
LOG(WARNING) << "CLML Version Selected:" << majorVersions[i] << " : " << majorVersions[i];
h_ClmlIntf = clGetMLInterfaceV2QCOM(0);
ICHECK(h_ClmlIntf != NULL) << "clGetMLInterfaceV2QCOM:" << result;
LOG(WARNING) << "CLML Target version:" << majorVersions[i];
break;
}
#endif
#if CL_QCOM_ML_OPS_H_MAJOR_VERSION == 3
if (majorVersions[i] == 3) {
h_ClmlIntf = clGetMLInterfaceV3QCOM(0);
LOG(WARNING) << "CLML Target version:" << majorVersions[i];
break;
}
#endif
}
ICHECK(h_ClmlIntf != NULL) << "clGetMLInterfaceVxQCOM:" << result
<< " Perhaps there is mispatch between CLML SDK version to target supported version";
char* tune_flag;
if ((tune_flag = getenv("CLML_IS_TUNNING_RUN")))
this->is_tuning_run = std::stoi(tune_flag);
Expand Down Expand Up @@ -523,16 +533,15 @@ class CLMLRuntime : public JSONRuntimeBase {
}

cl_ml_tensor_qcom DeviceMakeCLMLTensor(
void* pClmlIntf, cl_context context, tensor_dims_t dims,
cl_context context, tensor_dims_t dims,
cl_ml_tensor_layout_qcom layout = CL_TENSOR_LAYOUT_OPTIMAL_QCOM,
cl_channel_type dtype = CL_FLOAT) {
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 }};
CLMLInterfaceV2QCOM* clmlIntf = reinterpret_cast<CLMLInterfaceV2QCOM*>(pClmlIntf);
result = clmlIntf->clCreateMLTensorQCOM(workspace->context, NULL, &desc, &tensor);
result = h_ClmlIntf->clCreateMLTensorQCOM(workspace->context, NULL, &desc, &tensor);
ICHECK(tensor && result == CL_SUCCESS) << "clCreateMLTensorQCOM:" << result;
(void)result;
return tensor;
Expand All @@ -544,9 +553,8 @@ class CLMLRuntime : public JSONRuntimeBase {
cl_int result = CL_OUT_OF_HOST_MEMORY;
cl_mem buffer = NULL;

CLMLInterfaceV2QCOM* clmlIntf = reinterpret_cast<CLMLInterfaceV2QCOM*>(pClmlIntf);
result =
clmlIntf->clGetMLTensorMemorySizeQCOM(workspace->context, pTensorMemDesc->tensor, &size);
h_ClmlIntf->clGetMLTensorMemorySizeQCOM(workspace->context, pTensorMemDesc->tensor, &size);
ICHECK(result == CL_SUCCESS) << "clGetMLTensorMemorySizeQCOM:" << result;

buffer = clCreateBuffer(workspace->context, CL_MEM_READ_WRITE, size, NULL, &result);
Expand Down Expand Up @@ -612,8 +620,7 @@ class CLMLRuntime : public JSONRuntimeBase {
cl_channel_type cl_dtype = MakeCLDataType(tvm_dtype);

auto tensor_dsc = std::make_shared<cl_ml_tensor_memory_desc_qcom>();
tensor_dsc->tensor =
DeviceMakeCLMLTensor(h_ClmlIntf, workspace->context, dims, layout, cl_dtype);
tensor_dsc->tensor = DeviceMakeCLMLTensor(workspace->context, dims, layout, cl_dtype);
return tensor_dsc;
}

Expand Down Expand Up @@ -901,7 +908,6 @@ class CLMLRuntime : public JSONRuntimeBase {
auto input = MakeCLMLTensorFromJSONEntry(node.GetInputs()[0], {}, CL_TENSOR_LAYOUT_OPTIMAL_QCOM,
cl_dtype);
auto output = MakeCLMLTensorFromJSONNode(node, CL_TENSOR_LAYOUT_OPTIMAL_QCOM, cl_dtype);
auto in_dims = get_tensor_dims(nodes_[node.GetInputs()[0].id_]);

std::vector<std::string> windows = node.GetAttr<std::vector<std::string>>("pool_size");
std::vector<std::string> strides = node.GetAttr<std::vector<std::string>>("strides");
Expand Down Expand Up @@ -1103,7 +1109,6 @@ class CLMLRuntime : public JSONRuntimeBase {
cl_channel_type cl_dtype = MakeCLDataType(tvm_dtype);
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(cl_dtype);
int inputSize = input_.size();
int axis = std::stoi(node.GetAttr<std::vector<std::string>>("axis")[0]);
auto output = MakeCLMLTensorFromJSONNode(node, CL_TENSOR_LAYOUT_OPTIMAL_QCOM, cl_dtype);
cl_ml_tensor_qcom* concatInputs = new cl_ml_tensor_qcom[inputSize];
for (int i = 0; i < inputSize; i++) {
Expand Down Expand Up @@ -1262,7 +1267,12 @@ class CLMLRuntime : public JSONRuntimeBase {

CachedLayer layer_;
// CLML Context
#if CL_QCOM_ML_OPS_H_MAJOR_VERSION == 2
CLMLInterfaceV2QCOM* h_ClmlIntf = NULL;
#endif
#if CL_QCOM_ML_OPS_H_MAJOR_VERSION == 3
CLMLInterfaceV3QCOM* h_ClmlIntf = NULL;
#endif
cl::OpenCLWorkspace* workspace = NULL;
cl::OpenCLThreadEntry* tentry = NULL;
cl_ml_tuningcache_qcom tuning_cache = NULL;
Expand Down
5 changes: 4 additions & 1 deletion tests/python/contrib/test_clml/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ def test_conv2d(device, dtype):

@pytest.mark.parametrize("dtype", ["float16"])
@tvm.testing.requires_openclml
def _test_batchnorm(device, dtype):
def test_batchnorm(device, dtype):
if tvm.support.libinfo().get("TVM_CLML_VERSION", 2) < 3:
print("Skip due to unsupported CLML version")
return
in_shape = (1, 8, 64, 64)
channels = 8

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/task_build_adreno_bins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cd ${output_directory}
cp ../cmake/config.cmake .

echo set\(USE_MICRO OFF\) >> config.cmake
echo set\(USE_CLML ON\) >> config.cmake
echo set\(USE_CLML "${ADRENO_OPENCL}"\) >> config.cmake
echo set\(USE_CLML_GRAPH_EXECUTOR "${ADRENO_OPENCL}"\) >> config.cmake
echo set\(USE_RPC ON\) >> config.cmake
echo set\(USE_CPP_RPC ON\) >> config.cmake
Expand Down
4 changes: 3 additions & 1 deletion tests/scripts/task_config_build_adreno.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cp ../cmake/config.cmake .

[[ -z "${ADRENO_OPENCL}" ]] && CLML_PATH='ON' || CLML_PATH="${ADRENO_OPENCL}"

echo set\(USE_OPENCL ON\) >> config.cmake
echo set\(USE_CLML ON\) >> config.cmake
echo set\(USE_CLML ${CLML_PATH}\) >> config.cmake
echo set\(USE_RPC ON\) >> config.cmake
echo set\(USE_GRAPH_EXECUTOR ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE AUTO\) >> config.cmake
Expand Down

0 comments on commit e84da6b

Please sign in to comment.