Skip to content

Auto discovery change for device global #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions include/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,25 +512,16 @@ typedef enum {
ACL_DEVICE_GLOBAL_HOST_ACCESS_TYPE_COUNT
} acl_device_global_host_access_t;

// Enum values here also need to match the SPIRV spec for device
// global in the above link for acl_device_global_host_access_t.
// ACL_DEVICE_GLOBAL_INIT_MODE_TYPE_COUNT is used for validation in
// autodiscovery string parsing and should remain the last constant
// in the enum.
typedef enum {
ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM,
ACL_DEVICE_GLOBAL_INIT_MODE_RESET,

ACL_DEVICE_GLOBAL_INIT_MODE_TYPE_COUNT
} acl_device_global_init_mode_t;

// Definition of device global.
struct acl_device_global_mem_def_t {
uint64_t address;
uint32_t size;
acl_device_global_host_access_t host_access;
acl_device_global_init_mode_t init_mode;
// every device global has the same value for can_skip_programming
bool can_skip_programming;
bool implement_in_csr;
// every device global has the same value for reset_on_reuse
bool reset_on_reuse;
};

// Part of acl_device_def_t where members are populated from the information
Expand Down
22 changes: 13 additions & 9 deletions src/acl_auto_configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,25 +528,29 @@ static bool read_device_global_mem_defs(
static_cast<unsigned>(ACL_DEVICE_GLOBAL_HOST_ACCESS_TYPE_COUNT))
result = false;
}
auto init_mode =
static_cast<unsigned>(ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM);
bool can_skip_programming = false;
if (result && counters.back() > 0) {
result = read_uint_counters(config_str, curr_pos, init_mode, counters);
if (init_mode >=
static_cast<unsigned>(ACL_DEVICE_GLOBAL_INIT_MODE_TYPE_COUNT))
result = false;
result = read_bool_counters(config_str, curr_pos, can_skip_programming,
counters);
}
bool implement_in_csr = false;
if (result && counters.back() > 0) {
result =
read_bool_counters(config_str, curr_pos, implement_in_csr, counters);
}
bool reset_on_reuse = false;
if (result && counters.back() > 0) {
result =
read_bool_counters(config_str, curr_pos, reset_on_reuse, counters);
}

acl_device_global_mem_def_t dev_global_def = {
dev_global_addr, dev_global_size,
dev_global_addr,
dev_global_size,
static_cast<acl_device_global_host_access_t>(host_access),
static_cast<acl_device_global_init_mode_t>(init_mode),
implement_in_csr};
can_skip_programming,
implement_in_csr,
reset_on_reuse};
bool ok =
device_global_mem_defs.insert({device_global_name, dev_global_def})
.second;
Expand Down
3 changes: 1 addition & 2 deletions src/acl_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3016,8 +3016,7 @@ bool acl_device_has_reprogram_device_globals(cl_device_id device) {
std::find_if(device_global_mem_defs.begin(),
device_global_mem_defs.end(),
[](const auto &name_and_def) {
return name_and_def.second.init_mode ==
ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM;
return !name_and_def.second.can_skip_programming;
});
}

Expand Down
36 changes: 20 additions & 16 deletions test/acl_auto_configure_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(auto_configure, simple) {
#define VERSIONIDSTRINGIFY(x) #x
#define VERSIONIDTOSTR(x) VERSIONIDSTRINGIFY(x)
#define DEVICE_FIELDS " 23"
#define DEVICE_FIELDS_DEV_GLOBAL " 36"
#define DEVICE_FIELDS_DEV_GLOBAL " 38"
#define DEVICE_FIELDS_OLD " 18"
#define BOARDNAME "de4_gen2x4_swdimm"
#define BOARDNAME2 "pcie385_a7"
Expand Down Expand Up @@ -99,11 +99,11 @@ TEST(auto_configure, simple) {

// Device global autodiscovery entries
#define NUM_DEV_GLOBAL " 2"
#define NUM_DEV_GLOBAL_FIELD \
" 6" // contains dev_globa_name, address, size, host_access, init_mode,
// implement_in_csr with the above format
#define DEV_GLOBAL_1 " kernel15_dev_global 0x1000 2048 3 1 0"
#define DEV_GLOBAL_2 " kernel15_dev_global2 0x800 1024 1 0 1"
#define NUM_DEV_GLOBAL_FIELD " 7"
// The 7 fields are dev_globa_name, address, size, host_access,
// can_skip_programming, implement_in_csr, reset_on_reuse
#define DEV_GLOBAL_1 " kernel15_dev_global 0x1000 2048 3 0 0 0"
#define DEV_GLOBAL_2 " kernel15_dev_global2 0x800 1024 1 0 1 0"

int parsed;
std::string err_str;
Expand Down Expand Up @@ -286,16 +286,16 @@ TEST(auto_configure, simple) {
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
kernel15_dev_global->second.host_access);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_INIT_MODE_RESET,
kernel15_dev_global->second.init_mode);
CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming);
CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse);
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
kernel15_dev_global2->second.host_access);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM,
kernel15_dev_global2->second.init_mode);
CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming);
CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse);

