Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d32aac4

Browse files
committedJan 4, 2023
Cache context offline device setting specified by environment variables
1 parent d188f5c commit d32aac4

12 files changed

+110
-125
lines changed
 

‎include/acl_globals.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,8 @@ void acl_reset(void);
4444
// if it is not.
4545
cl_bool acl_init_from_hal_discovery(void);
4646

47-
// Looks at environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA.
48-
// If it exists and is prefixed by "+" then:
49-
// Return a pointer to the device name (without the "+" prefix).
50-
// Set *use_offline_ret_only = 1
51-
// If it exists and is not prefixed by "+" then
52-
// Return a pointer to the device name.
53-
// Set *use_offline_ret_only = 0
54-
#define ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY 0
55-
#define ACL_CONTEXT_OFFLINE_ONLY 1
56-
#define ACL_CONTEXT_MSIM 3
57-
#define ACL_CONTEXT_MPSIM 4
58-
const char *acl_get_offline_device_user_setting(int *use_offline_only_ret);
47+
acl_context_offline_mode_t
48+
acl_get_offline_device_user_setting(std::string *offline_device);
5949

6050
ACL_EXPORT
6151
extern struct _cl_platform_id acl_platform;

‎include/acl_types.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ typedef enum {
216216
ACL_COMPILER_MODE_NUM_MODES = CL_CONTEXT_COMPILER_MODE_NUM_MODES_INTELFPGA
217217
} acl_compiler_mode_t;
218218

