Skip to content

Commit

Permalink
* review
Browse files Browse the repository at this point in the history
  • Loading branch information
srkreddy1238 committed Feb 2, 2023
1 parent dfe2ddd commit 5e61a32
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
65 changes: 33 additions & 32 deletions apps/cpp_clml/clml_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ CLMLRunner::CLMLRunner(std::string name, ToolArgs& args, cl_platform_id arg_plat
cl_int majorVersions[MAX_VERSIONS];
cl_int minorVersions[MAX_VERSIONS];
cl_uint numVersions = 0;
result = clQueryMLInterfaceVersionsQCOM(NULL, NULL, 0, &numVersions);
result = clQueryMLInterfaceVersionsQCOM(nullptr, nullptr, 0, &numVersions);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);
CLML_SDK_TEST_AND_EXIT(numVersions > 0u);
CLML_SDK_TEST_AND_EXIT(numVersions <= MAX_VERSIONS);

result = clQueryMLInterfaceVersionsQCOM(majorVersions, minorVersions, numVersions, NULL);
result = clQueryMLInterfaceVersionsQCOM(majorVersions, minorVersions, numVersions, nullptr);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);

for (cl_uint i = 0; i < numVersions; ++i) {
Expand All @@ -74,7 +74,7 @@ CLMLRunner::CLMLRunner(std::string name, ToolArgs& args, cl_platform_id arg_plat
break;
}
}
CLML_SDK_TEST_AND_EXIT(this->h_ClmlIntf != NULL);
CLML_SDK_TEST_AND_EXIT(this->h_ClmlIntf != nullptr);

result = h_ClmlIntf->clCreateMLTuningCacheQCOM(&tuning_cache);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);
Expand Down Expand Up @@ -103,8 +103,8 @@ int CLMLRunner::Run(void) {
cl_int result;

for (size_t i = 0; i < this->function.size(); ++i) {
result =
h_ClmlIntf->clEnqueueMLOpQCOM(queue, this->function[i], this->descriptorSet, 0, NULL, NULL);
result = h_ClmlIntf->clEnqueueMLOpQCOM(queue, this->function[i], this->descriptorSet, 0,
nullptr, nullptr);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);
}
if (!r_args.output.empty()) {
Expand Down Expand Up @@ -155,13 +155,13 @@ void CLMLRunner::PrintMetaInfo(void) { LOG(INFO) << "\n" << this->meta_info; }
void CLMLRunner::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 = NULL;
cl_event evt = nullptr;
result = h_ClmlIntf->clEnqueueWriteMLTensorDataQCOM(this->queue, data, layout, tensor->tensor,
tensor->memory,
0, // n waitlist
NULL, // waitlist
&evt); // event
CLML_SDK_TEST_AND_EXIT((evt != NULL) && result == CL_SUCCESS);
0, // n waitlist
nullptr, // waitlist
&evt); // event
CLML_SDK_TEST_AND_EXIT((evt != nullptr) && result == CL_SUCCESS);
}

