Skip to content

Commit fc595ea

Browse files
committed
Merge branch 'main' into except-san-layer
2 parents cc4cc64 + ab0a706 commit fc595ea

35 files changed

+734
-191
lines changed

.github/codeql/codeql-config.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/codeql.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
uses: github/codeql-action/init@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
2828
with:
2929
languages: cpp, python
30-
config-file: ./.github/codeql/codeql-config.yml
3130

3231
- name: Install pip packages
3332
run: pip install -r third_party/requirements.txt

.github/workflows/trivy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
format: 'sarif'
3636
output: 'trivy-results.sarif'
3737
exit-code: 1 # Fail if issue found
38-
skip-dirs: '**/_deps/**'
3938
# file with suppressions: .trivyignore (in root dir)
4039

4140
- name: Print report and trivyignore file

cmake/FetchLevelZero.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)
4040
set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
4141
endif()
4242
if (UR_LEVEL_ZERO_LOADER_TAG STREQUAL "")
43-
set(UR_LEVEL_ZERO_LOADER_TAG v1.18.3)
43+
set(UR_LEVEL_ZERO_LOADER_TAG v1.17.39)
4444
endif()
4545

4646
# Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104

source/adapters/level_zero/command_buffer.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -627,32 +627,6 @@ urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t CommandBuffer) {
627627
return UR_RESULT_SUCCESS;
628628
}
629629

630-
/**
631-
* Sets the global offset for a kernel command that will be appended to the
632-
* command buffer.
633-
* @param[in] CommandBuffer The CommandBuffer where the command will be
634-
* appended.
635-
* @param[in] Kernel The handle to the kernel that will be appended.
636-
* @param[in] GlobalWorkOffset The global offset value.
637-
* @return UR_RESULT_SUCCESS or an error code on failure
638-
*/
639-
ur_result_t setKernelGlobalOffset(ur_exp_command_buffer_handle_t CommandBuffer,
640-
ur_kernel_handle_t Kernel,
641-
const size_t *GlobalWorkOffset) {
642-
643-
if (!CommandBuffer->Context->getPlatform()
644-
->ZeDriverGlobalOffsetExtensionFound) {
645-
logger::debug("No global offset extension found on this driver");
646-
return UR_RESULT_ERROR_INVALID_VALUE;
647-
}
648-
649-
ZE2UR_CALL(zeKernelSetGlobalOffsetExp,
650-
(Kernel->ZeKernel, GlobalWorkOffset[0], GlobalWorkOffset[1],
651-
GlobalWorkOffset[2]));
652-
653-
return UR_RESULT_SUCCESS;
654-
}
655-
656630
/**
657631
* Sets the kernel arguments for a kernel command that will be appended to the
658632
* command buffer.
@@ -754,7 +728,8 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
754728
Kernel->Mutex, Kernel->Program->Mutex, CommandBuffer->Mutex);
755729

756730
if (GlobalWorkOffset != NULL) {
757-
UR_CALL(setKernelGlobalOffset(CommandBuffer, Kernel, GlobalWorkOffset));
731+
UR_CALL(setKernelGlobalOffset(CommandBuffer->Context, Kernel->ZeKernel,
732+
WorkDim, GlobalWorkOffset));
758733
}
759734

760735
// If there are any pending arguments set them now.

source/adapters/level_zero/helpers/kernel_helpers.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@ ur_result_t getSuggestedLocalWorkSize(ur_device_handle_t hDevice,
6767
}
6868

6969
ur_result_t setKernelGlobalOffset(ur_context_handle_t Context,
70-
ze_kernel_handle_t Kernel,
70+
ze_kernel_handle_t Kernel, uint32_t WorkDim,
7171
const size_t *GlobalWorkOffset) {
7272
if (!Context->getPlatform()->ZeDriverGlobalOffsetExtensionFound) {
7373
logger::debug("No global offset extension found on this driver");
7474
return UR_RESULT_ERROR_INVALID_VALUE;
7575
}
7676

77-
ZE2UR_CALL(
78-
zeKernelSetGlobalOffsetExp,
79-
(Kernel, GlobalWorkOffset[0], GlobalWorkOffset[1], GlobalWorkOffset[2]));
77+
auto OffsetX = GlobalWorkOffset[0];
78+
auto OffsetY = WorkDim > 1 ? GlobalWorkOffset[1] : 0;
79+
auto OffsetZ = WorkDim > 2 ? GlobalWorkOffset[2] : 0;
80+
ZE2UR_CALL(zeKernelSetGlobalOffsetExp, (Kernel, OffsetX, OffsetY, OffsetZ));
8081

8182
return UR_RESULT_SUCCESS;
8283
}

source/adapters/level_zero/helpers/kernel_helpers.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ ur_result_t calculateKernelWorkDimensions(
3636
* command buffer.
3737
* @param[in] Context Context associated with the queue.
3838
* @param[in] Kernel The handle to the kernel that will be appended.
39-
* @param[in] GlobalWorkOffset The global offset value.
39+
* @param[in] WorkDim The number of work dimensions.
40+
* @param[in] GlobalWorkOffset Array of size WorkDim.
4041
* @return UR_RESULT_SUCCESS or an error code on failure
4142
*/
4243
ur_result_t setKernelGlobalOffset(ur_context_handle_t Context,
43-
ze_kernel_handle_t Kernel,
44+
ze_kernel_handle_t Kernel, uint32_t WorkDim,
4445
const size_t *GlobalWorkOffset);
4546

