Skip to content

Commit

Permalink
Resolve merge problems
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Oct 10, 2024
1 parent 007c7e1 commit 78e362b
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 284 deletions.
49 changes: 23 additions & 26 deletions source/adapters/opencl/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ commandHandleReleaseInternal(ur_exp_command_buffer_command_handle_t Command) {
ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
urQueueRelease(hInternalQueue);

cl_context CLContext = cl_adapter::cast<cl_context>(hContext);
cl_context CLContext = hContext->get();
cl_ext::clReleaseCommandBufferKHR_fn clReleaseCommandBufferKHR = nullptr;
cl_int Res =
cl_ext::getExtFuncFromContext<decltype(clReleaseCommandBufferKHR)>(
Expand Down Expand Up @@ -77,7 +77,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
pCommandBufferDesc ? pCommandBufferDesc->isUpdatable : false;

ur_device_command_buffer_update_capability_flags_t UpdateCapabilities;
cl_device_id CLDevice = cl_adapter::cast<cl_device_id>(hDevice);
cl_device_id CLDevice = hDevice->get();
CL_RETURN_ON_FAILURE(
getDeviceCommandBufferUpdateCapabilities(CLDevice, UpdateCapabilities));
bool DeviceSupportsUpdate = UpdateCapabilities > 0;
Expand All @@ -91,9 +91,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
IsUpdatable ? CL_COMMAND_BUFFER_MUTABLE_KHR : 0u, 0};

cl_int Res = CL_SUCCESS;
cl_command_queue CLQueue = Queue->get();
auto CLCommandBuffer = clCreateCommandBufferKHR(
1, CLQueue, Properties, &Res);
const cl_command_queue CLQueue = Queue->get();
auto CLCommandBuffer =
clCreateCommandBufferKHR(1, &CLQueue, Properties, &Res);
CL_RETURN_ON_FAILURE_AND_SET_NULL(Res, phCommandBuffer);

try {
Expand Down Expand Up @@ -178,10 +178,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
cl_command_properties_khr *Properties =
hCommandBuffer->IsUpdatable ? UpdateProperties : nullptr;
CL_RETURN_ON_FAILURE(clCommandNDRangeKernelKHR(
hCommandBuffer->CLCommandBuffer, nullptr, Properties,
hKernel->get(), workDim, pGlobalWorkOffset,
pGlobalWorkSize, pLocalWorkSize, numSyncPointsInWaitList,
pSyncPointWaitList, pSyncPoint, OutCommandHandle));
hCommandBuffer->CLCommandBuffer, nullptr, Properties, hKernel->get(),
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize,
numSyncPointsInWaitList, pSyncPointWaitList, pSyncPoint,
OutCommandHandle));

try {
auto URCommandHandle =
Expand Down Expand Up @@ -237,10 +237,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp(
cl_ext::CommandCopyBufferName, &clCommandCopyBufferKHR));

CL_RETURN_ON_FAILURE(clCommandCopyBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
hSrcMem->get(), hDstMem->get(),
srcOffset, dstOffset, size, numSyncPointsInWaitList, pSyncPointWaitList,
pSyncPoint, nullptr));
hCommandBuffer->CLCommandBuffer, nullptr, nullptr, hSrcMem->get(),
hDstMem->get(), srcOffset, dstOffset, size, numSyncPointsInWaitList,
pSyncPointWaitList, pSyncPoint, nullptr));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -271,11 +270,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp(
cl_ext::CommandCopyBufferRectName, &clCommandCopyBufferRectKHR));

CL_RETURN_ON_FAILURE(clCommandCopyBufferRectKHR(
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
hSrcMem->get(), hDstMem->get(),
OpenCLOriginRect, OpenCLDstRect, OpenCLRegion, srcRowPitch, srcSlicePitch,
dstRowPitch, dstSlicePitch, numSyncPointsInWaitList, pSyncPointWaitList,
pSyncPoint, nullptr));
hCommandBuffer->CLCommandBuffer, nullptr, nullptr, hSrcMem->get(),
hDstMem->get(), OpenCLOriginRect, OpenCLDstRect, OpenCLRegion,
srcRowPitch, srcSlicePitch, dstRowPitch, dstSlicePitch,
numSyncPointsInWaitList, pSyncPointWaitList, pSyncPoint, nullptr));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -355,9 +353,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferFillExp(
cl_ext::CommandFillBufferName, &clCommandFillBufferKHR));

