Skip to content

Commit e60a5fa

Browse files
committed
auto_configure: add attributes of device global to autodiscovery string parsing and extend unit test
1 parent 5994a1c commit e60a5fa

File tree

3 files changed

+115
-22
lines changed

3 files changed

+115
-22
lines changed

include/acl.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,39 @@ typedef class acl_device_program_info_t *acl_device_program_info;
498498
*/
499499
#define ACL_MEM_CAPABILITY_P2P (1 << 3)
500500

501+
// Enum values here need to match the SPIRV spec for device global in
502+
// https://github.com/intel/llvm/blob/44c6437684d64aba82d5a3de0e4bbe21d2b1f7ce/sycl/doc/design/spirv-extensions/SPV_INTEL_global_variable_decorations.asciidoc
503+
// ACL_DEVICE_GLOBAL_HOST_ACCESS_TYPE_COUNT is used for validation
504+
// in autodiscovery string parsing and should remain the last constant
505+
// in the enum.
506+
typedef enum {
507+
ACL_DEVICE_GLOBAL_HOST_ACCESS_READ_ONLY,
508+
ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
509+
ACL_DEVICE_GLOBAL_HOST_ACCESS_READ_WRITE,
510+
ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
511+
512+
ACL_DEVICE_GLOBAL_HOST_ACCESS_TYPE_COUNT
513+
} acl_device_global_host_access_t;
514+
515+
// Enum values here also need to match the SPIRV spec for device
516+
// global in the above link for acl_device_global_host_access_t.
517+
// ACL_DEVICE_GLOBAL_INIT_MODE_TYPE_COUNT is used for validation in
518+
// autodiscovery string parsing and should remain the last constant
519+
// in the enum.
520+
typedef enum {
521+
ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM,
522+
ACL_DEVICE_GLOBAL_INIT_MODE_RESET,
523+
524+
ACL_DEVICE_GLOBAL_INIT_MODE_TYPE_COUNT
525+
} acl_device_global_init_mode_t;
526+
501527
// Definition of device global.
502528
struct acl_device_global_mem_def_t {
503-
uint32_t address;
529+
uint64_t address;
504530
uint32_t size;
531+
acl_device_global_host_access_t host_access;
532+
acl_device_global_init_mode_t init_mode;
533+
bool implement_in_csr;
505534
};
506535

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

src/acl_auto_configure.cpp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ static bool read_uint32_counters(const std::string &str,
137137
return true;
138138
}
139139

140+
// Reads the next word in str and converts it into an unsigned 64-bit
141+
// fixed-length integer. Note this read utilizes stoull and fail if
142+
// unsigned long long is not 64-bit long on the platform.
143+
// Returns true if a valid integer was read or false if an error occurred.
144+
// pos is updated to the position immediately following the parsed word
145+
// even if an error occurs.
146+
static bool read_uint64_counters(const std::string &str,
147+
std::string::size_type &pos, uint64_t &val,
148+
std::vector<int> &counters) noexcept {
149+
std::string result;
150+
pos = read_word(str, pos, result);
151+
decrement_section_counters(counters);
152+
try {
153+
static_assert(sizeof(uint64_t) == sizeof(unsigned long long));
154+
val = static_cast<uint64_t>(std::stoull(result));
155+
} catch (const std::exception &e) {
156+
UNREFERENCED_PARAMETER(e);
157+
return false;
158+
}
159+
return true;
160+
}
161+
140162
// Reads the next word in str and converts it into an unsigned.
141163
// Returns true if a valid integer was read or false if an error occurred.
142164
// pos is updated to the position immediately following the parsed word
@@ -470,6 +492,9 @@ static bool read_device_global_mem_defs(
470492
total_fields_device_global, counters);
471493
}
472494

