29
29
#include < detail/xpti_registry.hpp>
30
30
#endif
31
31
32
- namespace sycl {
33
- inline namespace _V1 {
34
-
35
- using alloc = sycl::usm::alloc;
36
-
37
- namespace detail {
38
- #ifdef XPTI_ENABLE_INSTRUMENTATION
39
- extern xpti::trace_event_data_t *GSYCLGraphEvent;
40
- #endif
41
- namespace usm {
42
-
43
- void *alignedAllocHost (size_t Alignment, size_t Size, const context &Ctxt,
44
- alloc Kind, const property_list &PropList,
45
- const detail::code_location &CodeLoc) {
32
+ namespace {
33
+ void *alignedAllocHost (size_t Alignment, size_t Size, const sycl::context &Ctxt,
34
+ const sycl::property_list &PropList,
35
+ const sycl::detail::code_location &CodeLoc) {
46
36
#ifdef XPTI_ENABLE_INSTRUMENTATION
47
37
// Stash the code location information and propagate
48
- detail::tls_code_loc_t CL (CodeLoc);
49
- XPTIScope PrepareNotify (( void *)alignedAllocHost,
50
- (uint16_t )xpti::trace_point_type_t ::node_create,
51
- SYCL_MEM_ALLOC_STREAM_NAME, " malloc_host" );
38
+ sycl:: detail::tls_code_loc_t CL (CodeLoc);
39
+ sycl::detail:: XPTIScope PrepareNotify (
40
+ ( void *)alignedAllocHost, (uint16_t )xpti::trace_point_type_t ::node_create,
41
+ sycl::detail:: SYCL_MEM_ALLOC_STREAM_NAME, " malloc_host" );
52
42
PrepareNotify.addMetadata ([&](auto TEvent) {
53
43
xpti::addMetadata (TEvent, " sycl_device_name" , std::string (" Host" ));
54
44
xpti::addMetadata (TEvent, " sycl_device" , 0 );
@@ -72,13 +62,12 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
72
62
if (Size == 0 )
73
63
return nullptr ;
74
64
75
- std::shared_ptr<context_impl> CtxImpl = detail::getSyclObjImpl (Ctxt);
65
+ std::shared_ptr<sycl::detail::context_impl> CtxImpl =
66
+ sycl::detail::getSyclObjImpl (Ctxt);
76
67
ur_context_handle_t C = CtxImpl->getHandleRef ();
77
- const PluginPtr &Plugin = CtxImpl->getPlugin ();
68
+ const sycl::detail:: PluginPtr &Plugin = CtxImpl->getPlugin ();
78
69
ur_result_t Error = UR_RESULT_ERROR_INVALID_VALUE;
79
70
80
- switch (Kind) {
81
- case alloc::host: {
82
71
ur_usm_desc_t UsmDesc{};
83
72
UsmDesc.align = Alignment;
84
73
@@ -100,17 +89,6 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
100
89
Error = Plugin->call_nocheck (urUSMHostAlloc, C, &UsmDesc,
101
90
/* pool= */ nullptr , Size, &RetVal);
102
91
103
- break ;
104
- }
105
- case alloc::device:
106
- case alloc::shared:
107
- case alloc::unknown: {
108
- RetVal = nullptr ;
109
- Error = UR_RESULT_ERROR_INVALID_VALUE;
110
- break ;
111
- }
112
- }
113
-
114
92
// Error is for debugging purposes.
115
93
// The spec wants a nullptr returned, not an exception.
116
94
if (Error != UR_RESULT_SUCCESS)
@@ -121,6 +99,18 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
121
99
#endif
122
100
return RetVal;
123
101
}
102
+ } // namespace
103
+
104
+ namespace sycl {
105
+ inline namespace _V1 {
106
+
107
+ using alloc = sycl::usm::alloc;
108
+
109
+ namespace detail {
110
+ #ifdef XPTI_ENABLE_INSTRUMENTATION
111
+ extern xpti::trace_event_data_t *GSYCLGraphEvent;
112
+ #endif
113
+ namespace usm {
124
114
125
115
void *alignedAllocInternal (size_t Alignment, size_t Size,
126
116
const context_impl *CtxImpl,
@@ -351,27 +341,23 @@ void free(void *ptr, const queue &Q, const detail::code_location &CodeLoc) {
351
341
352
342
void *malloc_host (size_t Size, const context &Ctxt,
353
343
const detail::code_location &CodeLoc) {
354
- return detail::usm::alignedAllocHost (0 , Size, Ctxt, alloc::host,
355
- property_list{}, CodeLoc);
344
+ return alignedAllocHost (0 , Size, Ctxt, property_list{}, CodeLoc);
356
345
}
357
346
358
347
void *malloc_host (size_t Size, const context &Ctxt,
359
348
const property_list &PropList,
360
349
const detail::code_location &CodeLoc) {
361
- return detail::usm::alignedAllocHost (0 , Size, Ctxt, alloc::host, PropList,
362
- CodeLoc);
350
+ return alignedAllocHost (0 , Size, Ctxt, PropList, CodeLoc);
363
351
}
364
352
365
353
void *malloc_host (size_t Size, const queue &Q,
366
354
const detail::code_location &CodeLoc) {
367
- return detail::usm::alignedAllocHost (0 , Size, Q.get_context (), alloc::host,
368
- property_list{}, CodeLoc);
355
+ return alignedAllocHost (0 , Size, Q.get_context (), property_list{}, CodeLoc);
369
356
}
370
357
371
358
void *malloc_host (size_t Size, const queue &Q, const property_list &PropList,
372
359
const detail::code_location &CodeLoc) {
373
- return detail::usm::alignedAllocHost (0 , Size, Q.get_context (), alloc::host,
374
- PropList, CodeLoc);
360
+ return alignedAllocHost (0 , Size, Q.get_context (), PropList, CodeLoc);
375
361
}
376
362
377
363
void *malloc_shared (size_t Size, const device &Dev, const context &Ctxt,
@@ -401,28 +387,25 @@ void *malloc_shared(size_t Size, const queue &Q, const property_list &PropList,
401
387
402
388
void *aligned_alloc_host (size_t Alignment, size_t Size, const context &Ctxt,
403
389
const detail::code_location &CodeLoc) {
404
- return detail::usm::alignedAllocHost (Alignment, Size, Ctxt, alloc::host,
405
- property_list{}, CodeLoc);
390
+ return alignedAllocHost (Alignment, Size, Ctxt, property_list{}, CodeLoc);
406
391
}
407
392
408
393
void *aligned_alloc_host (size_t Alignment, size_t Size, const context &Ctxt,
409
394
const property_list &PropList,
410
395
const detail::code_location &CodeLoc) {
411
- return detail::usm::alignedAllocHost (Alignment, Size, Ctxt, alloc::host,
412
- PropList, CodeLoc);
396
+ return alignedAllocHost (Alignment, Size, Ctxt, PropList, CodeLoc);
413
397
}
414
398
415
399
void *aligned_alloc_host (size_t Alignment, size_t Size, const queue &Q,
416
400
const detail::code_location &CodeLoc) {
417
- return detail::usm:: alignedAllocHost (Alignment, Size, Q.get_context (),
418
- alloc::host, property_list{}, CodeLoc);
401
+ return alignedAllocHost (Alignment, Size, Q.get_context (), property_list{} ,
402
+ CodeLoc);
419
403
}
420
404
421
405
void *aligned_alloc_host (size_t Alignment, size_t Size, const queue &Q,
422
406
const property_list &PropList,
423
407
const detail::code_location &CodeLoc) {
424
- return detail::usm::alignedAllocHost (Alignment, Size, Q.get_context (),
425
- alloc::host, PropList, CodeLoc);
408
+ return alignedAllocHost (Alignment, Size, Q.get_context (), PropList, CodeLoc);
426
409
}
427
410
428
411
void *aligned_alloc_shared (size_t Alignment, size_t Size, const device &Dev,
@@ -460,25 +443,22 @@ void *malloc(size_t Size, const device &Dev, const context &Ctxt, alloc Kind,
460
443
const property_list &PropList,
461
444
const detail::code_location &CodeLoc) {
462
445
if (Kind == alloc::host)
463
- return detail::usm::alignedAllocHost (0 , Size, Ctxt, Kind, PropList,
464
- CodeLoc);
446
+ return alignedAllocHost (0 , Size, Ctxt, PropList, CodeLoc);
465
447
return detail::usm::alignedAlloc (0 , Size, Ctxt, Dev, Kind, PropList, CodeLoc);
466
448
}
467
449
468
450
void *malloc (size_t Size, const device &Dev, const context &Ctxt, alloc Kind,
469
451
const detail::code_location &CodeLoc) {
470
452
if (Kind == alloc::host)
471
- return detail::usm::alignedAllocHost (0 , Size, Ctxt, Kind, property_list{},
472
- CodeLoc);
453
+ return alignedAllocHost (0 , Size, Ctxt, property_list{}, CodeLoc);
473
454
return detail::usm::alignedAlloc (0 , Size, Ctxt, Dev, Kind, property_list{},
474
455
CodeLoc);
475
456
}
476
457
477
458
void *malloc (size_t Size, const queue &Q, alloc Kind,
478
459
const detail::code_location &CodeLoc) {
479
460
if (Kind == alloc::host)
480
- return detail::usm::alignedAllocHost (0 , Size, Q.get_context (), Kind,
481
- property_list{}, CodeLoc);
461
+ return alignedAllocHost (0 , Size, Q.get_context (), property_list{}, CodeLoc);
482
462
return detail::usm::alignedAlloc (0 , Size, Q.get_context (), Q.get_device (),
483
463
Kind, property_list{}, CodeLoc);
484
464
}
@@ -487,8 +467,7 @@ void *malloc(size_t Size, const queue &Q, alloc Kind,
487
467
const property_list &PropList,
488
468
const detail::code_location &CodeLoc) {
489
469
if (Kind == alloc::host)
490
- return detail::usm::alignedAllocHost (0 , Size, Q.get_context (), Kind,
491
- PropList, CodeLoc);
470
+ return alignedAllocHost (0 , Size, Q.get_context (), PropList, CodeLoc);
492
471
return detail::usm::alignedAlloc (0 , Size, Q.get_context (), Q.get_device (),
493
472
Kind, PropList, CodeLoc);
494
473
}
@@ -497,8 +476,7 @@ void *aligned_alloc(size_t Alignment, size_t Size, const device &Dev,
497
476
const context &Ctxt, alloc Kind,
498
477
const detail::code_location &CodeLoc) {
499
478
if (Kind == alloc::host)
500
- return detail::usm::alignedAllocHost (Alignment, Size, Ctxt, Kind,
501
- property_list{}, CodeLoc);
479
+ return alignedAllocHost (Alignment, Size, Ctxt, property_list{}, CodeLoc);
502
480
503
481
return detail::usm::alignedAlloc (Alignment, Size, Ctxt, Dev, Kind,
504
482
property_list{}, CodeLoc);
@@ -509,17 +487,16 @@ void *aligned_alloc(size_t Alignment, size_t Size, const device &Dev,
509
487
const property_list &PropList,
510
488
const detail::code_location &CodeLoc) {
511
489
if (Kind == alloc::host)
512
- return detail::usm::alignedAllocHost (Alignment, Size, Ctxt, Kind, PropList,
513
- CodeLoc);
490
+ return alignedAllocHost (Alignment, Size, Ctxt, PropList, CodeLoc);
514
491
return detail::usm::alignedAlloc (Alignment, Size, Ctxt, Dev, Kind, PropList,
515
492
CodeLoc);
516
493
}
517
494
518
495
void *aligned_alloc (size_t Alignment, size_t Size, const queue &Q, alloc Kind,
519
496
const detail::code_location &CodeLoc) {
520
497
if (Kind == alloc::host)
521
- return detail::usm:: alignedAllocHost (Alignment, Size, Q.get_context (), Kind ,
522
- property_list{}, CodeLoc);
498
+ return alignedAllocHost (Alignment, Size, Q.get_context (), property_list{} ,
499
+ CodeLoc);
523
500
return detail::usm::alignedAlloc (Alignment, Size, Q.get_context (),
524
501
Q.get_device (), Kind, property_list{},
525
502
CodeLoc);
@@ -529,8 +506,8 @@ void *aligned_alloc(size_t Alignment, size_t Size, const queue &Q, alloc Kind,
529
506
const property_list &PropList,
530
507
const detail::code_location &CodeLoc) {
531
508
if (Kind == alloc::host)
532
- return detail::usm:: alignedAllocHost (Alignment, Size, Q.get_context (), Kind ,
533
- PropList, CodeLoc);
509
+ return alignedAllocHost (Alignment, Size, Q.get_context (), PropList ,
510
+ CodeLoc);
534
511
return detail::usm::alignedAlloc (Alignment, Size, Q.get_context (),
535
512
Q.get_device (), Kind, PropList, CodeLoc);
536
513
}
0 commit comments