CL_RETURN_ON_FAILURE(clCommandFillBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
hBuffer->get(), pPattern, patternSize, offset, size,
numSyncPointsInWaitList, pSyncPointWaitList, pSyncPoint, nullptr));
hCommandBuffer->CLCommandBuffer, nullptr, nullptr, hBuffer->get(),
pPattern, patternSize, offset, size, numSyncPointsInWaitList,
pSyncPointWaitList, pSyncPoint, nullptr));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -481,11 +479,11 @@ void updateKernelArgs(std::vector<cl_mutable_dispatch_arg_khr> &CLArgs,
for (uint32_t i = 0; i < NumMemobjArgs; i++) {
const ur_exp_command_buffer_update_memobj_arg_desc_t &URMemObjArg =
ArgMemobjList[i];
cl_mem arg_value = URMemObjArg.hNewMemObjArg->get();
cl_mutable_dispatch_arg_khr CLArg{
URMemObjArg.argIndex, // arg_index
sizeof(cl_mem), // arg_size
cl_adapter::cast<const cl_mem *>(
&URMemObjArg.hNewMemObjArg) // arg_value
&arg_value // arg_value
};

CLArgs.push_back(CLArg);
Expand Down Expand Up @@ -516,7 +514,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
}

ur_exp_command_buffer_handle_t hCommandBuffer = hCommand->hCommandBuffer;
cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_context CLContext = hCommandBuffer->hContext->get();

cl_ext::clUpdateMutableCommandsKHR_fn clUpdateMutableCommandsKHR = nullptr;
UR_RETURN_ON_FAILURE(
Expand Down Expand Up @@ -566,8 +564,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
updateNDRange(CLLocalWorkSize, LocalWorkSizePtr);
}

cl_mutable_command_khr command =
cl_adapter::cast<cl_mutable_command_khr>(hCommand->CLMutableCommand);
cl_mutable_command_khr command = hCommand->CLMutableCommand;
cl_mutable_dispatch_config_khr dispatch_config = {
command,
static_cast<cl_uint>(CLArgs.size()), // num_args
Expand Down
14 changes: 0 additions & 14 deletions source/adapters/opencl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,6 @@ extern thread_local char ErrorMessage[MaxMessageSize];
ur_result_t ErrorCode);

[[noreturn]] void die(const char *Message);

template <class To, class From> To cast(From Value) {

if constexpr (std::is_pointer_v<From>) {
static_assert(std::is_pointer_v<From> == std::is_pointer_v<To>,
"Cast failed pointer check");
return reinterpret_cast<To>(Value);
} else {
static_assert(sizeof(From) == sizeof(To), "Cast failed size check");
static_assert(std::is_signed_v<From> == std::is_signed_v<To>,
"Cast failed sign check");
return static_cast<To>(Value);
}
}
} // namespace cl_adapter

namespace cl_ext {
Expand Down
35 changes: 16 additions & 19 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate(
}

try {
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, static_cast<cl_uint>(DeviceCount),
CLDevices.data(), nullptr, nullptr,
static_cast<cl_int *>(&Ret));
CL_RETURN_ON_FAILURE(Ret);
auto URContext =
std::make_unique<ur_context_handle_t_>(Ctx, DeviceCount, phDevices);
Expand Down Expand Up @@ -84,22 +84,19 @@ urContextRelease(ur_context_handle_t hContext) {
static std::mutex contextReleaseMutex;
auto clContext = hContext->get();

{
std::lock_guard<std::mutex> lock(contextReleaseMutex);
size_t refCount = 0;
CL_RETURN_ON_FAILURE(clGetContextInfo(clContext, CL_CONTEXT_REFERENCE_COUNT,
sizeof(size_t), &refCount, nullptr));

// ExtFuncPtrCache is destroyed in an atexit() callback, so it doesn't
// necessarily outlive the adapter (or all the contexts).
if (refCount == 1 && cl_ext::ExtFuncPtrCache) {
cl_ext::ExtFuncPtrCache->clearCache(clContext);
}
std::lock_guard<std::mutex> lock(contextReleaseMutex);
size_t refCount = hContext->getReferenceCount();
// ExtFuncPtrCache is destroyed in an atexit() callback, so it doesn't
// necessarily outlive the adapter (or all the contexts).
if (refCount == 1 && cl_ext::ExtFuncPtrCache) {
cl_ext::ExtFuncPtrCache->clearCache(clContext);
}

CL_RETURN_ON_FAILURE(
clReleaseContext(hContext->get()));

if (hContext->decrementReferenceCount() == 0) {
delete hContext;
} else {
CL_RETURN_ON_FAILURE(clReleaseContext(hContext->get()));
}
return UR_RESULT_SUCCESS;
}

Expand All @@ -118,8 +115,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
}

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

Expand Down
4 changes: 1 addition & 3 deletions source/adapters/opencl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ struct ur_context_handle_t_ {
static ur_result_t makeWithNative(native_type Ctx, uint32_t DevCount,
const ur_device_handle_t *phDevices,
ur_context_handle_t &Context) {
if (!phDevices) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}
try {
uint32_t CLDeviceCount;
CL_RETURN_ON_FAILURE(clGetContextInfo(Ctx, CL_CONTEXT_NUM_DEVICES,
Expand All @@ -63,6 +60,7 @@ struct ur_context_handle_t_ {
auto URContext =
std::make_unique<ur_context_handle_t_>(Ctx, DevCount, phDevices);
Context = URContext.release();
CL_RETURN_ON_FAILURE(clRetainContext(Ctx));
} catch (std::bad_alloc &) {
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
} catch (...) {
Expand Down
Loading

0 comments on commit 78e362b

Please sign in to comment.