Skip to content

Commit

Permalink
Formating
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Dec 11, 2023
1 parent 5a92d8a commit 26bd60a
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 138 deletions.
23 changes: 11 additions & 12 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate(
CLDevices[i] = phDevices[i]->get();
}

cl_context Ctx = clCreateContext(nullptr, cl_adapter::cast<cl_uint>(DeviceCount),
CLDevices.data(),
nullptr, nullptr, cl_adapter::cast<cl_int *>(&Ret));
cl_context Ctx = clCreateContext(
nullptr, cl_adapter::cast<cl_uint>(DeviceCount), CLDevices.data(),
nullptr, nullptr, cl_adapter::cast<cl_int *>(&Ret));

*phContext = new ur_context_handle_t_(Ctx, DeviceCount, phDevices);
return mapCLErrorToUR(Ret);
Expand Down Expand Up @@ -95,9 +95,8 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_DEVICES:
case UR_CONTEXT_INFO_REFERENCE_COUNT: {
size_t CheckPropSize = 0;
auto ClResult =
clGetContextInfo(hContext->get(), CLPropName,
propSize, pPropValue, &CheckPropSize);
auto ClResult = clGetContextInfo(hContext->get(), CLPropName, propSize,
pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
Expand Down Expand Up @@ -134,11 +133,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
}

UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
ur_native_handle_t hNativeContext, uint32_t numDevices, const ur_device_handle_t *phDevices,
const ur_context_native_properties_t *, ur_context_handle_t *phContext) {
ur_native_handle_t hNativeContext, uint32_t numDevices,
const ur_device_handle_t *phDevices, const ur_context_native_properties_t *,
ur_context_handle_t *phContext) {

cl_context NativeHandle =
reinterpret_cast<cl_context>(hNativeContext);
cl_context NativeHandle = reinterpret_cast<cl_context>(hNativeContext);
*phContext = new ur_context_handle_t_(NativeHandle, numDevices, phDevices);
return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -189,8 +188,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter(
auto *C = static_cast<ContextCallback *>(pUserData);
C->execute();
};
CL_RETURN_ON_FAILURE(clSetContextDestructorCallback(
hContext->get(), ClCallback, Callback));
CL_RETURN_ON_FAILURE(
clSetContextDestructorCallback(hContext->get(), ClCallback, Callback));

return UR_RESULT_SUCCESS;
}
22 changes: 12 additions & 10 deletions source/adapters/opencl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ getDevicesFromContext(ur_context_handle_t hContext,
}