4647
/**

source/adapters/level_zero/kernel.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,8 @@ ur_result_t urEnqueueKernelLaunch(
9696
std::scoped_lock<ur_shared_mutex, ur_shared_mutex, ur_shared_mutex> Lock(
9797
Queue->Mutex, Kernel->Mutex, Kernel->Program->Mutex);
9898
if (GlobalWorkOffset != NULL) {
99-
if (!Queue->Device->Platform->ZeDriverGlobalOffsetExtensionFound) {
100-
logger::error("No global offset extension found on this driver");
101-
return UR_RESULT_ERROR_INVALID_VALUE;
102-
}
103-
104-
ZE2UR_CALL(zeKernelSetGlobalOffsetExp,
105-
(ZeKernel, GlobalWorkOffset[0], GlobalWorkOffset[1],
106-
GlobalWorkOffset[2]));
99+
UR_CALL(setKernelGlobalOffset(Queue->Context, ZeKernel, WorkDim,
100+
GlobalWorkOffset));
107101
}
108102

109103
// If there are any pending arguments set them now.
@@ -257,14 +251,8 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(
257251
std::scoped_lock<ur_shared_mutex, ur_shared_mutex, ur_shared_mutex> Lock(
258252
Queue->Mutex, Kernel->Mutex, Kernel->Program->Mutex);
259253
if (GlobalWorkOffset != NULL) {
260-
if (!Queue->Device->Platform->ZeDriverGlobalOffsetExtensionFound) {
261-
logger::error("No global offset extension found on this driver");
262-
return UR_RESULT_ERROR_INVALID_VALUE;
263-
}
264-
265-
ZE2UR_CALL(zeKernelSetGlobalOffsetExp,
266-
(ZeKernel, GlobalWorkOffset[0], GlobalWorkOffset[1],
267-
GlobalWorkOffset[2]));
254+
UR_CALL(setKernelGlobalOffset(Queue->Context, ZeKernel, WorkDim,
255+
GlobalWorkOffset));
268256
}
269257

270258
// If there are any pending arguments set them now.

source/adapters/level_zero/v2/queue_immediate_in_order.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueKernelLaunch(
252252
hKernel->Mutex, hKernel->getProgramHandle()->Mutex, this->Mutex);
253253

254254
if (pGlobalWorkOffset != NULL) {
255-
UR_CALL(setKernelGlobalOffset(hContext, hZeKernel, pGlobalWorkOffset));
255+
UR_CALL(
256+
setKernelGlobalOffset(hContext, hZeKernel, workDim, pGlobalWorkOffset));
256257
}
257258

258259
ze_group_count_t zeThreadGroupDimensions{1, 1, 1};

source/adapters/opencl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_ur_adapter(${TARGET_NAME} SHARED
3737
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
3838
${CMAKE_CURRENT_SOURCE_DIR}/queue.cpp
3939
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
40+
${CMAKE_CURRENT_SOURCE_DIR}/usm.hpp
4041
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp
4142
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
4243
${CMAKE_CURRENT_SOURCE_DIR}/virtual_mem.cpp

source/adapters/opencl/enqueue.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,33 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
3030
const size_t *pGlobalWorkOffset, const size_t *pGlobalWorkSize,
3131
const size_t *pLocalWorkSize, uint32_t numEventsInWaitList,
3232
const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
33+
std::vector<size_t> compiledLocalWorksize;
34+
if (!pLocalWorkSize) {
35+
cl_device_id device = nullptr;
36+
CL_RETURN_ON_FAILURE(clGetCommandQueueInfo(
37+
cl_adapter::cast<cl_command_queue>(hQueue), CL_QUEUE_DEVICE,
38+
sizeof(device), &device, nullptr));
39+
// This query always returns size_t[3], if nothing was specified it returns
40+
// all zeroes.
41+
size_t queriedLocalWorkSize[3] = {0, 0, 0};
42+
CL_RETURN_ON_FAILURE(clGetKernelWorkGroupInfo(
43+
cl_adapter::cast<cl_kernel>(hKernel), device,
44+
CL_KERNEL_COMPILE_WORK_GROUP_SIZE, sizeof(size_t[3]),
45+
queriedLocalWorkSize, nullptr));
46+
if (queriedLocalWorkSize[0] != 0) {
47+
for (uint32_t i = 0; i < workDim; i++) {
48+
compiledLocalWorksize.push_back(queriedLocalWorkSize[i]);
49+
}
50+
}
51+
}
3352

3453
CL_RETURN_ON_FAILURE(clEnqueueNDRangeKernel(
3554
cl_adapter::cast<cl_command_queue>(hQueue),
3655
cl_adapter::cast<cl_kernel>(hKernel), workDim, pGlobalWorkOffset,
37-
pGlobalWorkSize, pLocalWorkSize, numEventsInWaitList,
38-
cl_adapter::cast<const cl_event *>(phEventWaitList),
56+
pGlobalWorkSize,
57+
compiledLocalWorksize.empty() ? pLocalWorkSize
58+
: compiledLocalWorksize.data(),
59+
numEventsInWaitList, cl_adapter::cast<const cl_event *>(phEventWaitList),
3960
cl_adapter::cast<cl_event *>(phEvent)));
4061

4162
return UR_RESULT_SUCCESS;

source/adapters/opencl/program.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(
8181

8282
*phProgram = cl_adapter::cast<ur_program_handle_t>(clCreateProgramWithIL(
8383
cl_adapter::cast<cl_context>(hContext), pIL, length, &Err));
84-
CL_RETURN_ON_FAILURE(Err);
8584
} else {
8685

8786
/* If none of the devices conform with CL 2.1 or newer make sure they all
@@ -109,6 +108,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(
109108

110109
*phProgram = cl_adapter::cast<ur_program_handle_t>(
111110
FuncPtr(cl_adapter::cast<cl_context>(hContext), pIL, length, &Err));
111+
}
112+
113+
// INVALID_VALUE is only returned in three circumstances according to the cl
114+
// spec:
115+
// * pIL == NULL
116+
// * length == 0
117+
// * pIL is not a well-formed binary
118+
// UR has a unique error code for each of these, so here we figure out which
119+
// to return
120+
if (Err == CL_INVALID_VALUE) {
121+
if (pIL == nullptr) {
122+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
123+
}
124+
if (length == 0) {
125+
return UR_RESULT_ERROR_INVALID_SIZE;
126+
}
127+
return UR_RESULT_ERROR_INVALID_BINARY;
128+
} else {
112129
CL_RETURN_ON_FAILURE(Err);
113130
}
114131

0 commit comments

Comments
 (0)