1 /* Test the `acc_get_property' and `acc_get_property_string' library
2 functions on amdgcn devices by comparing property values with
3 those obtained through the HSA API. */
4 /* { dg-additional-sources acc_get_property-aux.c } */
5 /* { dg-additional-options "-ldl" } */
6 /* { dg-do run { target openacc_amdgcn_accel_selected } } */
21 void expect_device_string_properties (acc_device_t dev_type
, int dev_num
,
22 const char* expected_vendor
,
23 const char* expected_name
,
24 const char* expected_driver
);
26 hsa_status_t (*hsa_agent_get_info_fn
) (hsa_agent_t agent
,
27 hsa_agent_info_t attribute
,
29 hsa_status_t (*hsa_system_get_info_fn
) (hsa_system_info_t attribute
,
31 hsa_status_t (*hsa_iterate_agents_fn
)
32 (hsa_status_t (*callback
)(hsa_agent_t agent
, void *data
), void *data
);
33 hsa_status_t (*hsa_init_fn
) (void);
35 char* support_cpu_devices
;
41 char* hsa_runtime_lib
;
44 #define DLSYM_FN(function) \
45 function##_fn = (typeof(function##_fn))dlsym (handle, #function); \
46 if (function##_fn == NULL) \
48 fprintf (stderr, "Could not get symbol " #function ".\n"); \
52 env_runtime
= getenv ("HSA_RUNTIME_LIB");
53 hsa_runtime_lib
= env_runtime
? env_runtime
: (char*)"libhsa-runtime64.so";
55 handle
= dlopen (hsa_runtime_lib
, RTLD_LAZY
);
58 fprintf (stderr
, "Could not load %s.\n", hsa_runtime_lib
);
62 DLSYM_FN (hsa_agent_get_info
)
63 DLSYM_FN (hsa_system_get_info
)
64 DLSYM_FN (hsa_iterate_agents
)
69 support_cpu_devices
= getenv ("GCN_SUPPORT_CPU_DEVICES");
73 check_agent_properties (hsa_agent_t agent
, void *dev_num_arg
)
83 hsa_device_type_t device_type
;
84 int* dev_num
= (int*)dev_num_arg
;
86 #define AGENT_GET_INFO(info_type, val) \
87 status = hsa_agent_get_info_fn (agent, info_type, &val); \
88 if (status != HSA_STATUS_SUCCESS) \
90 fprintf (stderr, "Failed to obtain " #info_type ".\n"); \
93 #define SYSTEM_GET_INFO(info_type, val) \
94 status = hsa_system_get_info_fn (info_type, &val); \
95 if (status != HSA_STATUS_SUCCESS) \
97 fprintf (stderr, "Failed to obtain " #info_type ".\n"); \
101 AGENT_GET_INFO (HSA_AGENT_INFO_DEVICE
, device_type
)
103 /* Skip unsupported device types. Mimic the GCN plugin's behavior. */
104 if (!(device_type
== HSA_DEVICE_TYPE_GPU
105 || (support_cpu_devices
&& device_type
== HSA_DEVICE_TYPE_CPU
)))
106 return HSA_STATUS_SUCCESS
;
108 AGENT_GET_INFO (HSA_AGENT_INFO_NAME
, name
)
109 AGENT_GET_INFO (HSA_AGENT_INFO_VENDOR_NAME
, vendor_name
)
111 SYSTEM_GET_INFO (HSA_SYSTEM_INFO_VERSION_MINOR
, minor
)
112 SYSTEM_GET_INFO (HSA_SYSTEM_INFO_VERSION_MAJOR
, major
)
114 snprintf (driver
, sizeof driver
, "HSA Runtime %hu.%hu",
115 (unsigned short int)major
, (unsigned short int)minor
);
117 expect_device_string_properties(acc_device_radeon
, *dev_num
,
118 vendor_name
, name
, driver
);
131 hsa_status_t status
=
132 hsa_iterate_agents_fn (&check_agent_properties
, &dev_num
);