/*!
Expand All @@ -173,12 +173,12 @@ void CLMLRunner::CopyDataToCLMLTensor(std::shared_ptr<cl_ml_tensor_memory_desc_q
void CLMLRunner::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 = NULL;
cl_event readEvent = nullptr;
// Read the output tensor
result = h_ClmlIntf->clEnqueueReadMLTensorDataQCOM(this->queue, tensor->tensor, tensor->memory,
data, layout,
0, // n waitlist
NULL, // waitlist
nullptr, // waitlist
&readEvent); // event
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);
result = clWaitForEvents(1, &readEvent);
Expand All @@ -194,12 +194,12 @@ cl_int CLMLRunner::AllocateTensorMemory(
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> pTensorMemDesc) {
uint32_t size = 0;
cl_int result = CL_OUT_OF_HOST_MEMORY;
cl_mem buffer = NULL;
cl_mem buffer = nullptr;

result = h_ClmlIntf->clGetMLTensorMemorySizeQCOM(context, pTensorMemDesc->tensor, &size);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);

buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, size, NULL, &result);
buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, size, nullptr, &result);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);

pTensorMemDesc->memory = buffer;
Expand Down Expand Up @@ -257,7 +257,7 @@ void CLMLRunner::MakeUnusedTensor(void) {
cl_ml_tensor_desc_qcom desc = {};
desc.num_dimensions = CL_TENSOR_UNUSED_QCOM;
this->unusedTensor = std::make_shared<cl_ml_tensor_memory_desc_qcom>();
result = this->h_ClmlIntf->clCreateMLTensorQCOM(this->context, NULL, &desc,
result = this->h_ClmlIntf->clCreateMLTensorQCOM(this->context, nullptr, &desc,
&(this->unusedTensor->tensor));
CLML_SDK_TEST_AND_EXIT(this->unusedTensor && result == CL_SUCCESS);
}
Expand Down Expand Up @@ -321,7 +321,8 @@ std::shared_ptr<cl_ml_tensor_memory_desc_qcom> CLMLRunner::MakeCLMLTensor(
auto tensor_dsc = std::make_shared<cl_ml_tensor_memory_desc_qcom>();
cl_ml_tensor_desc_qcom desc = {
cl_dtype, layout, dims.n, dims.c, dims.h, dims.w, 0, CL_TENSOR_DIMENSIONS_4D_QCOM, {0}};
result = this->h_ClmlIntf->clCreateMLTensorQCOM(this->context, NULL, &desc, &tensor_dsc->tensor);
result =
this->h_ClmlIntf->clCreateMLTensorQCOM(this->context, nullptr, &desc, &tensor_dsc->tensor);
CLML_SDK_TEST_AND_EXIT(tensor_dsc->tensor && result == CL_SUCCESS);
return tensor_dsc;
}
Expand Down Expand Up @@ -372,7 +373,7 @@ void CLMLRunner::MakeConv2D(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input
{clml_dilation[0], clml_dilation[1]},
0,
cl_arithmetic_mode};
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
if (!has_act) {
result = h_ClmlIntf->clCreateMLOpConvolutionForwardQCOM(
this->context, 0, &conv_desc, input_desc->tensor, weight_desc->tensor, bias_desc->tensor,
Expand All @@ -381,7 +382,7 @@ void CLMLRunner::MakeConv2D(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input
} else {
result = h_ClmlIntf->clCreateMLOpFusedConvolutionActivationForwardQCOM(
this->context, 0, &conv_desc, &act_desc, input_desc->tensor, weight_desc->tensor,
bias_desc->tensor, NULL, output_desc->tensor, &op, tuning_cache);
bias_desc->tensor, nullptr, output_desc->tensor, &op, tuning_cache);
CLML_SDK_TEST_AND_EXIT(op && result == CL_SUCCESS);
}
this->function.push_back(op);
Expand Down Expand Up @@ -443,7 +444,7 @@ void CLMLRunner::MakeConv2DWithBN(std::shared_ptr<cl_ml_tensor_memory_desc_qcom>
{clml_dilation[0], clml_dilation[1]},
0,
cl_arithmetic_mode};
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_ml_op_batchnorm_desc_qcom bn_desc = {CL_BATCHNORM_MODE_SPATIAL_QCOM, cl_arithmetic_mode};
if (!has_act) {
result = h_ClmlIntf->clCreateMLOpFusedConvolutionBatchNormForwardQCOM(
Expand All @@ -454,7 +455,7 @@ void CLMLRunner::MakeConv2DWithBN(std::shared_ptr<cl_ml_tensor_memory_desc_qcom>
} else {
result = h_ClmlIntf->clCreateMLOpFusedConvolutionBatchNormActivationForwardQCOM(
this->context, 0, &conv_desc, &bn_desc, &act_desc, input_desc->tensor, weight_desc->tensor,
bias_desc->tensor, output_desc->tensor, NULL, bn_mean->tensor, bn_var->tensor,
bias_desc->tensor, output_desc->tensor, nullptr, bn_mean->tensor, bn_var->tensor,
bn_scale->tensor, bn_bias->tensor, &op, tuning_cache);
CLML_SDK_TEST_AND_EXIT(op && result == CL_SUCCESS);
}
Expand All @@ -472,7 +473,7 @@ void CLMLRunner::MakeRelu(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input_d
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc,
cl_activation_function_qcom relu_type, std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;
cl_ml_op_activation_desc_qcom act_desc = {relu_type, CL_PROPAGATE_NAN_QCOM, cl_arithmetic_mode};

Expand Down Expand Up @@ -502,7 +503,7 @@ void CLMLRunner::MakeBatchNorm(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> in
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> bn_var,
std::vector<float> bn_attrs, std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_ml_op_batchnorm_desc_qcom bn_desc = {CL_BATCHNORM_MODE_SPATIAL_QCOM, cl_arithmetic_mode};
Expand Down Expand Up @@ -531,7 +532,7 @@ void CLMLRunner::MakePool2D(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input
std::vector<cl_uint> padding, std::string pool_type,
std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_ml_op_pooling_desc_qcom pool_desc = {
Expand Down Expand Up @@ -567,7 +568,7 @@ void CLMLRunner::MakeGlobalPool2D(std::shared_ptr<cl_ml_tensor_memory_desc_qcom>
std::vector<cl_uint> in_shape, std::string pool_type,
std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;
cl_ml_op_pooling_desc_qcom pool_desc = {
pool_type == "nn.global_max_pool2d" ? CL_POOLING_MODE_MAX_QCOM
Expand Down Expand Up @@ -599,7 +600,7 @@ void CLMLRunner::MakeReshape(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> inpu
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc,
std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

result = h_ClmlIntf->clCreateMLOpReshapeQCOM(this->context, 0, input_desc->tensor,
Expand All @@ -620,7 +621,7 @@ void CLMLRunner::MakeConcatenate(
std::vector<std::shared_ptr<cl_ml_tensor_memory_desc_qcom>> in_list,
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc, int axis, std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_ml_tensor_qcom* concatInputs = new cl_ml_tensor_qcom[in_list.size()];
Expand Down Expand Up @@ -650,7 +651,7 @@ void CLMLRunner::MakeDense(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input_
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> bias_desc,
std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_ml_op_convolution_desc_qcom conv_desc = {CL_CONVOLUTION_MODE_CONVOLUTION_QCOM,
Expand Down Expand Up @@ -681,7 +682,7 @@ void CLMLRunner::MakeSoftMax(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> inpu
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc,
std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_ml_op_softmax_desc_qcom softmax_desc = {CL_SOFTMAX_ALGORITHM_ACCURATE_QCOM,
Expand All @@ -706,7 +707,7 @@ void CLMLRunner::MakePad(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input_de
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc,
std::string pad_mode, std::vector<cl_uint> padding, std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_pad_mode_qcom clml_pad_mode = CL_PAD_MODE_CONSTANT_QCOM;
Expand Down Expand Up @@ -741,7 +742,7 @@ void CLMLRunner::MakeBatchFlatten(std::shared_ptr<cl_ml_tensor_memory_desc_qcom>
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc,
std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

result = h_ClmlIntf->clCreateMLOpReshapeQCOM(this->context, 0, input_desc->tensor,
Expand All @@ -763,7 +764,7 @@ void CLMLRunner::MakeClip(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> input_d
float a_min, std::string dtype) {
LOG(INFO) << "MakeClip called";
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_ml_op_clip_desc_qcom clip_desc = {
Expand All @@ -788,7 +789,7 @@ void CLMLRunner::MakeBinaryOp(std::shared_ptr<cl_ml_tensor_memory_desc_qcom> inp
std::shared_ptr<cl_ml_tensor_memory_desc_qcom> output_desc,
std::string op_name, std::string dtype) {
cl_arithmetic_mode_qcom cl_arithmetic_mode = MakeCLArithMode(MakeCLDataType(dtype));
cl_ml_op_qcom op = NULL;
cl_ml_op_qcom op = nullptr;
cl_int result;

cl_binary_op_qcom binary_op = CL_TENSOR_OP_ADD_QCOM;
Expand Down
10 changes: 5 additions & 5 deletions apps/cpp_clml/clml_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,20 @@ class CLMLRunner {
/*! \brief ML API interface */
GET_ML_API_INTERFACE* h_ClmlIntf = nullptr;
/*! \brief Tuning cache object */
cl_ml_tuningcache_qcom tuning_cache = NULL;
cl_ml_tuningcache_qcom tuning_cache = nullptr;
/*! \brief Flag to inticate a tuning run */
bool is_tuning_run;
/*! \brief The tuning file for loading or storing cache */
char* tuning_file;