struct ur_context_handle_t_ {
using native_type = cl_context;
native_type Context;
std::vector<ur_device_handle_t> Devices;
uint32_t DeviceCount;
using native_type = cl_context;
native_type Context;
std::vector<ur_device_handle_t> Devices;
uint32_t DeviceCount;

ur_context_handle_t_(native_type Ctx, uint32_t DevCount, const ur_device_handle_t *phDevices) : Context(Ctx), DeviceCount(DevCount) {
for (uint32_t i = 0; i < DeviceCount; i++) {
Devices.emplace_back(phDevices[i]);
}
ur_context_handle_t_(native_type Ctx, uint32_t DevCount,
const ur_device_handle_t *phDevices)
: Context(Ctx), DeviceCount(DevCount) {
for (uint32_t i = 0; i < DeviceCount; i++) {
Devices.emplace_back(phDevices[i]);
}
}

~ur_context_handle_t_() {}
~ur_context_handle_t_() {}

native_type get() { return Context; }
native_type get() { return Context; }
};
12 changes: 6 additions & 6 deletions source/adapters/opencl/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ ur_result_t cl_adapter::checkDeviceExtensions(
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(ur_platform_handle_t hPlatform,
ur_device_type_t DeviceType,
[[maybe_unused]] uint32_t NumEntries,
ur_device_handle_t *phDevices,
uint32_t *pNumDevices) {
UR_APIEXPORT ur_result_t UR_APICALL
urDeviceGet(ur_platform_handle_t hPlatform, ur_device_type_t DeviceType,
[[maybe_unused]] uint32_t NumEntries, ur_device_handle_t *phDevices,
uint32_t *pNumDevices) {

cl_device_type Type;
switch (DeviceType) {
Expand Down Expand Up @@ -1000,7 +999,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
CLNumDevicesRet,
CLSubDevices.data(), nullptr));
for (uint32_t i = 0; i < NumDevices; i++) {
phSubDevices[i] = new ur_device_handle_t_(CLSubDevices[i], hDevice->Platform, hDevice);
phSubDevices[i] =
new ur_device_handle_t_(CLSubDevices[i], hDevice->Platform, hDevice);
}
}

Expand Down
8 changes: 5 additions & 3 deletions source/adapters/opencl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ struct ur_device_handle_t_ {
native_type Device;
ur_platform_handle_t Platform;
cl_device_type Type = 0;
ur_device_handle_t ParentDevice = nullptr;
ur_device_handle_t ParentDevice = nullptr;

ur_device_handle_t_(native_type Dev, ur_platform_handle_t Plat, ur_device_handle_t Parent)
ur_device_handle_t_(native_type Dev, ur_platform_handle_t Plat,
ur_device_handle_t Parent)
: Device(Dev), Platform(Plat), ParentDevice(Parent) {
if (Parent) {
Type = Parent->Type;
} else {
clGetDeviceInfo(Device, CL_DEVICE_TYPE, sizeof(cl_device_type), &Type, nullptr);
clGetDeviceInfo(Device, CL_DEVICE_TYPE, sizeof(cl_device_type), &Type,
nullptr);
}
}

Expand Down
20 changes: 8 additions & 12 deletions source/adapters/opencl/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
if (!F || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;

Res = F(cl_adapter::cast<cl_command_queue>(hQueue),
hProgram->get(), name, blockingWrite, count,
offset, pSrc, numEventsInWaitList,
Res = F(cl_adapter::cast<cl_command_queue>(hQueue), hProgram->get(), name,
blockingWrite, count, offset, pSrc, numEventsInWaitList,
cl_adapter::cast<const cl_event *>(phEventWaitList),
cl_adapter::cast<cl_event *>(phEvent));

Expand Down Expand Up @@ -376,9 +375,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
if (!F || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;

Res = F(cl_adapter::cast<cl_command_queue>(hQueue),
hProgram->get(), name, blockingRead, count,
offset, pDst, numEventsInWaitList,
Res = F(cl_adapter::cast<cl_command_queue>(hQueue), hProgram->get(), name,
blockingRead, count, offset, pDst, numEventsInWaitList,
cl_adapter::cast<const cl_event *>(phEventWaitList),
cl_adapter::cast<cl_event *>(phEvent));

Expand Down Expand Up @@ -407,9 +405,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe(

if (FuncPtr) {
RetVal = mapCLErrorToUR(
FuncPtr(cl_adapter::cast<cl_command_queue>(hQueue),
hProgram->get(), pipe_symbol, blocking,
pDst, size, numEventsInWaitList,
FuncPtr(cl_adapter::cast<cl_command_queue>(hQueue), hProgram->get(),
pipe_symbol, blocking, pDst, size, numEventsInWaitList,
cl_adapter::cast<const cl_event *>(phEventWaitList),
cl_adapter::cast<cl_event *>(phEvent)));
}
Expand Down Expand Up @@ -439,9 +436,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe(

if (FuncPtr) {
RetVal = mapCLErrorToUR(
FuncPtr(cl_adapter::cast<cl_command_queue>(hQueue),
hProgram->get(), pipe_symbol, blocking,
pSrc, size, numEventsInWaitList,
FuncPtr(cl_adapter::cast<cl_command_queue>(hQueue), hProgram->get(),
pipe_symbol, blocking, pSrc, size, numEventsInWaitList,
cl_adapter::cast<const cl_event *>(phEventWaitList),
cl_adapter::cast<cl_event *>(phEvent)));
}
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/opencl/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ urKernelCreate(ur_program_handle_t hProgram, const char *pKernelName,
ur_kernel_handle_t *phKernel) {

cl_int CLResult;
*phKernel = cl_adapter::cast<ur_kernel_handle_t>(clCreateKernel(
hProgram->get(), pKernelName, &CLResult));
*phKernel = cl_adapter::cast<ur_kernel_handle_t>(
clCreateKernel(hProgram->get(), pKernelName, &CLResult));
CL_RETURN_ON_FAILURE(CLResult);
return UR_RESULT_SUCCESS;
}
Expand Down
12 changes: 6 additions & 6 deletions source/adapters/opencl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
}

void *HostPtr = pProperties ? pProperties->pHost : nullptr;
*phBuffer = reinterpret_cast<ur_mem_handle_t>(clCreateBuffer(
hContext->get(), static_cast<cl_mem_flags>(flags),
size, HostPtr, cl_adapter::cast<cl_int *>(&RetErr)));
*phBuffer = reinterpret_cast<ur_mem_handle_t>(
clCreateBuffer(hContext->get(), static_cast<cl_mem_flags>(flags), size,
HostPtr, cl_adapter::cast<cl_int *>(&RetErr)));
CL_RETURN_ON_FAILURE(RetErr);

return UR_RESULT_SUCCESS;
Expand All @@ -289,9 +289,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate(
cl_image_desc ImageDesc = mapURImageDescToCL(pImageDesc);
cl_map_flags MapFlags = convertURMemFlagsToCL(flags);

*phMem = reinterpret_cast<ur_mem_handle_t>(clCreateImage(
hContext->get(), MapFlags, &ImageFormat,
&ImageDesc, pHost, cl_adapter::cast<cl_int *>(&RetErr)));
*phMem = reinterpret_cast<ur_mem_handle_t>(
clCreateImage(hContext->get(), MapFlags, &ImageFormat, &ImageDesc, pHost,
cl_adapter::cast<cl_int *>(&RetErr)));
CL_RETURN_ON_FAILURE(RetErr);

return UR_RESULT_SUCCESS;
Expand Down
43 changes: 21 additions & 22 deletions source/adapters/opencl/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ urPlatformGetInfo(ur_platform_handle_t hPlatform, ur_platform_info_t propName,
if (hPlatform) {
Plat = hPlatform->get();
}
CL_RETURN_ON_FAILURE(clGetPlatformInfo(Plat, CLPropName,
propSize, pPropValue, pSizeRet));
CL_RETURN_ON_FAILURE(
clGetPlatformInfo(Plat, CLPropName, propSize, pPropValue, pSizeRet));

return UR_RESULT_SUCCESS;
}
default:
Expand All @@ -93,26 +93,25 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries,
cl_int Result = CL_SUCCESS;

std::call_once(
InitFlag,
[](cl_int &Result) {
Result = clGetPlatformIDs(0, nullptr, &NumPlatforms);
if (Result != CL_SUCCESS) {
return Result;
}
std::vector<cl_platform_id> CLPlatforms(NumPlatforms);
Result = clGetPlatformIDs(cl_adapter::cast<cl_uint>(NumPlatforms),
CLPlatforms.data(),
nullptr);
if (Result != CL_SUCCESS) {
InitFlag,
[](cl_int &Result) {
Result = clGetPlatformIDs(0, nullptr, &NumPlatforms);
if (Result != CL_SUCCESS) {
return Result;
}
std::vector<cl_platform_id> CLPlatforms(NumPlatforms);
Result = clGetPlatformIDs(cl_adapter::cast<cl_uint>(NumPlatforms),
CLPlatforms.data(), nullptr);
if (Result != CL_SUCCESS) {
return Result;
}
URPlatforms.resize(NumPlatforms);
for (uint32_t i = 0; i < NumPlatforms; i++) {
URPlatforms[i] = new ur_platform_handle_t_(CLPlatforms[i]);
}
return Result;
}
URPlatforms.resize(NumPlatforms);
for (uint32_t i = 0; i < NumPlatforms; i++) {
URPlatforms[i] = new ur_platform_handle_t_(CLPlatforms[i]);
}
return Result;
},
Result);
},
Result);

/* Absorb the CL_PLATFORM_NOT_FOUND_KHR and just return 0 in num_platforms */
if (Result == CL_PLATFORM_NOT_FOUND_KHR) {
Expand Down
8 changes: 5 additions & 3 deletions source/adapters/opencl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ struct ur_platform_handle_t_ {

ur_result_t InitDevices() {
cl_uint DeviceNum = 0;
CL_RETURN_ON_FAILURE(clGetDeviceIDs(Platform, CL_DEVICE_TYPE_ALL, 0, nullptr, &DeviceNum));
CL_RETURN_ON_FAILURE(
clGetDeviceIDs(Platform, CL_DEVICE_TYPE_ALL, 0, nullptr, &DeviceNum));

std::vector<cl_device_id> CLDevices(DeviceNum);
CL_RETURN_ON_FAILURE(clGetDeviceIDs(Platform, CL_DEVICE_TYPE_ALL, DeviceNum, CLDevices.data(), nullptr));
CL_RETURN_ON_FAILURE(clGetDeviceIDs(Platform, CL_DEVICE_TYPE_ALL, DeviceNum,
CLDevices.data(), nullptr));

Devices = std::vector<ur_device_handle_t>(DeviceNum);
for (size_t i = 0; i < DeviceNum; i++) {
Devices[i] = new ur_device_handle_t_(CLDevices[i], this, nullptr);
Devices[i] = new ur_device_handle_t_(CLDevices[i], this, nullptr);
}

return UR_RESULT_SUCCESS;
Expand Down
Loading

0 comments on commit 26bd60a

Please sign in to comment.