495+
// Clean up any residual information first
496+
device_global_mem_defs.clear();
497+
473498
for (auto i = 0U; result && (i < num_device_global); i++) {
474499
counters.emplace_back(total_fields_device_global);
475500

@@ -481,10 +506,10 @@ static bool read_device_global_mem_defs(
481506
}
482507

483508
// read device global address
484-
uint32_t dev_global_addr = 0; // Default
509+
uint64_t dev_global_addr = 0; // Default
485510
if (result && counters.back() > 0) {
486511
result =
487-
read_uint32_counters(config_str, curr_pos, dev_global_addr, counters);
512+
read_uint64_counters(config_str, curr_pos, dev_global_addr, counters);
488513
}
489514
// read device global address size
490515
uint32_t dev_global_size = 0; // Default
@@ -493,8 +518,34 @@ static bool read_device_global_mem_defs(
493518
read_uint32_counters(config_str, curr_pos, dev_global_size, counters);
494519
}
495520

496-
acl_device_global_mem_def_t dev_global_def = {dev_global_addr,
497-
dev_global_size};
521+
// read device global properties
522+
auto host_access =
523+
static_cast<unsigned>(ACL_DEVICE_GLOBAL_HOST_ACCESS_READ_WRITE);
524+
if (result && counters.back() > 0) {
525+
result = read_uint_counters(config_str, curr_pos, host_access, counters);
526+
if (host_access >=
527+
static_cast<unsigned>(ACL_DEVICE_GLOBAL_HOST_ACCESS_TYPE_COUNT))
528+
result = false;
529+
}
530+
auto init_mode =
531+
static_cast<unsigned>(ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM);
532+
if (result && counters.back() > 0) {
533+
result = read_uint_counters(config_str, curr_pos, init_mode, counters);
534+
if (init_mode >=
535+
static_cast<unsigned>(ACL_DEVICE_GLOBAL_INIT_MODE_TYPE_COUNT))
536+
result = false;
537+
}
538+
bool implement_in_csr = false;
539+
if (result && counters.back() > 0) {
540+
result =
541+
read_bool_counters(config_str, curr_pos, implement_in_csr, counters);
542+
}
543+
544+
acl_device_global_mem_def_t dev_global_def = {
545+
dev_global_addr, dev_global_size,
546+
static_cast<acl_device_global_host_access_t>(host_access),
547+
static_cast<acl_device_global_init_mode_t>(init_mode),
548+
implement_in_csr};
498549
bool ok =
499550
device_global_mem_defs.insert({device_global_name, dev_global_def})
500551
.second;

test/acl_auto_configure_test.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(auto_configure, simple) {
3636
#define VERSIONIDSTRINGIFY(x) #x
3737
#define VERSIONIDTOSTR(x) VERSIONIDSTRINGIFY(x)
3838
#define DEVICE_FIELDS " 23"
39-
#define DEVICE_FIELDS_DEV_GLOBAL " 30"
39+
#define DEVICE_FIELDS_DEV_GLOBAL " 36"
4040
#define DEVICE_FIELDS_OLD " 18"
4141
#define BOARDNAME "de4_gen2x4_swdimm"
4242
#define BOARDNAME2 "pcie385_a7"
@@ -99,10 +99,11 @@ TEST(auto_configure, simple) {
9999

100100
// Device global autodiscovery entries
101101
#define NUM_DEV_GLOBAL " 2"
102-
#define NUM_DEV_GLOBAL_FIELD " 3" // containing dev_globa_name, address, size
103-
#define DEV_GLOBAL_1 \
104-
" kernel15_dev_global 4096 2048" // in format of dev_globa_name, address, size
105-
#define DEV_GLOBAL_2 " kernel15_dev_global2 2048 1024"
102+
#define NUM_DEV_GLOBAL_FIELD \
103+
" 6" // contains dev_globa_name, address, size, host_access, init_mode,
104+
// implement_in_csr with the above format
105+
#define DEV_GLOBAL_1 " kernel15_dev_global 4096 2048 3 1 0"
106+
#define DEV_GLOBAL_2 " kernel15_dev_global2 2048 1024 1 0 1"
106107

107108
int parsed;
108109
std::string err_str;
@@ -283,8 +284,18 @@ TEST(auto_configure, simple) {
283284
m_device_def.autodiscovery_def.device_global_mem_defs.end());
284285
CHECK_EQUAL(4096, kernel15_dev_global->second.address);
285286
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
287+
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
288+
kernel15_dev_global->second.host_access);
289+
CHECK_EQUAL(ACL_DEVICE_GLOBAL_INIT_MODE_RESET,
290+
kernel15_dev_global->second.init_mode);
291+
CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr);
286292
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
287293
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
294+
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
295+
kernel15_dev_global2->second.host_access);
296+
CHECK_EQUAL(ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM,
297+
kernel15_dev_global2->second.init_mode);
298+
CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr);
288299