/*! \brief OpenCL platform */
cl_platform_id platform{NULL};
cl_platform_id platform{nullptr};
/*! \brief OpenCL context */
cl_context context{NULL};
cl_context context{nullptr};
/*! \brief OpenCL device */
cl_device_id device_id{NULL};
cl_device_id device_id{nullptr};
/*! \brief OpenCL Queue */
cl_command_queue queue{NULL};
cl_command_queue queue{nullptr};
/*! \brief Numpy object for params */
cnpy::npz_t npz_params;
/*! \brief Numpy object for inputs */
Expand Down
20 changes: 10 additions & 10 deletions apps/cpp_clml/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ void ParseCmdArgs(int argc, char* argv[], struct ToolArgs& args) {
bool ExtensionStringPresent(cl_platform_id platform_id, cl_device_id device_id) {
cl_int result = 0;
size_t reqd_size = 0;
result = clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, 0, NULL, &reqd_size);
result = clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, 0, nullptr, &reqd_size);
CLML_SDK_TEST_AND_EXIT(reqd_size > 0u && result == CL_SUCCESS);

std::vector<char> buf(reqd_size);
result = clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, reqd_size, buf.data(), NULL);
result = clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, reqd_size, buf.data(), nullptr);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);

std::string extensions(buf.data());
Expand All @@ -174,25 +174,25 @@ int ExecuteModel(ToolArgs& args) {
// Init OpenCL Environment
cl_int result;
cl_event readEvent = nullptr;
cl_platform_id platform = NULL;
cl_context context = NULL;
cl_device_id device_id = NULL;
cl_command_queue queue = NULL;
cl_platform_id platform = nullptr;
cl_context context = nullptr;
cl_device_id device_id = nullptr;
cl_command_queue queue = nullptr;

// Initialize Context and Command Queue
result = clGetPlatformIDs(1, &platform, NULL);
result = clGetPlatformIDs(1, &platform, nullptr);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);

uint32_t num_devices = 0;
result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, nullptr, &num_devices);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS && num_devices == 1);

result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device_id, nullptr);
CLML_SDK_TEST_AND_EXIT(device_id && result == CL_SUCCESS);

CLML_SDK_TEST_AND_EXIT(ExtensionStringPresent(platform, device_id) == true);

context = clCreateContext(0, 1, &device_id, NULL, NULL, &result);
context = clCreateContext(0, 1, &device_id, nullptr, nullptr, &result);
CLML_SDK_TEST_AND_EXIT(result == CL_SUCCESS);

cl_command_queue_properties queue_props = 0;
Expand Down

0 comments on commit 5e61a32

Please sign in to comment.