Skip to content

Commit d580bda

Browse files
committed
Update aocl_mmd.h version to 2024.2 and base buffer location support on MMD verison
1 parent 1422c0f commit d580bda

File tree

10 files changed

+697
-403
lines changed

10 files changed

+697
-403
lines changed

include/MMD/aocl_mmd.h

Lines changed: 466 additions & 346 deletions
Large diffs are not rendered by default.

include/acl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ typedef struct {
466466
cl_mem_alloc_flags_intel alloc_flags;
467467
cl_unified_shared_memory_type_intel type;
468468
cl_uint alignment; // May not be needed. Track for now.
469+
cl_uint host_shared_mem_id;
469470
} acl_usm_allocation_t;
470471

471472
typedef struct {
@@ -558,9 +559,10 @@ struct acl_sideband_signal_mapping {
558559
enum signal_type {
559560
SignalUnknown = -1,
560561
AvalonData = 0,
561-
AvalonSop = 1,
562-
AvalonEop = 2,
563-
AvalonEmpty = 3
562+
AvalonSOP = 1,
563+
AvalonEOP = 2, // Same as AXILast
564+
AvalonEmpty = 3,
565+
AXIUser = 4
564566
};
565567

566568
// Part of acl_device_def_t where members are populated from the information

include/acl_hal.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ typedef struct {
184184
int (*has_svm_memory_support)(unsigned int physical_device_id, int *value);
185185
/// Returns 1 if physical mem is supported
186186
int (*has_physical_mem)(unsigned int physical_device_id);
187+
/// Returns 1 if buffer location is supported across devices
188+
int (*support_buffer_location)(const std::vector<cl_device_id> &devices);
187189

188190
/// Get pointer to board specific extension functions
189191
void *(*get_board_extension_function_address)(
@@ -266,14 +268,7 @@ typedef struct {
266268
unsigned int physical_device_id, const char *interface_name,
267269
const void *host_addr, size_t dev_addr, size_t size);
268270

269-
/// Simulation only mmd call as of 2024.1
270-
/// Return the sideband signal buffer corresponding to the side band signal
271-
/// port identifier
272-
void *(*hostchannel_get_sideband_buffer)(unsigned int physical_device_id,
273-
unsigned int port_name,
274-
int channel_handle,
275-
size_t *buffer_size, int *status);
276-
271+
/// Simulation only hal function as of 2024.1
277272
/// Pull read_size of sideband data from the device into host_buffer, WITHOUT
278273
/// acknowledge
279274
size_t (*hostchannel_sideband_pull_no_ack)(unsigned int physical_device_id,
@@ -282,6 +277,7 @@ typedef struct {
282277
void *host_buffer,
283278
size_t read_size, int *status);
284279

280+
/// Simulation only hal function as of 2024.1
285281
/// Push write_size of sideband data to the device from host_buffer, WITHOUT
286282
/// acknowledge
287283
size_t (*hostchannel_sideband_push_no_ack)(unsigned int physical_device_id,

include/acl_hal_mmd.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,9 @@ typedef struct {
283283
// port identifier Get a pointer to the mmd buffer for the host channel
284284
// Simulation only mmd call as of 2024.1. HW MMD developer needs to implement
285285
// this function in the future To support hostpipe sideband signals.
286-
void *(*aocl_mmd_hostchannel_get_sideband_buffer)(int handle, int channel,
287-
int port_id,
288-
size_t *buffer_size,
289-
int *status);
286+
void *(*aocl_mmd_hostchannel_get_sideband_buffer)(
287+
int handle, int channel, aocl_mmd_hostchannel_port_id_t port_id,
288+
size_t *buffer_size, int *status);
290289

291290
} acl_mmd_dispatch_t;
292291

src/acl_hal_mmd.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ int acl_hal_mmd_simulation_device_global_interface_write(
185185
unsigned int physical_device_id, const char *interface_name,
186186
const void *host_addr, size_t dev_addr, size_t size);
187187

188-
void *acl_hal_mmd_hostchannel_get_sideband_buffer(
189-
unsigned int physical_device_id, unsigned int port_name, int channel_handle,
190-
size_t *buffer_size, int *status);
191-
192188
size_t acl_hal_mmd_hostchannel_sideband_pull_no_ack(
193189
unsigned int physical_device_id, unsigned int port_name, int channel_handle,
194190
void *host_buffer, size_t read_size, int *status);
@@ -209,6 +205,8 @@ static time_ns acl_bsp_get_timestamp(void);
209205

210206
int acl_hal_mmd_has_svm_support(unsigned int physical_device_id, int *value);
211207
int acl_hal_mmd_has_physical_mem(unsigned int physical_device_id);
208+
int acl_hal_mmd_support_buffer_location(
209+
const std::vector<cl_device_id> &devices);
212210

213211
static void *
214212
acl_hal_get_board_extension_function_address(const char *func_name,
@@ -296,6 +294,7 @@ static acl_hal_t acl_hal_mmd = {
296294
acl_hal_mmd_set_profile_stop_count, // set_profile_stop_cycle
297295
acl_hal_mmd_has_svm_support, // has_svm_memory_support
298296
acl_hal_mmd_has_physical_mem, // has_physical_mem
297+
acl_hal_mmd_support_buffer_location, // support_buffer_location
299298
acl_hal_get_board_extension_function_address, // get_board_extension_function_address
300299
acl_hal_mmd_pll_reconfigure, // pll_reconfigure
301300
acl_hal_mmd_reset_kernels, // reset_kernels
@@ -319,9 +318,8 @@ static acl_hal_t acl_hal_mmd = {
319318
acl_hal_mmd_write_csr, // write_csr
320319
acl_hal_mmd_simulation_device_global_interface_read, // simulation_device_global_interface_read
321320
acl_hal_mmd_simulation_device_global_interface_write, // simulation_device_global_interface_write
322-
acl_hal_mmd_hostchannel_get_sideband_buffer, // hostchannel_get_sideband_buffer
323-
acl_hal_mmd_hostchannel_sideband_pull_no_ack, // hostchannel_sideband_push
324-
acl_hal_mmd_hostchannel_sideband_push_no_ack, // hostchannel_sideband_push
321+
acl_hal_mmd_hostchannel_sideband_pull_no_ack, // hostchannel_sideband_pull_no_ack
322+
acl_hal_mmd_hostchannel_sideband_push_no_ack, // hostchannel_sideband_push_no_ack
325323
acl_hal_mmd_hostchannel_pull_no_ack, // hostchannel_pull_no_ack
326324
acl_hal_mmd_hostchannel_push_no_ack, // hostchannel_push_no_ack
327325
};
@@ -2496,23 +2494,6 @@ size_t acl_hal_mmd_hostchannel_ack_buffer(unsigned int physical_device_id,
24962494
pcie_dev_handle, channel_handle, ack_size, status);
24972495
}
24982496

2499-
void *acl_hal_mmd_hostchannel_get_sideband_buffer(
2500-
unsigned int physical_device_id, unsigned int port_name, int channel_handle,
2501-
size_t *buffer_size, int *status) {
2502-
2503-
int pcie_dev_handle;
2504-
2505-
pcie_dev_handle = device_info[physical_device_id].handle;
2506-
*status = 0;
2507-
2508-
// get the pointer to host channel mmd buffer
2509-
assert(device_info[physical_device_id]
2510-
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer);
2511-
return device_info[physical_device_id]
2512-
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer(
2513-
pcie_dev_handle, channel_handle, port_name, buffer_size, status);
2514-
}
2515-
25162497
size_t acl_hal_mmd_hostchannel_sideband_pull_no_ack(
25172498
unsigned int physical_device_id, unsigned int port_name, int channel_handle,
25182499
void *host_buffer, size_t read_size, int *status) {
@@ -2688,6 +2669,28 @@ int acl_hal_mmd_has_physical_mem(unsigned int physical_device_id) {
26882669
}
26892670
}
26902671

2672+
/**
2673+
* Returns if a set of devices all support buffer location mem property
2674+
* @param a vector of devices on which to query
2675+
* @return 1 if supported, else 0
2676+
*/
2677+
int acl_hal_mmd_support_buffer_location(
2678+
const std::vector<cl_device_id> &devices) {
2679+
acl_assert_locked();
2680+
2681+
int bl_supported = 1;
2682+
for (const auto &device : devices) {
2683+
unsigned int physical_device_id = device->def.physical_device_id;
2684+
if (MMDVERSION_LESSTHAN(
2685+
device_info[physical_device_id].mmd_dispatch->mmd_version,
2686+
2024.2)) {
2687+
bl_supported = 0;
2688+
}
2689+
}
2690+
2691+
return bl_supported;
2692+
}
2693+
26912694
#ifdef _WIN32
26922695
// Query the system timer, return a timer value in ns
26932696
cl_ulong acl_hal_mmd_get_timestamp() {

src/acl_offline_hal.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static const acl_hal_t acl_offline_hal = {
143143
acl_offline_hal_set_profile_stop_cycle,
144144
acl_offline_hal_has_svm_memory_support,
145145
acl_offline_hal_has_physical_mem,
146+
NULL,
146147
acl_offline_hal_get_board_extension_function_address,
147148
acl_offline_hal_pll_reconfigure,
148149
acl_offline_hal_reset_kernels,

src/acl_usm.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
143143
}
144144
}
145145

146+
bool track_mem_id = false;
146147
if (acl_get_hal()->host_alloc) {
147148
std::array<mem_properties_t, 3> mmd_properties;
148149
{
149150
auto mmd_properties_it = mmd_properties.begin();
150151
if (mem_id) {
151-
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
152+
if (acl_get_hal()->support_buffer_location(devices)) {
153+
track_mem_id = true;
152154
*mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
153155
*mmd_properties_it++ = *mem_id;
154156
}
@@ -197,6 +199,10 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
197199
usm_alloc->alloc_flags = alloc_flags;
198200
usm_alloc->type = CL_MEM_TYPE_HOST_INTEL;
199201
usm_alloc->alignment = alignment;
202+
usm_alloc->host_shared_mem_id = 0; // Initialize to 0
203+
if (track_mem_id) {
204+
usm_alloc->host_shared_mem_id = *mem_id;
205+
}
200206

201207
l_add_usm_alloc_to_context(context, usm_alloc);
202208
return mem;
@@ -434,12 +440,15 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
434440
properties += 2;
435441
}
436442

443+
bool track_mem_id = false;
437444
if (acl_get_hal()->shared_alloc) {
438445
std::array<mem_properties_t, 3> mmd_properties;
439446
{
440447
auto mmd_properties_it = mmd_properties.begin();
441448
if (mem_id) {
442-
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
449+
if (acl_get_hal()->support_buffer_location(
450+
std::vector<cl_device_id>{device})) {
451+
track_mem_id = true;
443452
*mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
444453
*mmd_properties_it++ = *mem_id;
445454
}
@@ -488,6 +497,10 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
488497
usm_alloc->alloc_flags = alloc_flags;
489498
usm_alloc->type = CL_MEM_TYPE_SHARED_INTEL;
490499
usm_alloc->alignment = alignment;
500+
usm_alloc->host_shared_mem_id = 0; // Initialize to 0
501+
if (track_mem_id) {
502+
usm_alloc->host_shared_mem_id = *mem_id;
503+
}
491504

492505
l_add_usm_alloc_to_context(context, usm_alloc);
493506
return mem;
@@ -554,6 +567,7 @@ CL_API_ENTRY cl_int CL_API_CALL clMemFreeINTEL(cl_context context, void *ptr) {
554567

555568
l_remove_usm_alloc_from_context(context, usm_alloc);
556569
acl_free(usm_alloc);
570+
usm_alloc = nullptr;
557571

558572
return CL_SUCCESS;
559573
}
@@ -617,6 +631,7 @@ CL_API_ENTRY cl_int CL_API_CALL clMemBlockingFreeINTEL(cl_context context,
617631

618632
l_remove_usm_alloc_from_context(context, usm_alloc);
619633
acl_free(usm_alloc);
634+
usm_alloc = nullptr;
620635

621636
return CL_SUCCESS;
622637
}
@@ -650,7 +665,11 @@ CL_API_ENTRY cl_int CL_API_CALL clGetMemAllocInfoINTEL(
650665

651666
case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
652667
if (usm_alloc) {
653-
RESULT_UINT(usm_alloc->mem->mem_id);
668+
if (usm_alloc->mem) {
669+
RESULT_UINT(usm_alloc->mem->mem_id);
670+
} else {
671+
RESULT_UINT(usm_alloc->host_shared_mem_id);
672+
}
654673
} else {
655674
RESULT_UINT(0);
656675
}

test/acl_hal_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static int acl_test_svm_memory_support =
3030
(CL_DEVICE_SVM_COARSE_GRAIN_BUFFER | CL_DEVICE_SVM_FINE_GRAIN_BUFFER |
3131
CL_DEVICE_SVM_FINE_GRAIN_SYSTEM);
3232
static bool acl_test_physical_memory_support = true;
33+
static bool acl_test_buffer_location_support = true;
3334

3435
// Parts of a valid HAL.
3536
void acltest_hal_init_device(const acl_system_def_t *def);
@@ -81,6 +82,8 @@ int acltest_hal_set_profile_stop_cycle(unsigned int physical_device_id,
8182
unsigned int accel_id, uint64_t value);
8283
int acl_test_hal_has_svm_support(unsigned int physical_device_id, int *value);
8384
int acl_test_hal_has_physical_mem(unsigned int physical_device_id);
85+
int acl_test_hal_support_buffer_location(
86+
const std::vector<cl_device_id> &devices);
8487
int acl_test_hal_pll_reconfigure(unsigned int physical_device_id,
8588
const char *pll_settings_str);
8689
void acl_test_hal_reset_kernels(cl_device_id device);
@@ -128,6 +131,7 @@ static const acl_hal_t simple_hal = {acltest_hal_init_device,
128131
acltest_hal_set_profile_stop_cycle,
129132
acl_test_hal_has_svm_support,
130133
acl_test_hal_has_physical_mem,
134+
acl_test_hal_support_buffer_location,
131135
0,
132136
acl_test_hal_pll_reconfigure,
133137
acl_test_hal_reset_kernels,
@@ -589,6 +593,10 @@ void acl_test_hal_set_physical_memory_support(bool value) {
589593
acl_test_physical_memory_support = value;
590594
}
591595

596+
void acl_test_hal_set_buffer_location_support(bool value) {
597+
acl_test_buffer_location_support = value;
598+
}
599+
592600
int acl_test_hal_has_svm_support(unsigned int physical_device_id, int *value) {
593601
physical_device_id = physical_device_id; // Avoid Windows warning
594602
*value = acl_test_svm_memory_support;
@@ -600,6 +608,11 @@ int acl_test_hal_has_physical_mem(unsigned int physical_device_id) {
600608
return acl_test_physical_memory_support;
601609
}
602610

611+
int acl_test_hal_support_buffer_location(
612+
const std::vector<cl_device_id> &devices) {
613+
return acl_test_buffer_location_support;
614+
}
615+
603616
int acl_test_hal_pll_reconfigure(unsigned int physical_device_id,
604617
const char *pll_settings_str) {
605618
physical_device_id = physical_device_id;

test/acl_hal_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void *acltest_translate_device_address(const void *device_ptr, size_t offset);
1616

1717
void acl_test_hal_set_svm_memory_support(int value);
1818
void acl_test_hal_set_physical_memory_support(bool value);
19+
void acl_test_hal_set_buffer_location_support(bool value);
1920

2021
extern bool acltest_hal_emulate_device_mem;
2122

0 commit comments

Comments
 (0)