Skip to content

Commit f05e6d4

Browse files
committed
Update aocl_mmd.h version to 2024.2
This change also: - Determines MMD buffer location support based on MMD verison - Formally define host pipe side band port id in aocl_mmd.h - Support querying buffer location on host/shared USM allocation
1 parent e62820e commit f05e6d4

13 files changed

+788
-427
lines changed

include/MMD/aocl_mmd.h

Lines changed: 474 additions & 348 deletions
Large diffs are not rendered by default.

include/acl.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ typedef struct {
468468
cl_mem_alloc_flags_intel alloc_flags;
469469
cl_unified_shared_memory_type_intel type;
470470
cl_uint alignment; // May not be needed. Track for now.
471+
cl_uint host_shared_mem_id;
471472
} acl_usm_allocation_t;
472473

473474
typedef struct {
@@ -558,16 +559,6 @@ struct acl_sideband_signal_mapping {
558559
unsigned sideband_size; // bit
559560
};
560561

561-
// Must match the definition in the compiler
562-
// Analysis/FPGAAnalysis/Utils/StreamParameters.h
563-
enum signal_type {
564-
SignalUnknown = -1,
565-
AvalonData = 0,
566-
AvalonSop = 1,
567-
AvalonEop = 2,
568-
AvalonEmpty = 3
569-
};
570-
571562
// Part of acl_device_def_t where members are populated from the information
572563
// in the autodiscovery string. This will get updated every time the device
573564
// is programmed with a new device binary as the new binary would contain a

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

include/acl_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ typedef struct host_op_struct {
296296
} host_op_t;
297297

298298
struct sideband_signal_t {
299-
unsigned port_identifier; // matches enum signal_type in acl.h
299+
unsigned port_identifier; // matches enum aocl_mmd_hostchannel_port_id_t in
300+
// aocl_mmd.h
300301
unsigned port_offset; // in bit
301302
unsigned side_band_size; // in bit
302303
};

src/acl_hal_mmd.cpp

Lines changed: 90 additions & 35 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
};
@@ -419,6 +417,39 @@ static int debug_verbosity = 0;
419417
// ************************** Helper functions ******************************
420418
// **************************************************************************
421419