219+
// Looks at environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA.
220+
// If it exists and is prefixed by "+" then:
221+
// Return a pointer to the device name (without the "+" prefix).
222+
// Set *use_offline_ret_only = 1
223+
// If it exists and is not prefixed by "+" then
224+
// Return a pointer to the device name.
225+
// Set *use_offline_ret_only = 0
226+
typedef enum {
227+
ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY,
228+
ACL_CONTEXT_OFFLINE_ONLY,
229+
ACL_CONTEXT_MSIM,
230+
ACL_CONTEXT_MPSIM
231+
} acl_context_offline_mode_t;
232+
219233
/* When a feature is still in development, it might need enum values
220234
* that are distinct from all published enums in the OpenCL token registry.
221235
* There is a reserved range for values for such "experimental" features.
@@ -1226,7 +1240,8 @@ typedef struct _cl_device_id {
12261240

12271241
unsigned int address_bits; // cache address bits to avoid GetDeviceInfo calls
12281242

1229-
int present; // Is the device present in the host system?
1243+
bool present; // Is the device present in the host system?
1244+
bool offline; // Is the device a real (i.e., not simulator) offline device?
12301245

12311246
// Error notification callback.
12321247
CL_EXCEPTION_TYPE_INTEL device_exception_status;
@@ -1573,9 +1588,16 @@ typedef struct _cl_platform_id
15731588
int device_exception_platform_counter; // indicates number of devices with at
15741589
// least one exception
15751590

1576-
// The setting of environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA, if
1577-
// any.
1578-
std::string offline_device;
1591+
// Record whether the platform has (non-simulator) offline device,
1592+
// value will be:
1593+
// 1: if there is a valid offline device specified by environment variable
1594+
// 0: if there is no offline device specified by environment variable
1595+
// -1: if the offline device specified by environment variable is invalid
1596+
int has_offline_device;
1597+
// Cache context offline mode specified by environment variables
1598+
// CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA, CL_CONTEXT_MPSIM_DEVICE_INTELFPGA
1599+
// or CL_CONTEXT_MSIM_DEVICE_INTELFPGA
1600+
acl_context_offline_mode_t offline_mode;
15791601

15801602
// Should we track and automatically release leaked objects?
15811603
// This helps immensely with the OpenCL conformance tests which tend to

‎src/acl_context.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ static void
4848
l_init_kernel_invocation_wrapper(acl_kernel_invocation_wrapper_t *wrapper,
4949
unsigned i);
5050
static void l_forcibly_release_allocations(cl_context context);
51-
static cl_device_id l_find_device_by_name(const std::string &name);
5251
static cl_int l_update_program_library_root(cl_context context,
5352
const char *new_root);
5453
static cl_int l_update_compile_command(cl_context context, const char *new_cmd);
@@ -553,7 +552,6 @@ static cl_int l_finalize_context(cl_context context, cl_uint num_devices,
553552
static cl_int l_load_properties(cl_context context,
554553
const cl_context_properties *properties) {
555554
const char *default_compile_cmd = 0;
556-
int env_override = 0;
557555
acl_assert_locked();
558556

559557
// Set defaults.
@@ -607,12 +605,11 @@ static cl_int l_load_properties(cl_context context,
607605
}
608606
}
609607

610-
// Environment variable can specify we always an offline device.
611-
if (!acl_platform.offline_device.empty()) {
612-
if (!l_find_device_by_name(acl_platform.offline_device))
613-
ERR_RET(CL_INVALID_VALUE, context,
614-
"Invalid offline device specified by environment variable "
615-
"CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA");
608+
// Check if environment variable specified offline device is valid
609+
if (acl_platform.has_offline_device < 0) {
610+
ERR_RET(CL_INVALID_VALUE, context,
611+
"Invalid offline device specified by environment variable "
612+
"CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA");
616613
}
617614

618615
// Get default for program_library_root.
@@ -717,8 +714,6 @@ static cl_int l_load_properties(cl_context context,
717714
// Always terminate list. After all, 'properties' might be empty!
718715
context->properties[context->num_property_entries++] = 0;
719716

720-
(void)acl_get_offline_device_user_setting(&env_override);
721-
722717
context->compiles_programs_incompletely = 0;
723718
switch (context->compiler_mode) {
724719
case static_cast<acl_compiler_mode_t>(
@@ -788,7 +783,7 @@ static cl_int l_load_properties(cl_context context,
788783
// We need backing store for the buffers.
789784
context->device_buffers_have_backing_store = 1;
790785

791-
if (env_override == ACL_CONTEXT_MPSIM) {
786+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
792787
// Simulator should support save/restore buffers around programming if
793788
// reprogramming on-the-fly is supported
794789
context->saves_and_restores_buffers_for_reprogramming = 1;
@@ -820,17 +815,6 @@ static cl_int l_load_properties(cl_context context,
820815
return CL_SUCCESS;
821816
}
822817

823-
static cl_device_id l_find_device_by_name(const std::string &name) {
824-
acl_assert_locked();
825-
826-
for (unsigned i = 0; i < acl_platform.num_devices; ++i) {
827-
if (name == acl_platform.device[i].def.autodiscovery_def.name) {
828-
return &(acl_platform.device[i]);
829-
}
830-
}
831-
return 0;
832-
}
833-
834818
// Initialize the given context.
835819
// Yes, this is like a "placement new".
836820
//
@@ -886,8 +870,6 @@ static cl_int l_init_context_with_devices(cl_context context,
886870
int num_present = 0;
887871
int num_absent = 0;
888872
for (cl_uint i = 0; i < num_devices; i++) {
889-
int usable = devices[i]->present;
890-
891873
// Can't mix both (actually) present and absent devices because there
892874
// is no consistent way to place device global memory.
893875
if (devices[i]->present) {
@@ -903,10 +885,7 @@ static cl_int l_init_context_with_devices(cl_context context,
903885
"Can't create a context with both offline and online devices");
904886
}
905887

906-
usable = usable || acl_platform.offline_device ==
907-
devices[i]->def.autodiscovery_def.name;
908-
909-
if (!usable)
888+
if (!devices[i]->present && !devices[i]->offline)
910889
ERR_RET(CL_DEVICE_NOT_AVAILABLE, context, "Device not available");
911890

912891
// Mark the device(s) as opened

‎src/acl_device_binary.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,10 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
175175
#define FAILREAD_MSG "Could not read parts of the program binary."
176176
size_t data_len = 0;
177177

178-
int env_override = 0;
179-
180178
acl_assert_locked();
181179

182-
(void)acl_get_offline_device_user_setting(&env_override);
183-
184-
if (env_override == ACL_CONTEXT_MPSIM && !validate_compile_options &&
180+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM &&
181+
!validate_compile_options &&
185182
context->compiler_mode != CL_CONTEXT_COMPILER_MODE_OFFLINE_INTELFPGA &&
186183
get_binary_len() < 1024) {
187184
// IF the binary is ridiculously small (arbitrary number) we are going
@@ -258,7 +255,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
258255
// runtime.
259256
if (acl_pkg_section_exists(pkg, ".acl.rand_hash", &data_len) &&
260257
dev_prog->device->loaded_bin == nullptr &&
261-
env_override != ACL_CONTEXT_MPSIM) {
258+
acl_platform.offline_mode != ACL_CONTEXT_MPSIM) {
262259
std::vector<char> pkg_rand_hash(data_len + 1);
263260
AND_CHECK(acl_pkg_read_section(pkg, ".acl.rand_hash", pkg_rand_hash.data(),
264261
data_len + 1),
@@ -305,7 +302,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
305302
// For simulator flow, we treat as if the device has already been
306303
// programmed and check device global memory layout against
307304
// dev_prog->device->last_bin
308-
if (env_override == ACL_CONTEXT_MPSIM) {
305+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
309306
if (validate_memory_layout && dev_prog->device->last_bin) {
310307
AND_CHECK(get_devdef().autodiscovery_def.num_global_mem_systems <=
311308
1 ||
@@ -357,7 +354,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
357354
is_simulator = 0;
358355
if (status == CL_SUCCESS &&
359356
acl_pkg_section_exists(pkg, ".acl.simulator_object", &data_len)) {
360-
if (env_override != ACL_CONTEXT_MPSIM) {
357+
if (acl_platform.offline_mode != ACL_CONTEXT_MPSIM) {
361358
acl_context_callback(
362359
context,
363360
"aocx contains simulated kernel, but simulation mode not set!");
@@ -382,7 +379,7 @@ cl_int acl_device_binary_t::load_binary_pkg(int validate_compile_options,
382379
context,
383380
"aocx contains unsupported legacy opencl emulated kernel for windows!");
384381
}
385-
if (status == CL_SUCCESS && env_override == ACL_CONTEXT_MPSIM &&
382+
if (status == CL_SUCCESS && acl_platform.offline_mode == ACL_CONTEXT_MPSIM &&
386383
!is_simulator) {
387384
acl_context_callback(context,
388385
"Simulation mode set but aocx is for hardware!");

‎src/acl_globals.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ static void l_reset_present_board() {
7373
// If it's prefixed by "+", then it's in addition to any auto-discovered
7474
// devices.
7575
// If not, then we don't even probe for auto-discovered devices.
76-
const char *acl_get_offline_device_user_setting(int *use_offline_only_ret) {
77-
int use_offline_only = 0;
76+
acl_context_offline_mode_t
77+
acl_get_offline_device_user_setting(std::string *offline_device) {
78+
acl_context_offline_mode_t use_offline_only =
79+
ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY;
7880
const char *setting = 0;
7981
const char *setting_deprecated = 0;
8082
const char *result = 0;
@@ -136,8 +138,15 @@ const char *acl_get_offline_device_user_setting(int *use_offline_only_ret) {
136138
}
137139
}
138140

139-
*use_offline_only_ret = use_offline_only;
140-
return result;
141+
if (offline_device) {
142+
if (use_offline_only == ACL_CONTEXT_MPSIM) {
143+
*offline_device = ACL_MPSIM_DEVICE_NAME;
144+
} else if (result) {
145+
*offline_device = result;
146+
}
147+
}
148+
149+
return use_offline_only;
141150
}
142151

143152
int acl_init(const acl_system_def_t *newsys) {
@@ -166,11 +175,11 @@ int acl_init(const acl_system_def_t *newsys) {
166175
// This function returns CL_TRUE if a hal is initialized and CL_FALSE
167176
// if it is not.
168177
cl_bool acl_init_from_hal_discovery(void) {
169-
int use_offline_only = 0;
170178
const acl_hal_t *board_hal;
171179
acl_assert_locked();
172180

173-
(void)acl_get_offline_device_user_setting(&use_offline_only);
181+
acl_context_offline_mode_t use_offline_only =
182+
acl_get_offline_device_user_setting(NULL);
174183

175184
// Two jobs:
176185
// 1. Set the HAL from the linked-in HAL library.
@@ -223,7 +232,8 @@ void acl_reset(void) {
223232

224233
l_reset_present_board();
225234

226-
acl_platform.offline_device = "";
235+
acl_platform.offline_mode = ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY;
236+
acl_platform.has_offline_device = 0;
227237
acl_platform.num_devices = 0;
228238
for (unsigned i = 0; i < ACL_MAX_DEVICE; ++i) {
229239
acl_platform.device[i] = _cl_device_id();

‎src/acl_hal_mmd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,6 @@ acl_mmd_get_system_definition(acl_system_def_t *sys,
11991199
buf[MAX_BOARD_NAMES_LEN]; // This is a bit subtle, pointers to device
12001200
// names might get cached by various routines
12011201
char *ptr, *saveptr;
1202-
int use_offline_only;
12031202

12041203
#ifdef _WIN32
12051204
// We're really relying on this being called before anything else
@@ -1248,7 +1247,8 @@ acl_mmd_get_system_definition(acl_system_def_t *sys,
12481247
#endif
12491248

12501249
// Dynamically load board mmd & symbols
1251-
acl_get_offline_device_user_setting(&use_offline_only);
1250+
acl_context_offline_mode_t use_offline_only =
1251+
acl_get_offline_device_user_setting(NULL);
12521252
if (use_offline_only == ACL_CONTEXT_MPSIM) {
12531253

12541254
// Substitute the simulator MMD layer.

‎src/acl_kernel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,9 +2918,7 @@ static cl_int l_copy_and_adjust_arguments_for_device(
29182918
[needed_mem_id]);
29192919
#endif
29202920

2921-
int env_override = 0;
2922-
(void)acl_get_offline_device_user_setting(&env_override);
2923-
if (env_override == ACL_CONTEXT_MPSIM) {
2921+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
29242922
if (!acl_realloc_buffer_for_simulator(mem_obj, needed_physical_id,
29252923
needed_mem_id)) {
29262924
return CL_MEM_OBJECT_ALLOCATION_FAILURE;

‎src/acl_kernel_if.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,
706706
char description_size_lsb[KERNEL_ROM_SIZE_BYTES_READ + 1];
707707
unsigned int size_location, version, size;
708708
int result = 0;
709-
int use_offline_only = 0;
710709
acl_assert_locked();
711710

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

724723
// The simulator doesn't have any kernel interface information until the aocx
725724
// is loaded, which happens later.
726-
acl_get_offline_device_user_setting(&use_offline_only);
727-
if (use_offline_only == ACL_CONTEXT_MPSIM) {
725+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
728726
std::string err_msg;
729727
auto parse_result = acl_load_device_def_from_str(
730728
acl_shipped_board_cfgs[0].cfg, sysdef->device[0].autodiscovery_def,

‎src/acl_platform.cpp

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ struct _cl_platform_id acl_platform = {
5454
,
5555
0 // default value for device_exception_platform_counter
5656
,
57-
"" // No offline device specified by an environment variable, as far as we
58-
// know right now.
57+
0 // No offline device specified by an environment variable so far
5958
};
6059

6160
// Used to detect if user is creating contexts/getting platform ids in multiple
@@ -74,9 +73,9 @@ static std::vector<std::optional<acl_system_def_t>> shipped_board_defs;
7473

7574
//////////////////////////////
7675
// Local functions.
77-
static void l_initialize_offline_devices(int offline_mode);
76+
static void l_initialize_offline_devices(std::string offline_device);
7877
static void l_initialize_devices(const acl_system_def_t *present_board_def,
79-
int offline_mode, unsigned int num_devices,
78+
unsigned int num_devices,
8079
const cl_device_id *devices);
8180
static void l_add_device(int idx);
8281

@@ -128,7 +127,7 @@ clGetPlatformIDsIntelFPGA(cl_uint num_entries, cl_platform_id *platforms,
128127
// - Probed devices we find actually attached to the host (probed on
129128
// PCIe), if any,
130129
// - Followed by followed by the list of devices we ship.
131-
// Only probed devices will be marked with .present == 1.
130+
// Only probed devices will be marked with .present == true.
132131
//
133132
// In the end this calls back into acl_init_platform which also sets
134133
// acl_platform.initialized = 1.
@@ -288,7 +287,6 @@ const char *acl_platform_extensions() {
288287
// Initialize the internal bookkeeping based on the system definition
289288
// provided to us.
290289
void acl_init_platform(void) {
291-
int offline_mode = 0;
292290
acl_assert_locked();
293291

294292
acl_platform.dispatch = &acl_icd_dispatch;
@@ -303,15 +301,9 @@ void acl_init_platform(void) {
303301
acl_platform.cl_obj_head = 0;
304302

305303
// Set offline_device property
306-
const char *offline_device =
307-
acl_get_offline_device_user_setting(&offline_mode);
308-
if (offline_device) {
309-
if (offline_mode == ACL_CONTEXT_MPSIM) {
310-
acl_platform.offline_device = ACL_MPSIM_DEVICE_NAME;
311-
} else {
312-
acl_platform.offline_device = offline_device;
313-
}
314-
}
304+
std::string offline_device = "";
305+
acl_platform.offline_mode =
306+
acl_get_offline_device_user_setting(&offline_device);
315307

316308
acl_platform.name = "Intel(R) FPGA SDK for OpenCL(TM)";
317309
acl_platform.vendor = "Intel(R) Corporation";
@@ -383,12 +375,13 @@ void acl_init_platform(void) {
383375
// having.
384376
acl_platform.initial_board_def = acl_present_board_def();
385377

386-
switch (offline_mode) {
378+
switch (acl_platform.offline_mode) {
387379
case ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY:
388380
acl_platform.num_devices =
389381
acl_platform.initial_board_def->num_devices +
390-
(offline_device ? 1 : 0); // the devices in the board def + 1 for the
391-
// offline device, if it exists
382+
(offline_device.empty() ? 0
383+
: 1); // the devices in the board def + 1 for
384+
// the offline device, if it exists
392385
break;
393386
case ACL_CONTEXT_MPSIM:
394387
#ifdef __linux__
@@ -409,7 +402,7 @@ void acl_init_platform(void) {
409402
l_add_device(static_cast<int>(i));
410403
}
411404

412-
l_initialize_offline_devices(offline_mode);
405+
l_initialize_offline_devices(offline_device);
413406

414407
// Device operation queue.
415408
acl_init_device_op_queue(&acl_platform.device_op_queue);
@@ -516,15 +509,11 @@ void acl_init_platform(void) {
516509

517510
void acl_finalize_init_platform(unsigned int num_devices,
518511
const cl_device_id *devices) {
519-
int offline_mode = 0;
520512
int have_single_bank_with_shared_memory;
521513
acl_assert_locked();
522514
assert(num_devices > 0);
523515

524-
(void)acl_get_offline_device_user_setting(&offline_mode);
525-
526-
l_initialize_devices(acl_present_board_def(), offline_mode, num_devices,
527-
devices);
516+
l_initialize_devices(acl_present_board_def(), num_devices, devices);
528517

529518
if (is_SOC_device()) {
530519
size_t cur_num_banks =
@@ -569,7 +558,7 @@ static void l_show_devs(const char *prefix) {
569558
}
570559
}
571560

572-
static void l_initialize_offline_devices(int offline_mode) {
561+
static void l_initialize_offline_devices(std::string offline_device) {
573562
acl_platform.global_mem.range.begin = 0;
574563
acl_platform.global_mem.range.next = 0;
575564

@@ -596,7 +585,7 @@ static void l_initialize_offline_devices(int offline_mode) {
596585
board_def->num_devices = 1;
597586
}
598587

599-
if (offline_mode == ACL_CONTEXT_MPSIM) {
588+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
600589
auto &board_def = shipped_board_defs.emplace_back();
601590
board_def.emplace();
602591
std::string err_msg;
@@ -611,66 +600,74 @@ static void l_initialize_offline_devices(int offline_mode) {
611600
}
612601
}
613602

614-
if (!acl_platform.offline_device.empty()) {
603+
if (!offline_device.empty()) {
615604
unsigned int board_count = 1;
616605
int device_index = 0;
617-
if (offline_mode == ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY) {
606+
if (acl_platform.offline_mode == ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY) {
618607
// In this case, we place the offline device at the end of the device list
619608
// (after the autodiscovered devices).
620609
device_index = (int)(acl_platform.num_devices - board_count);
621610
}
622611

612+
const bool is_present = (acl_platform.offline_mode == ACL_CONTEXT_MPSIM);
623613
// If the user specified an offline device, then load it.
624614
// Search the shipped board defs for the device:
625615
for (const auto &board_def : shipped_board_defs) {
626616
if (!board_def.has_value())
627617
continue;
628-
if (acl_platform.offline_device !=
629-
board_def->device[0].autodiscovery_def.name)
618+
619+
// Currently we either have a single simulator device or a single
620+
// offline device, so bail early if device name doesn't match
621+
if (offline_device != board_def->device[0].autodiscovery_def.name)
630622
continue;
631623

632-
const bool is_present = (offline_mode == ACL_CONTEXT_MPSIM);
633624
for (unsigned j = 0; j < board_count; j++) {
634625
// Bail if not present and we haven't been told to use absent devices
635-
if (!is_present && acl_platform.offline_device !=
636-
board_def->device[0].autodiscovery_def.name)
626+
// In future, need to index offline_device with j when multiple
627+
// simulator devices are supported
628+
if (!is_present &&
629+
offline_device != board_def->device[0].autodiscovery_def.name)
637630
continue;
638631
// Add HW specific device definition
639632
acl_platform.device[device_index].def =
640633
board_def->device[0]; // Struct Copy
641634
acl_platform.device[device_index].present = is_present;
635+
acl_platform.device[device_index].offline = !is_present;
636+
if (!is_present)
637+
acl_platform.has_offline_device = 1;
642638
device_index++;
643639
}
644640
}
641+
if (!is_present && acl_platform.has_offline_device == 0) {
642+
// Did not find specified offline device in the shipped board defs
643+
acl_platform.has_offline_device = -1;
644+
}
645645
}
646646
l_show_devs("offline");
647647
}
648648

649649
// Initialize acl_platform with device information.
650650
// Also determine global mem address range.
651651
static void l_initialize_devices(const acl_system_def_t *present_board_def,
652-
int offline_mode, unsigned int num_devices,
652+
unsigned int num_devices,
653653
const cl_device_id *devices) {
654654
unsigned int i, j;
655655
acl_assert_locked();
656656

657-
acl_print_debug_msg("\n\nReset device list: %d\n", offline_mode);
657+
acl_print_debug_msg("\n\nReset device list: %d\n",
658+
acl_platform.offline_mode);
658659

659660
if (present_board_def) {
660661
acl_print_debug_msg("\n\nPresent board def: %d\n",
661662
present_board_def->num_devices);
662663
}
663664

664-
// shipped_board_def populated earlier in l_initialize_offline_devices
665-
666-
if (offline_mode == ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY ||
667-
offline_mode == ACL_CONTEXT_MSIM || offline_mode == ACL_CONTEXT_MPSIM) {
665+
if (acl_platform.offline_mode != ACL_CONTEXT_OFFLINE_ONLY) {
668666
unsigned int num_platform_devices = acl_platform.num_devices;
669-
if (!acl_platform.offline_device.empty() &&
670-
offline_mode != ACL_CONTEXT_MSIM && offline_mode != ACL_CONTEXT_MPSIM) {
671-
num_platform_devices -=
672-
1; // In this case there's an extra offline devices at the end of the
673-
// list. Do not check it.
667+
if (acl_platform.has_offline_device == 1) {
668+
// There's an extra offline devices at the end of the list, Do not check
669+
// it.
670+
num_platform_devices -= 1;
674671
}
675672

676673
// Then add the present devices, if any.
@@ -691,7 +688,7 @@ static void l_initialize_devices(const acl_system_def_t *present_board_def,
691688
if (acl_platform.device[i].opened_count == 1) {
692689
acl_platform.device[i].def =
693690
present_board_def->device[i]; // Struct copy.
694-
acl_platform.device[i].present = 1;
691+
acl_platform.device[i].present = true;
695692
}
696693
break;
697694
}
@@ -728,6 +725,7 @@ static void l_add_device(int idx) {
728725

729726
device->min_local_mem_size = 16 * 1024; // Min value for OpenCL full profile.
730727
device->address_bits = 64; // Yes, our devices are 64-bit.
728+
device->offline = false; // Not an offline device by default
731729
}
732730

733731
// These functions check to see if a given object is known to the system.

‎src/acl_program.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,9 +1638,7 @@ void acl_program_device(void *user_data, acl_device_op_t *op) {
16381638
dev_prog->device->def.autodiscovery_def =
16391639
dev_bin->get_devdef().autodiscovery_def;
16401640

1641-
int offline_mode = 0;
1642-
(void)acl_get_offline_device_user_setting(&offline_mode);
1643-
if (offline_mode == ACL_CONTEXT_MPSIM) {
1641+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
16441642
// Override the device name to the simulator.
16451643
// In function acl_device_binary_t::load_binary_pkg, the name member will
16461644
// be checked against the .acl.board section of the aocx file, which would

‎src/acl_usm.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
148148
{
149149
auto mmd_properties_it = mmd_properties.begin();
150150
if (mem_id) {
151-
int use_offline_only;
152-
acl_get_offline_device_user_setting(&use_offline_only);
153-
if (use_offline_only == ACL_CONTEXT_MPSIM) {
151+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
154152
*mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
155153
*mmd_properties_it++ = *mem_id;
156154
}
@@ -433,9 +431,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
433431
{
434432
auto mmd_properties_it = mmd_properties.begin();
435433
if (mem_id) {
436-
int use_offline_only;
437-
acl_get_offline_device_user_setting(&use_offline_only);
438-
if (use_offline_only == ACL_CONTEXT_MPSIM) {
434+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
439435
*mmd_properties_it++ = AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION;
440436
*mmd_properties_it++ = *mem_id;
441437
}

‎test/acl_command_queue_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ MT_TEST_GROUP(acl_command_queue) {
5252
CHECK_EQUAL(CL_SUCCESS,
5353
clGetDeviceIDs(m_platform, CL_DEVICE_TYPE_ALL, MAX_DEVICES,
5454
&m_device[0], &m_num_devices));
55-
int offline_only = 0;
56-
CHECK_EQUAL(0, acl_get_offline_device_user_setting(&offline_only));
57-
CHECK_EQUAL(0, offline_only);
55+
CHECK_EQUAL(ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY,
56+
acl_get_offline_device_user_setting(NULL));
5857
CHECK(m_num_devices > 0);
5958
}
6059

0 commit comments

Comments
 (0)
Please sign in to comment.