// Check a second parsing.
// It should allocate a new string for the name.
Expand Down Expand Up @@ -493,12 +493,14 @@ TEST(auto_configure, many_ok_forward_compatibility) {
// sections and subsections to check forward compatibility

std::string str(VERSIONIDTOSTR(
ACL_AUTO_CONFIGURE_VERSIONID) " 49 "
ACL_AUTO_CONFIGURE_VERSIONID) " 51 "
"sample40byterandomhash000000000000000000 "
"a10gx 0 1 17 DDR 2 1 6 0 2147483648 100 "
"100 100 100 0 - 0 200 200 200 200 0 0 0 "
"2 9 ms_dev_global1 0x800 1024 3 0 0 300 "
"2 10 ms_dev_global1 0x800 1024 3 0 0 0 "
"300 "
"300 300 ms_dev_global2 0x1000 1024 1 1 1 "
"0 "
"300 300 300 0 0 400 400 47 "
"40 external_sort_stage_0 0 128 1 0 0 1 0 "
"1 0 1 10 0 0 4 1 0 0 0 500 500 500 0 0 "
Expand Down Expand Up @@ -1206,14 +1208,15 @@ TEST(auto_configure, kernel_arg_info) {

TEST(auto_configure, hostpipe) {
std::string str(VERSIONIDTOSTR(
ACL_AUTO_CONFIGURE_VERSIONID) " 49 "
ACL_AUTO_CONFIGURE_VERSIONID) " 50 "
"sample40byterandomhash000000000000000000 "
"a10gx_hostpipe 0 1 15 DDR 2 1 6 0 "
"2147483648 0 100 100 100 100 200 200 200 "
"200 "
"2 9 host_to_dev 1 0 32 32768 300 300 300 "
"300 dev_to_host 0 1 32 32768 300 300 300 "
"300 400 1 6 dev_global_3 0x400 2048 0 0 0 "
"300 400 1 7 dev_global_3 0x400 2048 0 0 0 "
"0 "
"1 29 foo 0 128 1 0 0 1 0 1 0 0 0 0 0 0 1 "
"1 1 3 1 1 1 3 1 0 0 800 800 800 900 "
"900"
Expand Down Expand Up @@ -1243,9 +1246,10 @@ TEST(auto_configure, hostpipe) {

TEST(auto_configure, streaming) {
const std::string config_str{
"23 29 " RANDOM_HASH
"23 30 " RANDOM_HASH
" pac_a10 0 1 13 DDR 2 2 24 1 2 0 4294967296 4294967296 8589934592 0 - 0 "
"0 0 0 1 6 device_global_name 0x100 128 0 0 0 1 105 _ZTS3CRCILi0EE 0 256 "
"0 0 0 1 7 device_global_name 0x100 128 0 0 0 0 1 105 _ZTS3CRCILi0EE 0 "
"256 "
"1 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 k0_ZTS3CRCILi0EE_arg1 8 0 0 8 1 0 0 1 k0_ZTS3CRCILi0EE_arg2 7 0 0 8 1 "
"0 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 "
Expand Down
5 changes: 3 additions & 2 deletions test/acl_kernel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4350,8 +4350,9 @@ TEST(acl_kernel_reprogram_scheduler, device_global_reprogram) {
{/* address */ 1024,
/* size */ 1024,
/* host_access */ ACL_DEVICE_GLOBAL_HOST_ACCESS_READ_WRITE,
/* init_mode */ ACL_DEVICE_GLOBAL_INIT_MODE_REPROGRAM,
/* implement_in_csr */ false}});
/* can_skip_programming */ false,
/* implement_in_csr */ false,
/* reset_on_reuse */ false}});

// Initial eager reprogram
int offset = m_devlog.num_ops;
Expand Down