289300
// Check a second parsing.
290301
// It should allocate a new string for the name.
@@ -482,11 +493,13 @@ TEST(auto_configure, many_ok_forward_compatibility) {
482493
// sections and subsections to check forward compatibility
483494

484495
std::string str(VERSIONIDTOSTR(
485-
ACL_AUTO_CONFIGURE_VERSIONID) " 29 "
496+
ACL_AUTO_CONFIGURE_VERSIONID) " 49 "
486497
"sample40byterandomhash000000000000000000 "
487-
"a10gx 0 1 15 DDR 2 1 6 0 2147483648 100 "
488-
"100 100 100 200 200 200 200 0 0 0 0 2 "
489-
"1 name1 name2 0 0 47 "
498+
"a10gx 0 1 17 DDR 2 1 6 0 2147483648 100 "
499+
"100 100 100 0 - 0 200 200 200 200 0 0 0 "
500+
"2 9 ms_dev_global1 2048 1024 3 0 0 300 "
501+
"300 300 ms_dev_global2 4096 1024 1 1 1 "
502+
"300 300 300 0 0 400 400 47 "
490503
"40 external_sort_stage_0 0 128 1 0 0 1 0 "
491504
"1 0 1 10 0 0 4 1 0 0 0 500 500 500 0 0 "
492505
"0 0 1 1 1 3 1 1 1 3 1 0 0 800 800 800 "
@@ -677,10 +690,10 @@ TEST(auto_configure, many_ok_forward_compatibility) {
677690

678691
TEST(auto_configure, many_limit_check) {
679692
std::string str(VERSIONIDTOSTR(
680-
ACL_AUTO_CONFIGURE_VERSIONID) " 15 "
693+
ACL_AUTO_CONFIGURE_VERSIONID) " 19 "
681694
"sample40byterandomhash000000000000000000 "
682-
"a10gx 0 1 7 DDR 2 1 2 0 2147483648 0 0 0 "
683-
"0 75 "
695+
"a10gx 0 1 9 DDR 2 1 2 0 2147483648 0 - 0 "
696+
"0 0 0 0 0 75 " // 75 kernels
684697
"31 external_sort_stage_0 0 128 1 0 0 1 0 "
685698
"1 0 1 6 0 0 4 1 0 0 0 0 0 0 1 1 1 3 1 1 1 "
686699
"3 1 "
@@ -1193,14 +1206,14 @@ TEST(auto_configure, kernel_arg_info) {
11931206

11941207
TEST(auto_configure, hostpipe) {
11951208
std::string str(VERSIONIDTOSTR(
1196-
ACL_AUTO_CONFIGURE_VERSIONID) " 46 "
1209+
ACL_AUTO_CONFIGURE_VERSIONID) " 49 "
11971210
"sample40byterandomhash000000000000000000 "
11981211
"a10gx_hostpipe 0 1 15 DDR 2 1 6 0 "
11991212
"2147483648 0 100 100 100 100 200 200 200 "
12001213
"200 "
12011214
"2 9 host_to_dev 1 0 32 32768 300 300 300 "
12021215
"300 dev_to_host 0 1 32 32768 300 300 300 "
1203-
"300 400 1 3 name3 400 0 "
1216+
"300 400 1 6 dev_global_3 1024 2048 0 0 0 "
12041217
"1 29 foo 0 128 1 0 0 1 0 1 0 0 0 0 0 0 1 "
12051218
"1 1 3 1 1 1 3 1 0 0 800 800 800 900 "
12061219
"900"
@@ -1230,10 +1243,10 @@ TEST(auto_configure, hostpipe) {
12301243

12311244
TEST(auto_configure, streaming) {
12321245
const std::string config_str{
1233-
"23 26 " RANDOM_HASH
1246+
"23 29 " RANDOM_HASH
12341247
" pac_a10 0 1 13 DDR 2 2 24 1 2 0 4294967296 4294967296 8589934592 0 - 0 "
1235-
"0 0 0 1 3 device_global_name 256 128 1 105 _ZTS3CRCILi0EE 0 256 1 0 0 1 "
1236-
"0 1 0 9 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg0 8 2 1 8 1024 0 3 1 "
1248+
"0 0 0 1 6 device_global_name 256 128 0 0 0 1 105 _ZTS3CRCILi0EE 0 256 1 "
1249+
"0 0 1 0 1 0 9 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg0 8 2 1 8 1024 0 3 1 "
12371250
"k0_ZTS3CRCILi0EE_arg1 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg2 7 0 0 8 1 0 "
12381251
"0 0 7 0 0 8 1 0 0 0 7 2 1 8 1024 0 2 0 7 0 0 8 1 0 0 0 7 0 0 8 1 0 0 0 "
12391252
"7 0 0 8 1 0 0 0 0 0 1 2 64 4096 1 1 1 3 1 1 1 3 1 0 1 "

0 commit comments

Comments
 (0)