3
3
4
4
// System headers.
5
5
#include < algorithm>
6
+ #include < array>
6
7
#include < cassert>
7
8
#include < cstdio>
8
9
#include < iostream>
10
+ #include < optional>
9
11
#include < sstream>
10
12
#include < string>
11
13
#include < unordered_set>
28
30
#include < acl_usm.h>
29
31
#include < acl_util.h>
30
32
33
+ #include < MMD/aocl_mmd.h>
34
+
31
35
#ifdef __GNUC__
32
36
#pragma GCC visibility push(protected)
33
37
#endif
@@ -99,11 +103,15 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
99
103
// Iterate over properties.
100
104
// The end of the properties list is specified with a zero.
101
105
cl_mem_alloc_flags_intel alloc_flags = 0 ;
106
+ std::optional<cl_uint> mem_id;
102
107
while (properties != NULL && *properties != 0 ) {
103
108
switch (*properties) {
104
109
case CL_MEM_ALLOC_FLAGS_INTEL: {
105
110
alloc_flags = *(properties + 1 );
106
111
} break ;
112
+ case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
113
+ mem_id = (cl_uint) * (properties + 1 );
114
+ } break ;
107
115
default : {
108
116
UNLOCK_BAIL_INFO (CL_INVALID_PROPERTY, context, " Invalid properties" );
109
117
}
@@ -138,6 +146,16 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
138
146
}
139
147
140
148
if (acl_get_hal ()->host_alloc ) {
149
+ std::array<mem_properties_t , 3 > mmd_properties;
150
+ {
151
+ auto mmd_properties_it = mmd_properties.begin ();
152
+ if (mem_id) {
153
+ *mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
154
+ *mmd_properties_it++ = *mem_id;
155
+ }
156
+ *mmd_properties_it++ = 0 ;
157
+ }
158
+
141
159
acl_usm_allocation_t *usm_alloc =
142
160
(acl_usm_allocation_t *)acl_malloc (sizeof (acl_usm_allocation_t ));
143
161
@@ -146,7 +164,8 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
146
164
}
147
165
148
166
int error = 0 ;
149
- void *mem = acl_get_hal ()->host_alloc (devices, size, alignment, &error);
167
+ void *mem = acl_get_hal ()->host_alloc (devices, size, alignment,
168
+ mmd_properties.data (), &error);
150
169
if (error) {
151
170
acl_free (usm_alloc);
152
171
switch (error) {
@@ -380,6 +399,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
380
399
// The end of the properties list is specified with a zero.
381
400
cl_mem_alloc_flags_intel alloc_flags = 0 ;
382
401
std::unordered_set<unsigned long long > seen_flags;
402
+ std::optional<cl_uint> mem_id;
383
403
while (properties != NULL && *properties != 0 ) {
384
404
switch (*properties) {
385
405
case CL_MEM_ALLOC_FLAGS_INTEL: {
@@ -396,6 +416,14 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
396
416
}
397
417
alloc_flags = *(properties + 1 );
398
418
} break ;
419
+ case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
420
+ if (seen_flags.insert (CL_MEM_ALLOC_BUFFER_LOCATION_INTEL).second ==
421
+ false ) {
422
+ UNLOCK_BAIL_INFO (CL_INVALID_PROPERTY, context,
423
+ " Property specified multiple times" );
424
+ }
425
+ mem_id = (cl_uint) * (properties + 1 );
426
+ } break ;
399
427
default : {
400
428
UNLOCK_BAIL_INFO (CL_INVALID_PROPERTY, context, " Invalid properties" );
401
429
}
@@ -404,6 +432,16 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
404
432
}
405
433
406
434
if (acl_get_hal ()->shared_alloc ) {
435
+ std::array<mem_properties_t , 3 > mmd_properties;
436
+ {
437
+ auto mmd_properties_it = mmd_properties.begin ();
438
+ if (mem_id) {
439
+ *mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
440
+ *mmd_properties_it++ = *mem_id;
441
+ }
442
+ *mmd_properties_it++ = 0 ;
443
+ }
444
+
407
445
acl_usm_allocation_t *usm_alloc =
408
446
(acl_usm_allocation_t *)acl_malloc (sizeof (acl_usm_allocation_t ));
409
447
@@ -412,8 +450,8 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
412
450
}
413
451
414
452
int error;
415
- void *mem =
416
- acl_get_hal ()-> shared_alloc (device, size, alignment, nullptr , &error);
453
+ void *mem = acl_get_hal ()-> shared_alloc (device, size, alignment,
454
+ mmd_properties. data () , &error);
417
455
if (mem == NULL ) {
418
456
acl_free (usm_alloc);
419
457
switch (error) {
0 commit comments