Skip to content

Commit 6addfea

Browse files
committed
Merge branch 'main' into review/yang/local_accessor
2 parents ca8e651 + 31d0fe1 commit 6addfea

27 files changed

+379
-249
lines changed

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ typedef enum ur_device_info_t {
15461546
///< shared memory access
15471547
UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT = 87, ///< [::ur_device_usm_access_capability_flags_t] support USM system wide
15481548
///< shared memory access
1549-
UR_DEVICE_INFO_UUID = 88, ///< [char[]] return device UUID
1549+
UR_DEVICE_INFO_UUID = 88, ///< [uint8_t[]] return device UUID
15501550
UR_DEVICE_INFO_PCI_ADDRESS = 89, ///< [char[]] return device PCI address
15511551
UR_DEVICE_INFO_GPU_EU_COUNT = 90, ///< [uint32_t] return Intel GPU EU count
15521552
UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH = 91, ///< [uint32_t] return Intel GPU EU SIMD width

include/ur_print.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,8 +3596,17 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info
35963596
} break;
35973597
case UR_DEVICE_INFO_UUID: {
35983598

3599-
const char *tptr = (const char *)ptr;
3600-
printPtr(os, tptr);
3599+
const uint8_t *tptr = (const uint8_t *)ptr;
3600+
os << "{";
3601+
size_t nelems = size / sizeof(uint8_t);
3602+
for (size_t i = 0; i < nelems; ++i) {
3603+
if (i != 0) {
3604+
os << ", ";
3605+
}
3606+
3607+
os << tptr[i];
3608+
}
3609+
os << "}";
36013610
} break;
36023611
case UR_DEVICE_INFO_PCI_ADDRESS: {
36033612

scripts/core/device.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ etors:
377377
- name: USM_SYSTEM_SHARED_SUPPORT
378378
desc: "[$x_device_usm_access_capability_flags_t] support USM system wide shared memory access"
379379
- name: UUID
380-
desc: "[char[]] return device UUID"
380+
desc: "[uint8_t[]] return device UUID"
381381
- name: PCI_ADDRESS
382382
desc: "[char[]] return device PCI address"
383383
- name: GPU_EU_COUNT

scripts/templates/ldrddi.cpp.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace ur_loader
5858
{
5959
for( auto& platform : context->platforms )
6060
{
61+
if(platform.initStatus != ${X}_RESULT_SUCCESS)
62+
continue;
6163
platform.dditable.${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( 1, &${obj['params'][1]['name']}[adapterIndex], nullptr );
6264
try
6365
{

scripts/templates/tools-info.hpp.mako

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ inline void printPlatformInfos(${x}_platform_handle_t hPlatform, std::string_vie
6262
inline void printDeviceInfos(${x}_device_handle_t hDevice, std::string_view prefix = " ") {
6363
%for etor in obj['etors']:
6464
std::cout << prefix;
65+
%if etor['name'] == '$X_DEVICE_INFO_UUID':
66+
printDeviceUUID(hDevice, ${etor['name'].replace('$X', X)});
67+
%else:
6568
printDeviceInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hDevice, ${etor['name'].replace('$X', X)});
69+
%endif
6670
%endfor
6771
}
6872
%endif

source/adapters/level_zero/adapter.cpp

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ ur_adapter_handle_t_ *GlobalAdapter = new ur_adapter_handle_t_();
1919
ur_adapter_handle_t_ *GlobalAdapter;
2020
#endif
2121

22+
class ur_legacy_sink : public logger::Sink {
23+
public:
24+
ur_legacy_sink(std::string logger_name = "", bool skip_prefix = true)
25+
: Sink(std::move(logger_name), skip_prefix) {
26+
this->ostream = &std::cerr;
27+
}
28+
29+
virtual void print([[maybe_unused]] logger::Level level,
30+
const std::string &msg) override {
31+
fprintf(stderr, "%s", msg.c_str());
32+
}
33+
34+
~ur_legacy_sink() = default;
35+
};
36+
2237
ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
2338
uint32_t ZeDriverCount = 0;
2439
ZE2UR_CALL(zeDriverGet, (&ZeDriverCount, nullptr));
@@ -44,7 +59,18 @@ ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
4459

4560
ur_result_t adapterStateInit() { return UR_RESULT_SUCCESS; }
4661

47-
ur_adapter_handle_t_::ur_adapter_handle_t_() {
62+
ur_adapter_handle_t_::ur_adapter_handle_t_()
63+
: logger(logger::get_logger("level_zero")) {
64+
65+
if (UrL0Debug & UR_L0_DEBUG_BASIC) {
66+
logger.setLegacySink(std::make_unique<ur_legacy_sink>());
67+
};
68+
69+
if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
70+
setEnvVar("ZE_ENABLE_VALIDATION_LAYER", "1");
71+
setEnvVar("ZE_ENABLE_PARAMETER_VALIDATION", "1");
72+
}
73+
4874
PlatformCache.Compute = [](Result<PlatformVec> &result) {
4975
static std::once_flag ZeCallCountInitialized;
5076
try {
@@ -68,7 +94,7 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() {
6894
}
6995

7096
if (getenv("SYCL_ENABLE_PCI") != nullptr) {
71-
urPrint(
97+
logger::warning(
7298
"WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n");
7399
}
74100

@@ -91,8 +117,9 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() {
91117
return;
92118
}
93119
if (*GlobalAdapter->ZeResult != ZE_RESULT_SUCCESS) {
94-
urPrint("zeInit: Level Zero initialization failure\n");
120+
logger::error("zeInit: Level Zero initialization failure\n");
95121
result = ze2urResult(*GlobalAdapter->ZeResult);
122+
96123
return;
97124
}
98125

@@ -157,10 +184,10 @@ ur_result_t adapterStateTeardown() {
157184
// zeMemAllocShared = 0 \---> zeMemFree = 1
158185
//
159186
// clang-format on
160-
161-
fprintf(stderr, "Check balance of create/destroy calls\n");
162-
fprintf(stderr,
163-
"----------------------------------------------------------\n");
187+
// TODO: use logger to print this messages
188+
std::cerr << "Check balance of create/destroy calls\n";
189+
std::cerr << "----------------------------------------------------------\n";
190+
std::stringstream ss;
164191
for (const auto &Row : CreateDestroySet) {
165192
int diff = 0;
166193
for (auto I = Row.begin(); I != Row.end();) {
@@ -171,23 +198,30 @@ ur_result_t adapterStateTeardown() {
171198
bool Last = (++I == Row.end());
172199

173200
if (Last) {
174-
fprintf(stderr, " \\--->");
201+
ss << " \\--->";
175202
diff -= ZeCount;
176203
} else {
177204
diff += ZeCount;
178205
if (!First) {
179-
fprintf(stderr, " | \n");
206+
ss << " | ";
207+
std::cerr << ss.str() << "\n";
208+
ss.str("");
209+
ss.clear();
180210
}
181211
}
182-
183-
fprintf(stderr, "%30s = %-5d", ZeName, ZeCount);
212+
ss << std::setw(30) << std::right << ZeName;
213+
ss << " = ";
214+
ss << std::setw(5) << std::left << ZeCount;
184215
}
185216

186217
if (diff) {
187218
LeakFound = true;
188-
fprintf(stderr, " ---> LEAK = %d", diff);
219+
ss << " ---> LEAK = " << diff;
189220
}
190-
fprintf(stderr, "\n");
221+
222+
std::cerr << ss.str() << '\n';
223+
ss.str("");
224+
ss.clear();
191225
}
192226

193227
ZeCallCount->clear();

source/adapters/level_zero/adapter.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99
//===----------------------------------------------------------------------===//
1010

11+
#include "logger/ur_logger.hpp"
1112
#include <atomic>
1213
#include <mutex>
1314
#include <optional>
@@ -16,13 +17,16 @@
1617

1718
using PlatformVec = std::vector<std::unique_ptr<ur_platform_handle_t_>>;
1819

20+
class ur_legacy_sink;
21+
1922
struct ur_adapter_handle_t_ {
2023
ur_adapter_handle_t_();
2124
std::atomic<uint32_t> RefCount = 0;
2225
std::mutex Mutex;
2326

2427
std::optional<ze_result_t> ZeResult;
2528
ZeCache<Result<PlatformVec>> PlatformCache;
29+
logger::Logger &logger;
2630
};
2731

2832
extern ur_adapter_handle_t_ *GlobalAdapter;

source/adapters/level_zero/command_buffer.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99
//===----------------------------------------------------------------------===//
1010
#include "command_buffer.hpp"
11+
#include "logger/ur_logger.hpp"
1112
#include "ur_level_zero.hpp"
1213

1314
/* L0 Command-buffer Extension Doc see:
@@ -140,16 +141,16 @@ ur_result_t calculateKernelWorkDimensions(
140141
while (GlobalWorkSize3D[I] % GroupSize[I]) {
141142
--GroupSize[I];
142143
}
143-
if (GlobalWorkSize3D[I] / GroupSize[I] > UINT32_MAX) {
144-
urPrint("calculateKernelWorkDimensions: can't find a WG size "
145-
"suitable for global work size > UINT32_MAX\n");
144+
if (GlobalWorkSize[I] / GroupSize[I] > UINT32_MAX) {
145+
logger::debug("calculateKernelWorkDimensions: can't find a WG size "
146+
"suitable for global work size > UINT32_MAX");
146147
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
147148
}
148149
WG[I] = GroupSize[I];
149150
}
150-
urPrint("calculateKernelWorkDimensions: using computed WG size = {%d, "
151-
"%d, %d}\n",
152-
WG[0], WG[1], WG[2]);
151+
logger::debug("calculateKernelWorkDimensions: using computed WG "
152+
"size = {{{}, {}, {}}}",
153+
WG[0], WG[1], WG[2]);
153154
}
154155
}
155156

@@ -177,30 +178,27 @@ ur_result_t calculateKernelWorkDimensions(
177178
break;
178179

179180
default:
180-
urPrint("calculateKernelWorkDimensions: unsupported work_dim\n");
181+
logger::error("calculateKernelWorkDimensions: unsupported work_dim");
181182
return UR_RESULT_ERROR_INVALID_VALUE;
182183
}
183184

184185
// Error handling for non-uniform group size case
185186
if (GlobalWorkSize3D[0] !=
186187
size_t(ZeThreadGroupDimensions.groupCountX) * WG[0]) {
187-
urPrint("calculateKernelWorkDimensions: invalid work_dim. The range "
188-
"is not a "
189-
"multiple of the group size in the 1st dimension\n");
188+
logger::error("calculateKernelWorkDimensions: invalid work_dim. The range "
189+
"is not a multiple of the group size in the 1st dimension");
190190
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
191191
}
192192
if (GlobalWorkSize3D[1] !=
193193
size_t(ZeThreadGroupDimensions.groupCountY) * WG[1]) {
194-
urPrint("calculateKernelWorkDimensions: invalid work_dim. The range "
195-
"is not a "
196-
"multiple of the group size in the 2nd dimension\n");
194+
logger::error("calculateKernelWorkDimensions: invalid work_dim. The range "
195+
"is not a multiple of the group size in the 2nd dimension");
197196
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
198197
}
199198
if (GlobalWorkSize3D[2] !=
200199
size_t(ZeThreadGroupDimensions.groupCountZ) * WG[2]) {
201-
urPrint("calculateKernelWorkDimensions: invalid work_dim. The range "
202-
"is not a "
203-
"multiple of the group size in the 3rd dimension\n");
200+
logger::error("calculateKernelWorkDimensions: invalid work_dim. The range "
201+
"is not a multiple of the group size in the 3rd dimension");
204202
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
205203
}
206204

@@ -268,9 +266,9 @@ static ur_result_t enqueueCommandBufferMemCopyHelper(
268266
(CommandBuffer->ZeCommandList, Dst, Src, Size,
269267
LaunchEvent->ZeEvent, ZeEventList.size(), ZeEventList.data()));
270268

271-
urPrint("calling zeCommandListAppendMemoryCopy() with"
272-
" ZeEvent %#" PRIxPTR "\n",
273-
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
269+
logger::debug("calling zeCommandListAppendMemoryCopy() with"
270+
" ZeEvent {}",
271+
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
274272

275273
return UR_RESULT_SUCCESS;
276274
}
@@ -335,9 +333,9 @@ static ur_result_t enqueueCommandBufferMemCopyRectHelper(
335333
DstSlicePitch, Src, &ZeSrcRegion, SrcPitch, SrcSlicePitch,
336334
LaunchEvent->ZeEvent, ZeEventList.size(), ZeEventList.data()));
337335

338-
urPrint("calling zeCommandListAppendMemoryCopyRegion() with"
339-
" ZeEvent %#" PRIxPTR "\n",
340-
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
336+
logger::debug("calling zeCommandListAppendMemoryCopyRegion() with"
337+
" ZeEvent {}",
338+
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
341339

342340
return UR_RESULT_SUCCESS;
343341
}
@@ -378,9 +376,9 @@ static ur_result_t enqueueCommandBufferFillHelper(
378376
(CommandBuffer->ZeCommandList, Ptr, Pattern, PatternSize, Size,
379377
LaunchEvent->ZeEvent, ZeEventList.size(), ZeEventList.data()));
380378

381-
urPrint("calling zeCommandListAppendMemoryFill() with"
382-
" ZeEvent %#lx\n",
383-
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
379+
logger::debug("calling zeCommandListAppendMemoryFill() with"
380+
" ZeEvent {}",
381+
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
384382

385383
return UR_RESULT_SUCCESS;
386384
}
@@ -519,7 +517,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
519517
if (GlobalWorkOffset != NULL) {
520518
if (!CommandBuffer->Context->getPlatform()
521519
->ZeDriverGlobalOffsetExtensionFound) {
522-
urPrint("No global offset extension found on this driver\n");
520+
logger::debug("No global offset extension found on this driver");
523521
return UR_RESULT_ERROR_INVALID_VALUE;
524522
}
525523

@@ -606,9 +604,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
606604
&ZeThreadGroupDimensions, LaunchEvent->ZeEvent,
607605
ZeEventList.size(), ZeEventList.data()));
608606

609-
urPrint("calling zeCommandListAppendLaunchKernel() with"
610-
" ZeEvent %#" PRIxPTR "\n",
611-
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
607+
logger::debug("calling zeCommandListAppendLaunchKernel() with"
608+
" ZeEvent {}",
609+
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
612610

613611
return UR_RESULT_SUCCESS;
614612
}
@@ -1068,7 +1066,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
10681066
if (NewGlobalWorkOffset && Dim > 0) {
10691067
if (!CommandBuffer->Context->getPlatform()
10701068
->ZeDriverGlobalOffsetExtensionFound) {
1071-
urPrint("No global offset extension found on this driver\n");
1069+
logger::error("No global offset extension found on this driver");
10721070
return UR_RESULT_ERROR_INVALID_VALUE;
10731071
}
10741072
auto MutableGroupOffestDesc =
@@ -1277,8 +1275,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
12771275
// Zero.
12781276
continue;
12791277
} else {
1280-
urPrint("urCommandBufferUpdateKernelLaunchExp: unsupported name of "
1281-
"execution attribute.\n");
1278+
logger::error("urCommandBufferUpdateKernelLaunchExp: unsupported name of "
1279+
"execution attribute.");
12821280
return UR_RESULT_ERROR_INVALID_VALUE;
12831281
}
12841282
}

0 commit comments

Comments
 (0)