420+
// Version string format should be MAJOR.MINOR(.PATCH)
421+
// To compare the MMD/HAL versions we will only compare the last two digits
422+
// of the MAJOR field together with the MINOR field, and ignore the PATCH field
423+
// if that exists. This function truncates the version string to exactly that
424+
// and convert it to double to be compared. Returns -1 if input is invalid.
425+
double l_parse_mmd_version_str(std::string version_str) {
426+
size_t start_idx, length;
427+
428+
// Find the '.' between the MAJOR and MINOR field
429+
std::string::size_type i = version_str.find('.');
430+
if (i == std::string::npos || i < 2) {
431+
return -1;
432+
} else {
433+
start_idx = i - 2;
434+
}
435+
// Check if there is a '.' for PATCH field
436+
std::string::size_type j = version_str.find('.', i + 1);
437+
length = (j == std::string::npos ? version_str.length() : j) - start_idx;
438+
439+
// Get the part of the MMD version string that will be used to compare
440+
// for compatibility with the runtime HAL
441+
std::string version_substr = version_str.substr(start_idx, length);
442+
double mmd_version_num = 0;
443+
try {
444+
mmd_version_num = std::stod(version_substr);
445+
} catch (const std::exception &) {
446+
// Just return error and let the caller handle failure
447+
return -1;
448+
}
449+
450+
return mmd_version_num;
451+
}
452+
422453
// MMD dynamic load helpers
423454
#ifdef _WIN32
424455
char *acl_strtok(char *str, const char *delim, char **saveptr) {
@@ -965,22 +996,40 @@ void l_get_physical_devices(acl_mmd_dispatch_t *mmd_dispatch,
965996
mmd_dispatch->aocl_mmd_get_offline_info(AOCL_MMD_VERSION, sizeof(buf), buf,
966997
NULL);
967998
buf[sizeof(buf) - 1] = 0;
968-
mmd_dispatch->mmd_version = atof(buf);
999+
mmd_dispatch->mmd_version = l_parse_mmd_version_str(std::string(buf));
1000+
if (mmd_dispatch->mmd_version < 0) {
1001+
printf(" Invalid MMD version: %s\n", buf);
1002+
printf("Contact the board package support vendor for resolution.\n");
1003+
fflush(stdout);
1004+
assert(0);
1005+
}
9691006
min_MMD_version =
9701007
(!MMDVERSION_LESSTHAN(min_MMD_version, mmd_dispatch->mmd_version))
9711008
? mmd_dispatch->mmd_version
9721009
: min_MMD_version;
9731010
ACL_HAL_DEBUG_MSG_VERBOSE(1, "HAL : Getting info version: %s\n", buf);
9741011

975-
if (MMDVERSION_LESSTHAN(atof(AOCL_MMD_VERSION_STRING),
1012+
static double hal_version = 0;
1013+
if (hal_version == 0) { // Just parse once at start-up
1014+
hal_version = l_parse_mmd_version_str(AOCL_MMD_VERSION_STRING);
1015+
if (hal_version < 0) { // This should theoretically never happen
1016+
printf(" Invalid runtime version: %s\n", AOCL_MMD_VERSION_STRING);
1017+
fflush(stdout);
1018+
assert(0);
1019+
}
1020+
}
1021+
if (MMDVERSION_LESSTHAN(hal_version,
9761022
mmd_dispatch->mmd_version) || // MMD newer than HAL
9771023
MMDVERSION_LESSTHAN(mmd_dispatch->mmd_version,
9781024
14.0)) // Before this wasn't forward compatible
9791025
{
9801026
printf(" Runtime version: %s\n", AOCL_MMD_VERSION_STRING);
9811027
printf(" MMD version: %s\n", buf);
1028+
printf("MMD version is newer than the runtime version! Use the runtime "
1029+
"with version greater or equal to the MMD version, or contact the "
1030+
"board support package vendors if mismatch is unexpected.\n");
9821031
fflush(stdout);
983-
assert(0 && "MMD version mismatch");
1032+
assert(0);
9841033
}
9851034

9861035
// Disable yield as initialization
@@ -2496,23 +2545,6 @@ size_t acl_hal_mmd_hostchannel_ack_buffer(unsigned int physical_device_id,
24962545
pcie_dev_handle, channel_handle, ack_size, status);
24972546
}
24982547

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-
25162548
size_t acl_hal_mmd_hostchannel_sideband_pull_no_ack(
25172549
unsigned int physical_device_id, unsigned int port_name, int channel_handle,
25182550
void *host_buffer, size_t read_size, int *status) {
@@ -2527,10 +2559,11 @@ size_t acl_hal_mmd_hostchannel_sideband_pull_no_ack(
25272559

25282560
assert(device_info[physical_device_id]
25292561
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer);
2530-
pull_buffer =
2531-
device_info[physical_device_id]
2532-
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer(
2533-
pcie_dev_handle, channel_handle, port_name, &buffer_size, status);
2562+
pull_buffer = device_info[physical_device_id]
2563+
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer(
2564+
pcie_dev_handle, channel_handle,
2565+
static_cast<aocl_mmd_hostchannel_port_id_t>(port_name),
2566+
&buffer_size, status);
25342567

25352568
if ((NULL == pull_buffer) || (0 == buffer_size)) {
25362569
return 0;
@@ -2563,10 +2596,11 @@ size_t acl_hal_mmd_hostchannel_sideband_push_no_ack(
25632596
assert(device_info[physical_device_id]
25642597
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer);
25652598

2566-
push_buffer =
2567-
device_info[physical_device_id]
2568-
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer(
2569-
pcie_dev_handle, channel_handle, port_name, &buffer_size, status);
2599+
push_buffer = device_info[physical_device_id]
2600+
.mmd_dispatch->aocl_mmd_hostchannel_get_sideband_buffer(
2601+
pcie_dev_handle, channel_handle,
2602+
static_cast<aocl_mmd_hostchannel_port_id_t>(port_name),
2603+
&buffer_size, status);
25702604

25712605
if ((NULL == push_buffer) || (0 == buffer_size)) {
25722606
return 0;
@@ -2688,6 +2722,27 @@ int acl_hal_mmd_has_physical_mem(unsigned int physical_device_id) {
26882722
}
26892723
}
26902724

2725+
/**
2726+
* Returns if a set of devices all support buffer location mem property
2727+
* @param a vector of devices on which to query
2728+
* @return 1 if supported, else 0
2729+
*/
2730+
int acl_hal_mmd_support_buffer_location(
2731+
const std::vector<cl_device_id> &devices) {
2732+
acl_assert_locked();
2733+
2734+
int bl_supported = 1;
2735+
for (const auto &device : devices) {
2736+
unsigned int physical_device_id = device->def.physical_device_id;
2737+
if (MMDVERSION_LESSTHAN(
2738+
device_info[physical_device_id].mmd_dispatch->mmd_version, 24.2)) {
2739+
bl_supported = 0;
2740+
}
2741+
}
2742+
2743+
return bl_supported;
2744+
}
2745+
26912746
#ifdef _WIN32
26922747
// Query the system timer, return a timer value in ns
26932748
cl_ulong acl_hal_mmd_get_timestamp() {

src/acl_hostch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static cl_int l_push_sideband_packet(unsigned int physical_device_id,
7171
for (auto const &sideband_signal_entry :
7272
host_pipe_info.side_band_signals_vector) {
7373
size_t pushed_data;
74-
if (sideband_signal_entry.port_identifier == AvalonData) {
74+
if (sideband_signal_entry.port_identifier ==
75+
static_cast<unsigned>(AOCL_MMD_HOSTCHANNEL_PORT_DATA)) {
7576
pushed_data = acl_get_hal()->hostchannel_push_no_ack(
7677
host_pipe_info.m_physical_device_id, host_pipe_info.m_channel_handle,
7778
(const void *)((char *)host_buffer +
@@ -117,7 +118,8 @@ static size_t l_pull_sideband_packet(unsigned int physical_device_id,
117118
for (auto const &sideband_signal_entry :
118119
host_pipe_info.side_band_signals_vector) {
119120
size_t pulled_data;
120-
if (sideband_signal_entry.port_identifier == AvalonData) {
121+
if (sideband_signal_entry.port_identifier ==
122+
static_cast<unsigned>(AOCL_MMD_HOSTCHANNEL_PORT_DATA)) {
121123
pulled_data = acl_get_hal()->hostchannel_pull_no_ack(
122124
host_pipe_info.m_physical_device_id, host_pipe_info.m_channel_handle,
123125
(void *)((char *)host_buffer + sideband_signal_entry.port_offset / 8),

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_program.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,8 @@ l_register_hostpipes_to_program(acl_device_program_info_t *dev_prog,
13961396

13971397
auto &host_pipe_info =
13981398
dev_prog->program_hostpipe_map.at(sideband_signal_mapping.logical_name);
1399-
if (sideband_signal_mapping.port_identifier != AvalonData) {
1399+
if (sideband_signal_mapping.port_identifier !=
1400+
static_cast<unsigned>(AOCL_MMD_HOSTCHANNEL_PORT_DATA)) {
14001401
host_pipe_info.num_side_band_signals++;
14011402
}
14021403

0 commit comments

Comments
 (0)