Skip to content

Commit 65bfeab

Browse files
committed
Merge branch 'adapters' into merge-some-main-changes-into-adapters-second-patch
2 parents 07ad4f8 + 192e940 commit 65bfeab

33 files changed

+967
-296
lines changed

.github/workflows/cmake.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ jobs:
196196
-DUR_BUILD_TESTS=ON
197197
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
198198
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
199+
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
199200
-DUR_CONFORMANCE_TARGET_TRIPLES=${{matrix.adapter.triplet}}
200201
201202
- name: Build
202203
# This is so that device binaries can find the sycl runtime library
203-
run: LD_LIBRARY_PATH=${{github.workspace}}/dpcpp_compiler/lib
204-
cmake --build ${{github.workspace}}/build -j $(nproc)
204+
run: cmake --build ${{github.workspace}}/build -j $(nproc)
205205

206206
- name: Test adapter specific
207207
working-directory: ${{github.workspace}}/build

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ option(UR_BUILD_ADAPTER_CUDA "build cuda adapter from SYCL" OFF)
4242
option(UR_BUILD_ADAPTER_HIP "build hip adapter from SYCL" OFF)
4343
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
4444
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
45+
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")
46+
set(UR_SYCL_LIBRARY_DIR "" CACHE PATH
47+
"Path of the SYCL runtime library directory")
4548

4649
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
4750
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ List of options provided by CMake:
136136
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
137137
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |
138138
| UR_ENABLE_COMGR | Enable comgr lib usage | AMD/NVIDIA | AMD |
139+
| UR_DPCXX | Path of the DPC++ compiler executable to build CTS device binaries | File path | `""` |
140+
| UR_SYCL_LIBRARY_DIR | Path of the SYCL runtime library directory to build CTS device binaries | Directory path | `""` |
139141

140142
### Additional make targets
141143

source/adapters/level_zero/adapter.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
175175
}
176176

177177
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
178-
ur_adapter_handle_t Adapter, ///< [in] handle of the platform instance
178+
[[maybe_unused]] ur_adapter_handle_t
179+
AdapterHandle, ///< [in] handle of the platform instance
179180
const char **Message, ///< [out] pointer to a C string where the adapter
180181
///< specific error message will be stored.
181-
int32_t *Error ///< [out] pointer to an integer where the adapter specific
182-
///< error code will be stored.
182+
[[maybe_unused]] int32_t
183+
*Error ///< [out] pointer to an integer where the adapter specific
184+
///< error code will be stored.
183185
) {
184-
std::ignore = Adapter;
185-
std::ignore = Message;
186-
std::ignore = Error;
187-
urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__);
188-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
186+
AdapterHandle = &Adapter;
187+
*Message = ErrorMessage;
188+
Error = &ErrorAdapterNativeCode;
189+
190+
return ErrorMessageCode;
189191
}
190192

191193
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,

source/adapters/level_zero/command_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ ur_result_t calculateKernelWorkDimensions(
177177
Device->ZeDeviceComputeProperties->maxGroupSizeX,
178178
Device->ZeDeviceComputeProperties->maxGroupSizeY,
179179
Device->ZeDeviceComputeProperties->maxGroupSizeZ};
180-
GroupSize[I] = std::min(size_t(GroupSize[I]), GlobalWorkSize[I]);
180+
GroupSize[I] = (std::min)(size_t(GroupSize[I]), GlobalWorkSize[I]);
181181
while (GlobalWorkSize[I] % GroupSize[I]) {
182182
--GroupSize[I];
183183
}

