Skip to content

Cache context offline device setting specified by environment variables #235

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
Jan 6, 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
4 changes: 4 additions & 0 deletions include/acl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,10 @@ typedef struct _cl_platform_id
// The setting of environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA, if
// any.
std::string offline_device;
// Cache context offline mode specified by environment variables
// CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA, CL_CONTEXT_MPSIM_DEVICE_INTELFPGA
// or CL_CONTEXT_MSIM_DEVICE_INTELFPGA
int offline_mode;

// Should we track and automatically release leaked objects?
// This helps immensely with the OpenCL conformance tests which tend to
Expand Down
5 changes: 1 addition & 4 deletions src/acl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ static cl_int l_finalize_context(cl_context context, cl_uint num_devices,
static cl_int l_load_properties(cl_context context,
const cl_context_properties *properties) {
const char *default_compile_cmd = 0;
int env_override = 0;
acl_assert_locked();

// Set defaults.
Expand Down Expand Up @@ -717,8 +716,6 @@ static cl_int l_load_properties(cl_context context,
// Always terminate list. After all, 'properties' might be empty!
context->properties[context->num_property_entries++] = 0;

(void)acl_get_offline_device_user_setting(&env_override);

context->compiles_programs_incompletely = 0;
switch (context->compiler_mode) {
case static_cast<acl_compiler_mode_t>(
Expand Down Expand Up @@ -788,7 +785,7 @@ static cl_int l_load_properties(cl_context context,
// We need backing store for the buffers.
context->device_buffers_have_backing_store = 1;

if (env_override == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
// Simulator should support save/restore buffers around programming if
// reprogramming on-the-fly is supported
context->saves_and_restores_buffers_for_reprogramming = 1;
Expand Down
15 changes: 6 additions & 9 deletions src/acl_device_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,10 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
#define FAILREAD_MSG "Could not read parts of the program binary."
size_t data_len = 0;

int env_override = 0;

acl_assert_locked();

(void)acl_get_offline_device_user_setting(&env_override);

if (env_override == ACL_CONTEXT_MPSIM && !validate_compile_options &&
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM &&
!validate_compile_options &&
context->compiler_mode != CL_CONTEXT_COMPILER_MODE_OFFLINE_INTELFPGA &&
get_binary_len() < 1024) {
// IF the binary is ridiculously small (arbitrary number) we are going
Expand Down Expand Up @@ -258,7 +255,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
// runtime.
if (acl_pkg_section_exists(pkg, ".acl.rand_hash", &data_len) &&
dev_prog->device->loaded_bin == nullptr &&
env_override != ACL_CONTEXT_MPSIM) {
acl_platform.offline_mode != ACL_CONTEXT_MPSIM) {
std::vector<char> pkg_rand_hash(data_len + 1);
AND_CHECK(acl_pkg_read_section(pkg, ".acl.rand_hash", pkg_rand_hash.data(),
data_len + 1),
Expand Down Expand Up @@ -305,7 +302,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
// For simulator flow, we treat as if the device has already been
// programmed and check device global memory layout against
// dev_prog->device->last_bin
if (env_override == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
if (validate_memory_layout && dev_prog->device->last_bin) {
AND_CHECK(get_devdef().autodiscovery_def.num_global_mem_systems <=
1 ||
Expand Down Expand Up @@ -357,7 +354,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
is_simulator = 0;
if (status == CL_SUCCESS &&
acl_pkg_section_exists(pkg, ".acl.simulator_object", &data_len)) {
if (env_override != ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode != ACL_CONTEXT_MPSIM) {
acl_context_callback(
context,
"aocx contains simulated kernel, but simulation mode not set!");
Expand All @@ -382,7 +379,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
context,
"aocx contains unsupported legacy opencl emulated kernel for windows!");
}
if (status == CL_SUCCESS && env_override == ACL_CONTEXT_MPSIM &&
if (status == CL_SUCCESS && acl_platform.offline_mode == ACL_CONTEXT_MPSIM &&
!is_simulator) {
acl_context_callback(context,
"Simulation mode set but aocx is for hardware!");
Expand Down
1 change: 1 addition & 0 deletions src/acl_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void acl_reset(void) {
l_reset_present_board();

acl_platform.offline_device = "";
acl_platform.offline_mode = ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY;
acl_platform.num_devices = 0;
for (unsigned i = 0; i < ACL_MAX_DEVICE; ++i) {
acl_platform.device[i] = _cl_device_id();
Expand Down
2 changes: 1 addition & 1 deletion src/acl_hal_mmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ acl_mmd_get_system_definition(acl_system_def_t *sys,
#endif

// Dynamically load board mmd & symbols
acl_get_offline_device_user_setting(&use_offline_only);
(void)acl_get_offline_device_user_setting(&use_offline_only);
if (use_offline_only == ACL_CONTEXT_MPSIM) {

// Substitute the simulator MMD layer.
Expand Down
4 changes: 1 addition & 3 deletions src/acl_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2918,9 +2918,7 @@ static cl_int l_copy_and_adjust_arguments_for_device(
[needed_mem_id]);
#endif

int env_override = 0;
(void)acl_get_offline_device_user_setting(&env_override);
if (env_override == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
if (!acl_realloc_buffer_for_simulator(mem_obj, needed_physical_id,
needed_mem_id)) {
return CL_MEM_OBJECT_ALLOCATION_FAILURE;
Expand Down
4 changes: 1 addition & 3 deletions src/acl_kernel_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,
char description_size_lsb[KERNEL_ROM_SIZE_BYTES_READ + 1];
unsigned int size_location, version, size;
int result = 0;
int use_offline_only = 0;
acl_assert_locked();

assert(acl_bsp_io_is_valid(&bsp_io));
Expand All @@ -723,8 +722,7 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,

// The simulator doesn't have any kernel interface information until the aocx
// is loaded, which happens later.
acl_get_offline_device_user_setting(&use_offline_only);
if (use_offline_only == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
std::string err_msg;
auto parse_result = acl_load_device_def_from_str(
acl_shipped_board_cfgs[0].cfg, sysdef->device[0].autodiscovery_def,
Expand Down
16 changes: 6 additions & 10 deletions src/acl_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ const char *acl_platform_extensions() {
// Initialize the internal bookkeeping based on the system definition
// provided to us.
void acl_init_platform(void) {
int offline_mode = 0;
acl_assert_locked();

acl_platform.dispatch = &acl_icd_dispatch;
Expand All @@ -304,9 +303,9 @@ void acl_init_platform(void) {

// Set offline_device property
const char *offline_device =
acl_get_offline_device_user_setting(&offline_mode);
acl_get_offline_device_user_setting(&acl_platform.offline_mode);
if (offline_device) {
if (offline_mode == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
acl_platform.offline_device = ACL_MPSIM_DEVICE_NAME;
} else {
acl_platform.offline_device = offline_device;
Expand Down Expand Up @@ -383,7 +382,7 @@ void acl_init_platform(void) {
// having.
acl_platform.initial_board_def = acl_present_board_def();

switch (offline_mode) {
switch (acl_platform.offline_mode) {
case ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY:
acl_platform.num_devices =
acl_platform.initial_board_def->num_devices +
Expand All @@ -409,7 +408,7 @@ void acl_init_platform(void) {
l_add_device(static_cast<int>(i));
}

l_initialize_offline_devices(offline_mode);
l_initialize_offline_devices(acl_platform.offline_mode);

// Device operation queue.
acl_init_device_op_queue(&acl_platform.device_op_queue);
Expand Down Expand Up @@ -516,15 +515,12 @@ void acl_init_platform(void) {

void acl_finalize_init_platform(unsigned int num_devices,
const cl_device_id *devices) {
int offline_mode = 0;
int have_single_bank_with_shared_memory;
acl_assert_locked();
assert(num_devices > 0);

(void)acl_get_offline_device_user_setting(&offline_mode);

l_initialize_devices(acl_present_board_def(), offline_mode, num_devices,
devices);
l_initialize_devices(acl_present_board_def(), acl_platform.offline_mode,
num_devices, devices);

if (is_SOC_device()) {
size_t cur_num_banks =
Expand Down
4 changes: 1 addition & 3 deletions src/acl_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,9 +1638,7 @@ void acl_program_device(void *user_data, acl_device_op_t *op) {
dev_prog->device->def.autodiscovery_def =
dev_bin->get_devdef().autodiscovery_def;

int offline_mode = 0;
(void)acl_get_offline_device_user_setting(&offline_mode);
if (offline_mode == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
// Override the device name to the simulator.
// In function acl_device_binary_t::load_binary_pkg, the name member will
// be checked against the .acl.board section of the aocx file, which would
Expand Down
8 changes: 2 additions & 6 deletions src/acl_usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
{
auto mmd_properties_it = mmd_properties.begin();
if (mem_id) {
int use_offline_only;
acl_get_offline_device_user_setting(&use_offline_only);
if (use_offline_only == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
*mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
*mmd_properties_it++ = *mem_id;
}
Expand Down Expand Up @@ -433,9 +431,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
{
auto mmd_properties_it = mmd_properties.begin();
if (mem_id) {
int use_offline_only;
acl_get_offline_device_user_setting(&use_offline_only);
if (use_offline_only == ACL_CONTEXT_MPSIM) {
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
*mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
*mmd_properties_it++ = *mem_id;
}
Expand Down