-
Notifications
You must be signed in to change notification settings - Fork 70
Cache context offline device setting specified by environment variables (2nd stage) #234
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -216,6 +216,20 @@ typedef enum { | |||||||||||||||||||||||||
ACL_COMPILER_MODE_NUM_MODES = CL_CONTEXT_COMPILER_MODE_NUM_MODES_INTELFPGA | ||||||||||||||||||||||||||
} acl_compiler_mode_t; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Looks at environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA. | ||||||||||||||||||||||||||
// If it exists and is prefixed by "+" then: | ||||||||||||||||||||||||||
// Return a pointer to the device name (without the "+" prefix). | ||||||||||||||||||||||||||
// Set *use_offline_ret_only = 1 | ||||||||||||||||||||||||||
// If it exists and is not prefixed by "+" then | ||||||||||||||||||||||||||
// Return a pointer to the device name. | ||||||||||||||||||||||||||
// Set *use_offline_ret_only = 0 | ||||||||||||||||||||||||||
typedef enum { | ||||||||||||||||||||||||||
ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY, | ||||||||||||||||||||||||||
ACL_CONTEXT_OFFLINE_ONLY, | ||||||||||||||||||||||||||
ACL_CONTEXT_MSIM, | ||||||||||||||||||||||||||
ACL_CONTEXT_MPSIM | ||||||||||||||||||||||||||
} acl_context_offline_mode_t; | ||||||||||||||||||||||||||
Comment on lines
+226
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can introduce a scoped enum to group the constants:
Suggested change
Lowercase is easier to discern for the human reader. (Other projects use SnakeCase for similar reasons.) |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/* When a feature is still in development, it might need enum values | ||||||||||||||||||||||||||
* that are distinct from all published enums in the OpenCL token registry. | ||||||||||||||||||||||||||
* There is a reserved range for values for such "experimental" features. | ||||||||||||||||||||||||||
|
@@ -1226,7 +1240,8 @@ typedef struct _cl_device_id { | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
unsigned int address_bits; // cache address bits to avoid GetDeviceInfo calls | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
int present; // Is the device present in the host system? | ||||||||||||||||||||||||||
bool present; // Is the device present in the host system? | ||||||||||||||||||||||||||
bool offline; // Is the device a real (i.e., not simulator) offline device? | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Error notification callback. | ||||||||||||||||||||||||||
CL_EXCEPTION_TYPE_INTEL device_exception_status; | ||||||||||||||||||||||||||
|
@@ -1573,13 +1588,16 @@ typedef struct _cl_platform_id | |||||||||||||||||||||||||
int device_exception_platform_counter; // indicates number of devices with at | ||||||||||||||||||||||||||
// least one exception | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// The setting of environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA, if | ||||||||||||||||||||||||||
// any. | ||||||||||||||||||||||||||
std::string offline_device; | ||||||||||||||||||||||||||
// Record whether the platform has (non-simulator) offline device, | ||||||||||||||||||||||||||
// value will be: | ||||||||||||||||||||||||||
// 1: if there is a valid offline device specified by environment variable | ||||||||||||||||||||||||||
// 0: if there is no offline device specified by environment variable | ||||||||||||||||||||||||||
// -1: if the offline device specified by environment variable is invalid | ||||||||||||||||||||||||||
int has_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; | ||||||||||||||||||||||||||
acl_context_offline_mode_t offline_mode; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Should we track and automatically release leaked objects? | ||||||||||||||||||||||||||
// This helps immensely with the OpenCL conformance tests which tend to | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,8 +73,10 @@ static void l_reset_present_board() { | |
// If it's prefixed by "+", then it's in addition to any auto-discovered | ||
// devices. | ||
// If not, then we don't even probe for auto-discovered devices. | ||
const char *acl_get_offline_device_user_setting(int *use_offline_only_ret) { | ||
int use_offline_only = 0; | ||
acl_context_offline_mode_t | ||
acl_get_offline_device_user_setting(std::string *offline_device) { | ||
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about combining these into a struct to avoid the null pointer? struct acl_context_offline_device {
std::string name;
acl_context_offline_mode mode;
} |
||
acl_context_offline_mode_t use_offline_only = | ||
ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY; | ||
const char *setting = 0; | ||
const char *setting_deprecated = 0; | ||
const char *result = 0; | ||
|
@@ -136,8 +138,15 @@ const char *acl_get_offline_device_user_setting(int *use_offline_only_ret) { | |
} | ||
} | ||
|
||
*use_offline_only_ret = use_offline_only; | ||
return result; | ||
if (offline_device) { | ||
if (use_offline_only == ACL_CONTEXT_MPSIM) { | ||
*offline_device = ACL_MPSIM_DEVICE_NAME; | ||
} else if (result) { | ||
*offline_device = result; | ||
} | ||
} | ||
Comment on lines
+141
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this function is indeed the right place for this code. However, could you replace the earlier What is the content of |
||
|
||
return use_offline_only; | ||
} | ||
|
||
int acl_init(const acl_system_def_t *newsys) { | ||
|
@@ -166,11 +175,11 @@ int acl_init(const acl_system_def_t *newsys) { | |
// This function returns CL_TRUE if a hal is initialized and CL_FALSE | ||
// if it is not. | ||
cl_bool acl_init_from_hal_discovery(void) { | ||
int use_offline_only = 0; | ||
const acl_hal_t *board_hal; | ||
acl_assert_locked(); | ||
|
||
(void)acl_get_offline_device_user_setting(&use_offline_only); | ||
acl_context_offline_mode_t use_offline_only = | ||
acl_get_offline_device_user_setting(NULL); | ||
|
||
// Two jobs: | ||
// 1. Set the HAL from the linked-in HAL library. | ||
|
@@ -223,8 +232,8 @@ void acl_reset(void) { | |
|
||
l_reset_present_board(); | ||
|
||
acl_platform.offline_device = ""; | ||
acl_platform.offline_mode = ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY; | ||
acl_platform.has_offline_device = 0; | ||
acl_platform.num_devices = 0; | ||
for (unsigned i = 0; i < ACL_MAX_DEVICE; ++i) { | ||
acl_platform.device[i] = _cl_device_id(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not document the possible modes, but the offline device name passed to
acl_get_offline_device_user_setting()
. Could you move this comment to the function body and replace the existing, duplicate comment? (There are two possible places for the comment; I prefer the function definition since that avoids having to jump between the comment and the implementation.)