source/adapters/level_zero/common.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,16 @@ template <> zes_structure_type_t getZesStructureType<zes_mem_properties_t>() {
280280
// Global variables for ZER_EXT_RESULT_ADAPTER_SPECIFIC_ERROR
281281
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
282282
thread_local char ErrorMessage[MaxMessageSize];
283+
thread_local int32_t ErrorAdapterNativeCode;
283284

284285
// Utility function for setting a message and warning
285-
[[maybe_unused]] void setErrorMessage(const char *message,
286-
ur_result_t error_code) {
287-
assert(strlen(message) <= MaxMessageSize);
288-
strcpy(ErrorMessage, message);
289-
ErrorMessageCode = error_code;
286+
[[maybe_unused]] void setErrorMessage(const char *pMessage,
287+
ur_result_t ErrorCode,
288+
int32_t AdapterErrorCode) {
289+
assert(strlen(pMessage) <= MaxMessageSize);
290+
strcpy(ErrorMessage, pMessage);
291+
ErrorMessageCode = ErrorCode;
292+
ErrorAdapterNativeCode = AdapterErrorCode;
290293
}
291294

292295
ur_result_t zerPluginGetLastError(char **message) {

source/adapters/level_zero/common.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ constexpr char ZE_SUPPORTED_EXTENSIONS[] =
467467
constexpr size_t MaxMessageSize = 256;
468468
extern thread_local ur_result_t ErrorMessageCode;
469469
extern thread_local char ErrorMessage[MaxMessageSize];
470+
extern thread_local int32_t ErrorAdapterNativeCode;
470471

471472
// Utility function for setting a message and warning
472-
[[maybe_unused]] void setErrorMessage(const char *message,
473-
ur_result_t error_code);
473+
[[maybe_unused]] void setErrorMessage(const char *pMessage,
474+
ur_result_t ErrorCode,
475+
int32_t AdapterErrorCode);

source/adapters/level_zero/device.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
7474

7575
uint32_t ZeDeviceCount = MatchedDevices.size();
7676

77-
auto N = std::min(ZeDeviceCount, NumEntries);
77+
auto N = (std::min)(ZeDeviceCount, NumEntries);
7878
if (Devices)
7979
std::copy_n(MatchedDevices.begin(), N, Devices);
8080

@@ -631,7 +631,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
631631
case UR_DEVICE_INFO_GLOBAL_MEM_FREE: {
632632
if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
633633
setErrorMessage("Set ZES_ENABLE_SYSMAN=1 to obtain free memory",
634-
UR_RESULT_SUCCESS);
634+
UR_RESULT_ERROR_UNINITIALIZED,
635+
static_cast<int32_t>(ZE_RESULT_ERROR_UNINITIALIZED));
635636
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
636637
}
637638
// Only report device memory which zeMemAllocDevice can allocate from.
@@ -1239,7 +1240,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceSelectBinary(
12391240
uint32_t *SelectedBinaryInd = SelectedBinary;
12401241

12411242
// Find the appropriate device image, fallback to spirv if not found
1242-
constexpr uint32_t InvalidInd = std::numeric_limits<uint32_t>::max();
1243+
constexpr uint32_t InvalidInd = (std::numeric_limits<uint32_t>::max)();
12431244
uint32_t Spirv = InvalidInd;
12441245

12451246
for (uint32_t i = 0; i < NumBinaries; ++i) {

source/adapters/level_zero/kernel.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
7979
UR_RESULT_ERROR_INVALID_VALUE);
8080
if (LocalWorkSize) {
8181
// L0
82-
UR_ASSERT(LocalWorkSize[0] < std::numeric_limits<uint32_t>::max(),
82+
UR_ASSERT(LocalWorkSize[0] < (std::numeric_limits<uint32_t>::max)(),
8383
UR_RESULT_ERROR_INVALID_VALUE);
84-
UR_ASSERT(LocalWorkSize[1] < std::numeric_limits<uint32_t>::max(),
84+
UR_ASSERT(LocalWorkSize[1] < (std::numeric_limits<uint32_t>::max)(),
8585
UR_RESULT_ERROR_INVALID_VALUE);
86-
UR_ASSERT(LocalWorkSize[2] < std::numeric_limits<uint32_t>::max(),
86+
UR_ASSERT(LocalWorkSize[2] < (std::numeric_limits<uint32_t>::max)(),
8787
UR_RESULT_ERROR_INVALID_VALUE);
8888
WG[0] = static_cast<uint32_t>(LocalWorkSize[0]);
8989
WG[1] = static_cast<uint32_t>(LocalWorkSize[1]);
@@ -110,7 +110,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
110110
Queue->Device->ZeDeviceComputeProperties->maxGroupSizeX,
111111
Queue->Device->ZeDeviceComputeProperties->maxGroupSizeY,
112112
Queue->Device->ZeDeviceComputeProperties->maxGroupSizeZ};
113-
GroupSize[I] = std::min(size_t(GroupSize[I]), GlobalWorkSize[I]);
113+
GroupSize[I] = (std::min)(size_t(GroupSize[I]), GlobalWorkSize[I]);
114114
while (GlobalWorkSize[I] % GroupSize[I]) {
115115
--GroupSize[I];
116116
}
@@ -284,8 +284,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
284284
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
285285
if (GlobalVarSize < Offset + Count) {
286286
setErrorMessage("Write device global variable is out of range.",
287-
UR_RESULT_ERROR_INVALID_VALUE);
288-
return UR_RESULT_ERROR_UNKNOWN;
287+
UR_RESULT_ERROR_INVALID_VALUE,
288+
static_cast<int32_t>(ZE_RESULT_ERROR_INVALID_ARGUMENT));
289+
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
289290
}
290291

291292
// Copy engine is preferred only for host to device transfer.
@@ -333,8 +334,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
333334
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
334335
if (GlobalVarSize < Offset + Count) {
335336
setErrorMessage("Read from device global variable is out of range.",
336-
UR_RESULT_ERROR_INVALID_VALUE);
337-
return UR_RESULT_ERROR_UNKNOWN;
337+
UR_RESULT_ERROR_INVALID_VALUE,
338+
static_cast<int32_t>(ZE_RESULT_ERROR_INVALID_ARGUMENT));
339+
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
338340
}
339341

340342
// Copy engine is preferred only for host to device transfer.

source/adapters/level_zero/platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(
121121
if (*NumPlatforms == 0)
122122
*NumPlatforms = URPlatformsCache->size();
123123
else
124-
*NumPlatforms = std::min(URPlatformsCache->size(), (size_t)NumEntries);
124+
*NumPlatforms = (std::min)(URPlatformsCache->size(), (size_t)NumEntries);
125125
}
126126

127127
return UR_RESULT_SUCCESS;

0 commit comments

Comments
 (0)