@@ -417,6 +417,39 @@ static int debug_verbosity = 0;
417
417
// ************************** Helper functions ******************************
418
418
// **************************************************************************
419
419
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
+
420
453
// MMD dynamic load helpers
421
454
#ifdef _WIN32
422
455
char *acl_strtok (char *str, const char *delim, char **saveptr) {
@@ -963,22 +996,40 @@ void l_get_physical_devices(acl_mmd_dispatch_t *mmd_dispatch,
963
996
mmd_dispatch->aocl_mmd_get_offline_info (AOCL_MMD_VERSION, sizeof (buf), buf,
964
997
NULL );
965
998
buf[sizeof (buf) - 1 ] = 0 ;
966
- 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
+ }
967
1006
min_MMD_version =
968
1007
(!MMDVERSION_LESSTHAN (min_MMD_version, mmd_dispatch->mmd_version ))
969
1008
? mmd_dispatch->mmd_version
970
1009
: min_MMD_version;
971
1010
ACL_HAL_DEBUG_MSG_VERBOSE (1 , " HAL : Getting info version: %s\n " , buf);
972
1011
973
- 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,
974
1022
mmd_dispatch->mmd_version ) || // MMD newer than HAL
975
1023
MMDVERSION_LESSTHAN (mmd_dispatch->mmd_version ,
976
1024
14.0 )) // Before this wasn't forward compatible
977
1025
{
978
1026
printf (" Runtime version: %s\n " , AOCL_MMD_VERSION_STRING);
979
1027
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 " );
980
1031
fflush (stdout);
981
- assert (0 && " MMD version mismatch " );
1032
+ assert (0 );
982
1033
}
983
1034
984
1035
// Disable yield as initialization
@@ -2682,8 +2733,7 @@ int acl_hal_mmd_support_buffer_location(
2682
2733
for (const auto &device : devices) {
2683
2734
unsigned int physical_device_id = device->def .physical_device_id ;
2684
2735
if (MMDVERSION_LESSTHAN (
2685
- device_info[physical_device_id].mmd_dispatch ->mmd_version ,
2686
- 2024.2 )) {
2736
+ device_info[physical_device_id].mmd_dispatch ->mmd_version , 24.2 )) {
2687
2737
bl_supported = 0 ;
2688
2738
}
2689
2739
}
0 commit comments