CS5820 – Solved

$ 20.99
Category:

Description

Assignment 3: GPU Tuning

(1) Write a program to print device details like serial number, UUID, Board number and PCI address etc.
Solution:
/*
*
* SPDX-License-Identifier: MIT
*
*/
#include <level_zero/zes_api.h>
#include <algorithm>
#include <fstream>
#include <getopt.h>
#include <iostream>
#include <map>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h> #include <vector> bool verbose = true;
std::string getErrorString(ze_result_t error)
{
static const std::map<ze_result_t, std::string> mgetErrorString{
{ZE_RESULT_NOT_READY, “ZE_RESULT_NOT_READY”},
{ZE_RESULT_ERROR_DEVICE_LOST, “ZE_RESULT_ERROR_DEVICE_LOST”},
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, ”
ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY”},
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, ”
ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY”},
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE, ”
ZE_RESULT_ERROR_MODULE_BUILD_FAILURE”},
{ZE_RESULT_ERROR_MODULE_LINK_FAILURE, ” ZE_RESULT_ERROR_MODULE_LINK_FAILURE”},
{ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, ” ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS”},
{ZE_RESULT_ERROR_NOT_AVAILABLE, “ZE_RESULT_ERROR_NOT_AVAILABLE”},
{ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, ” ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE”},
{ZE_RESULT_ERROR_UNINITIALIZED, “ZE_RESULT_ERROR_UNINITIALIZED”},
{ZE_RESULT_ERROR_UNSUPPORTED_VERSION, ”
ZE_RESULT_ERROR_UNSUPPORTED_VERSION”},
{ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, ”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
ZE_RESULT_ERROR_UNSUPPORTED_FEATURE”},
{ZE_RESULT_ERROR_INVALID_ARGUMENT, ”
ZE_RESULT_ERROR_INVALID_ARGUMENT”},
{ZE_RESULT_ERROR_INVALID_NULL_HANDLE, ”
ZE_RESULT_ERROR_INVALID_NULL_HANDLE”},
{ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, ”
ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE”},
{ZE_RESULT_ERROR_INVALID_NULL_POINTER, ” ZE_RESULT_ERROR_INVALID_NULL_POINTER”},
{ZE_RESULT_ERROR_INVALID_SIZE, “ZE_RESULT_ERROR_INVALID_SIZE”},
{ZE_RESULT_ERROR_UNSUPPORTED_SIZE, ” ZE_RESULT_ERROR_UNSUPPORTED_SIZE”},
{ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, ” ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT”},
{ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT, ” ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT”},
{ZE_RESULT_ERROR_INVALID_ENUMERATION, ” ZE_RESULT_ERROR_INVALID_ENUMERATION”},
{ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION, ”
ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION”},
{ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT, ”
ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT”},
{ZE_RESULT_ERROR_INVALID_NATIVE_BINARY, ”
ZE_RESULT_ERROR_INVALID_NATIVE_BINARY”},
{ZE_RESULT_ERROR_INVALID_GLOBAL_NAME, ”
ZE_RESULT_ERROR_INVALID_GLOBAL_NAME”},
{ZE_RESULT_ERROR_INVALID_KERNEL_NAME, ”
ZE_RESULT_ERROR_INVALID_KERNEL_NAME”},
{ZE_RESULT_ERROR_INVALID_FUNCTION_NAME, ” ZE_RESULT_ERROR_INVALID_FUNCTION_NAME”},
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION, ”
ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION”},
{ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION, ”
ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX, ”
ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE, ”
ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE, ” ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE”},
{ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED, ”
ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED”},
{ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE, ” ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE”},
{ZE_RESULT_ERROR_OVERLAPPING_REGIONS, ” ZE_RESULT_ERROR_OVERLAPPING_REGIONS”},
{ZE_RESULT_ERROR_UNKNOWN, “ZE_RESULT_ERROR_UNKNOWN”}}; auto i = mgetErrorString.find(error); if (i == mgetErrorString.end()) return “ZE_RESULT_ERROR_UNKNOWN”;
else return mgetErrorString.at(error);
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
}
#define VALIDATECALL(myZeCall) do
{ ze_result_t r = myZeCall; if (r != ZE_RESULT_SUCCESS)
{ std::cout << getErrorString(r)
<< ” returned by ”
<< #myZeCall << “: ”
<< __FUNCTION__ << “: ”
<< __LINE__ << ” “;
}
} while (0);
void getDeviceHandles(ze_driver_handle_t &driverHandle, std::vector< ze_device_handle_t> &devices, int argc, char *argv[])
{
VALIDATECALL(zeInit(ZE_INIT_FLAG_GPU_ONLY));
uint32_t driverCount = 0;
VALIDATECALL(zeDriverGet(&driverCount, nullptr)); if (driverCount == 0)
{
std::cout << “Error could not retrieve driver” << std::endl; std::terminate();
}
VALIDATECALL(zeDriverGet(&driverCount, &driverHandle));
uint32_t deviceCount = 0;
VALIDATECALL(zeDeviceGet(driverHandle, &deviceCount, nullptr)); if (deviceCount == 0)
{
std::cout << “Error could not retrieve device” << std::endl; std::terminate();
} devices.resize(deviceCount);
VALIDATECALL(zeDeviceGet(driverHandle, &deviceCount, devices.data()));
ze_device_properties_t deviceProperties = {
ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; for (const auto &device : devices)
{
VALIDATECALL(zeDeviceGetProperties(device, &deviceProperties));
if (verbose)
{
std::cout << “Device Name = ” << deviceProperties.name << std
::endl; std::cout << “deviceProperties.flags = ” << deviceProperties.
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

flags << “on device” << device << std::endl;
}
}
}
bool validateGetenv(const char *name)
{
const char *env = getenv(name); if ((nullptr == env) || (0 == strcmp(“0”, env))) return false;
return (0 == strcmp(“1”, env));
}
int main(int argc, char *argv[])
{ std::vector<ze_device_handle_t> devices; std::vector<ze_device_handle_t> devices; std::vector<ze_device_handle_t> devices; ze_driver_handle_t driver;
if (!validateGetenv(“ZES_ENABLE_SYSMAN”))
{
std::cout << “Must set environment variable ZES_ENABLE_SYSMAN=1″
<< std::endl; exit(0);
}
getDeviceHandles(driver, devices, argc, argv);
/*Using the structures zes_device_properties_t and zes_pci_properties_t to get device properties and pci addresses respectively */
zes_device_properties_t devProps; if (zesDeviceGetProperties(devices[0], &devProps) == ZE_RESULT_SUCCESS)
{
printf(” UUID: %s “, devProps.core.uuid.id) printf(” #subdevices: %u “, devProps.numSubdevices) printf(” brand: %s “, devProps.brandName) printf(” model: %s “, devProps.modelName)
} zes_pci_properties_t pciProps; if (zesDevicePciGetProperties(devices[0], &pciProps) ==
ZE_RESULT_SUCCESS)
printf(” PCI address: %04u:%02u:%02u.%u”, pciProps.address.domain,
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 pciProps.address.bus,
156 pciProps.address.device,
157 pciProps.address.function);
158 }
(2) Write a program to Write a daemon/application who keep monitoring temperature and if any temperature changes just print to report change in temperature Solution:
*
*
* SPDX-License-Identifier: MIT
*
*/
#include <level_zero/zes_api.h>
#include <algorithm>
#include <fstream>
#include <getopt.h>
#include <iostream>
#include <map>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h> #include <vector> bool verbose = true;
std::string getErrorString(ze_result_t error)
{
static const std::map<ze_result_t, std::string> mgetErrorString{
{ZE_RESULT_NOT_READY, “ZE_RESULT_NOT_READY”},
{ZE_RESULT_ERROR_DEVICE_LOST, “ZE_RESULT_ERROR_DEVICE_LOST”},
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, ”
ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY”},
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, ”
ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY”},
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE, ”
ZE_RESULT_ERROR_MODULE_BUILD_FAILURE”},
{ZE_RESULT_ERROR_MODULE_LINK_FAILURE, ” ZE_RESULT_ERROR_MODULE_LINK_FAILURE”},
{ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, ” ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS”},
{ZE_RESULT_ERROR_NOT_AVAILABLE, “ZE_RESULT_ERROR_NOT_AVAILABLE”},
{ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, ” ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE”},
{ZE_RESULT_ERROR_UNINITIALIZED, “ZE_RESULT_ERROR_UNINITIALIZED”},
{ZE_RESULT_ERROR_UNSUPPORTED_VERSION, ”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
ZE_RESULT_ERROR_UNSUPPORTED_VERSION”},
36 {ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, ”
ZE_RESULT_ERROR_UNSUPPORTED_FEATURE”},
37 {ZE_RESULT_ERROR_INVALID_ARGUMENT, ”
ZE_RESULT_ERROR_INVALID_ARGUMENT”},
38 {ZE_RESULT_ERROR_INVALID_NULL_HANDLE, ”
ZE_RESULT_ERROR_INVALID_NULL_HANDLE”},
39 {ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, ”
ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE”},
{ZE_RESULT_ERROR_INVALID_NULL_POINTER, ” ZE_RESULT_ERROR_INVALID_NULL_POINTER”},
{ZE_RESULT_ERROR_INVALID_SIZE, “ZE_RESULT_ERROR_INVALID_SIZE”},
{ZE_RESULT_ERROR_UNSUPPORTED_SIZE, ” ZE_RESULT_ERROR_UNSUPPORTED_SIZE”},
{ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, ” ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT”},
{ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT, ” ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT”},
{ZE_RESULT_ERROR_INVALID_ENUMERATION, ” ZE_RESULT_ERROR_INVALID_ENUMERATION”},
{ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION, ”
ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION”},
{ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT, ”
ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT”},
{ZE_RESULT_ERROR_INVALID_NATIVE_BINARY, ”
ZE_RESULT_ERROR_INVALID_NATIVE_BINARY”},
{ZE_RESULT_ERROR_INVALID_GLOBAL_NAME, ”
ZE_RESULT_ERROR_INVALID_GLOBAL_NAME”},
{ZE_RESULT_ERROR_INVALID_KERNEL_NAME, ”
ZE_RESULT_ERROR_INVALID_KERNEL_NAME”},
{ZE_RESULT_ERROR_INVALID_FUNCTION_NAME, ” ZE_RESULT_ERROR_INVALID_FUNCTION_NAME”},
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION, ”
ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION”},
{ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION, ”
ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX, ”
ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE, ”
ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE, ” ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE”},
{ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED, ”
ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED”},
{ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE, ” ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE”},
{ZE_RESULT_ERROR_OVERLAPPING_REGIONS, ” ZE_RESULT_ERROR_OVERLAPPING_REGIONS”},
{ZE_RESULT_ERROR_UNKNOWN, “ZE_RESULT_ERROR_UNKNOWN”}}; auto i = mgetErrorString.find(error); if (i == mgetErrorString.end()) return “ZE_RESULT_ERROR_UNKNOWN”;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 else
65 return mgetErrorString.at(error);
66 }
67
68 #define VALIDATECALL(myZeCall)
69 do
70 {

71 ze_result_t r = myZeCall;
if (r != ZE_RESULT_SUCCESS)
{ std::cout << getErrorString(r)
<< ” returned by ”
<< #myZeCall << “: ”
<< __FUNCTION__ << “: ”
<< __LINE__ << ” “;
}
} while (0);
void getDeviceHandles(ze_driver_handle_t &driverHandle, std::vector< ze_device_handle_t> &devices, int argc, char *argv[])
{
VALIDATECALL(zeInit(ZE_INIT_FLAG_GPU_ONLY));
uint32_t driverCount = 0;
VALIDATECALL(zeDriverGet(&driverCount, nullptr)); if (driverCount == 0)
{
std::cout << “Error could not retrieve driver” << std::endl; std::terminate();
}
VALIDATECALL(zeDriverGet(&driverCount, &driverHandle));
uint32_t deviceCount = 0;
VALIDATECALL(zeDeviceGet(driverHandle, &deviceCount, nullptr)); if (deviceCount == 0)
{
std::cout << “Error could not retrieve device” << std::endl; std::terminate();
} devices.resize(deviceCount);
VALIDATECALL(zeDeviceGet(driverHandle, &deviceCount, devices.data()));
ze_device_properties_t deviceProperties = {
ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; for (const auto &device : devices)
{
VALIDATECALL(zeDeviceGetProperties(device, &deviceProperties));
if (verbose)
{
std::cout << “Device Name = ” << deviceProperties.name << std
::endl; std::cout << “deviceProperties.flags = ” << deviceProperties. flags << “on device” << device << std::endl;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 }
116 }
117 }
118 //After getting the device handles
119 //Let us use this Temperature_Monitor function using the mentioned 3 APIs
to complete the task
void Temperature_Monitor(std::vector<ze_device_handle_t> &devices)
{
std::cout << std::endl;
uint32_t numSens = 0;
//We use the zesDeviceEnumTemperatureSensors API to get handle of the temperature sensors
VALIDATECALL(zesDeviceEnumTemperatureSensors(devices, &numSens, NULL))
;
if (numSens == 0)
{
std::cout << “Error: Could not get handle of temp. sensors” << std ::endl;
}
//We use the Temp. properties and state api structures here where we check the properties and monitor the state
zes_temp_properties_t temp; for (const auto &temp_properties)
{
float t_i = 0; float t_p = 0;
VALIDATECALL(zesTemperatureGetProperties(temp, &temp_properties)); if (verbose)
{
std::cout << “maxTemp “<< temp_properties.maxTemperature;
//maxTemperature is the only double value supported, gives output in deg. Celcius
std::cout<<std::endl;
}
VALIDATECALL(zesTemperatureGetState(temp, &t_i)); if (verbose)
{
std::cout << “instantaneous_temp” << t_i << std::endl;
}
float t_d = t_p – t_i; if (verbose)
{
std::cout << 10 << std::endl; //Temp Data freq.
}
t_d = 0; while(1)
{
VALIDATECALL(zesTemperatureGetState(temp, &t_p)); //Ongoing loop for continuous checking and monitoring
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 }
161 }
162 }
163 bool validateGetenv(const char *name)
{ const char *env = getenv(name); if ((nullptr == env) || (0 == strcmp(“0”, env))) return false;
return (0 == strcmp(“1”, env));
} int main(int argc, char *argv[])
{ std::vector<ze_device_handle_t> devices; ze_driver_handle_t driver;
if (!validateGetenv(“ZES_ENABLE_SYSMAN”))
{
std::cout << “Must set environment variable ZES_ENABLE_SYSMAN=1”
} << std::endl; exit(0);
}
getDeviceHandles(driver, devices, argc, argv);
Temperature_Monitor(devices[0]);
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

(3) Write a program to Read the available frequency clocks and current frequency. Try to set maximum frequency range through API and Now read back what is current frequency set
Solution:
/*
*
* SPDX-License-Identifier: MIT
*
*/
#include <level_zero/zes_api.h>
#include <algorithm>
#include <fstream>
#include <getopt.h>
#include <iostream>
#include <map>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h> #include <vector> bool verbose = true;
std::string getErrorString(ze_result_t error)
{
static const std::map<ze_result_t, std::string> mgetErrorString{
{ZE_RESULT_NOT_READY, “ZE_RESULT_NOT_READY”},
{ZE_RESULT_ERROR_DEVICE_LOST, “ZE_RESULT_ERROR_DEVICE_LOST”},
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, ”
ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY”},
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, ”
ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY”},
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE, ”
ZE_RESULT_ERROR_MODULE_BUILD_FAILURE”},
{ZE_RESULT_ERROR_MODULE_LINK_FAILURE, ” ZE_RESULT_ERROR_MODULE_LINK_FAILURE”},
{ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, ” ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS”},
{ZE_RESULT_ERROR_NOT_AVAILABLE, “ZE_RESULT_ERROR_NOT_AVAILABLE”},
{ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, ” ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE”},
{ZE_RESULT_ERROR_UNINITIALIZED, “ZE_RESULT_ERROR_UNINITIALIZED”},
{ZE_RESULT_ERROR_UNSUPPORTED_VERSION, ”
ZE_RESULT_ERROR_UNSUPPORTED_VERSION”},
{ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, ”
ZE_RESULT_ERROR_UNSUPPORTED_FEATURE”},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 {ZE_RESULT_ERROR_INVALID_ARGUMENT, ”
ZE_RESULT_ERROR_INVALID_ARGUMENT”},
38 {ZE_RESULT_ERROR_INVALID_NULL_HANDLE, ” ZE_RESULT_ERROR_INVALID_NULL_HANDLE”},
39 {ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, ”
ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE”},
{ZE_RESULT_ERROR_INVALID_NULL_POINTER, ” ZE_RESULT_ERROR_INVALID_NULL_POINTER”},
{ZE_RESULT_ERROR_INVALID_SIZE, “ZE_RESULT_ERROR_INVALID_SIZE”},
{ZE_RESULT_ERROR_UNSUPPORTED_SIZE, ” ZE_RESULT_ERROR_UNSUPPORTED_SIZE”},
{ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, ” ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT”},
{ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT, ” ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT”},
{ZE_RESULT_ERROR_INVALID_ENUMERATION, ” ZE_RESULT_ERROR_INVALID_ENUMERATION”},
{ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION, ”
ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION”},
{ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT, ”
ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT”},
{ZE_RESULT_ERROR_INVALID_NATIVE_BINARY, ”
ZE_RESULT_ERROR_INVALID_NATIVE_BINARY”},
{ZE_RESULT_ERROR_INVALID_GLOBAL_NAME, ”
ZE_RESULT_ERROR_INVALID_GLOBAL_NAME”},
{ZE_RESULT_ERROR_INVALID_KERNEL_NAME, ”
ZE_RESULT_ERROR_INVALID_KERNEL_NAME”},
{ZE_RESULT_ERROR_INVALID_FUNCTION_NAME, ” ZE_RESULT_ERROR_INVALID_FUNCTION_NAME”},
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION, ”
ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION”},
{ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION, ”
ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX, ”
ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE, ”
ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE”},
{ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE, ” ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE”},
{ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED, ”
ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED”},
{ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE, ” ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE”},
{ZE_RESULT_ERROR_OVERLAPPING_REGIONS, ” ZE_RESULT_ERROR_OVERLAPPING_REGIONS”},
{ZE_RESULT_ERROR_UNKNOWN, “ZE_RESULT_ERROR_UNKNOWN”}}; auto i = mgetErrorString.find(error); if (i == mgetErrorString.end()) return “ZE_RESULT_ERROR_UNKNOWN”;
else return mgetErrorString.at(error);
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 }
67
68 #define VALIDATECALL(myZeCall) 69 do
70 {
71 ze_result_t r = myZeCall;
if (r != ZE_RESULT_SUCCESS)
{ std::cout << getErrorString(r)
<< ” returned by ”
<< #myZeCall << “: ”
<< __FUNCTION__ << “: ”
<< __LINE__ << ” “;
}
} while (0);
void getDeviceHandles(ze_driver_handle_t &driverHandle, std::vector< ze_device_handle_t> &devices, int argc, char *argv[])
{
VALIDATECALL(zeInit(ZE_INIT_FLAG_GPU_ONLY));
uint32_t driverCount = 0;
VALIDATECALL(zeDriverGet(&driverCount, nullptr)); if (driverCount == 0)
{
std::cout << “Error could not retrieve driver” << std::endl; std::terminate();
}
VALIDATECALL(zeDriverGet(&driverCount, &driverHandle));
uint32_t deviceCount = 0;
VALIDATECALL(zeDeviceGet(driverHandle, &deviceCount, nullptr)); if (deviceCount == 0)
{
std::cout << “Error could not retrieve device” << std::endl; std::terminate();
} devices.resize(deviceCount);
VALIDATECALL(zeDeviceGet(driverHandle, &deviceCount, devices.data()));
ze_device_properties_t deviceProperties = {
ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; for (const auto &device : devices)
{
VALIDATECALL(zeDeviceGetProperties(device, &deviceProperties));
if (verbose)
{
std::cout << “Device Name = ” << deviceProperties.name << std
::endl; std::cout << “deviceProperties.flags = ” << deviceProperties.
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
flags << “on device” << device << std::endl;
115 }
116 }

117 }
118
119 void testSysmanFrequency(ze_device_handle_t &device) {
std::cout << std::endl
<< ” —- Frequency tests —- ” << std::endl;
bool iamroot = (geteuid() == 0);
uint32_t count = 0;
VALIDATECALL(zesDeviceEnumFrequencyDomains(device, &count, nullptr)); if (count == 0) { std::cout << “Could not retrieve frequency domains” << std::endl; return;
}
std::vector<zes_freq_handle_t> handles(count, nullptr);
VALIDATECALL(zesDeviceEnumFrequencyDomains(device, &count, handles. data()));
for (const auto &handle : handles) { zes_freq_properties_t freqProperties = {}; zes_freq_range_t freqRange = {}; zes_freq_range_t testFreqRange = {}; zes_freq_state_t freqState = {};
VALIDATECALL(zesFrequencyGetProperties(handle, &freqProperties)); if (verbose) { std::cout << “freqProperties.type = ” << freqProperties.type
<< std::endl; std::cout << “freqProperties.canControl = ” << freqProperties.
canControl << std::endl; std::cout << “freqProperties.isThrottleEventSupported = ” <<
freqProperties.isThrottleEventSupported << std::endl; std::cout << “freqProperties.min = ” << freqProperties.min <<
std::endl; std::cout << “freqProperties.max = ” << freqProperties.max <<
std::endl; if (freqProperties.onSubdevice) { std::cout << “freqProperties.subdeviceId = ” <<
freqProperties.subdeviceId << std::endl;
}
}
VALIDATECALL(zesFrequencyGetState(handle, &freqState)); if (verbose) { std::cout << “freqState.currentVoltage = ” << freqState.
currentVoltage << std::endl; std::cout << “freqState.request = ” << freqState.request <<
std::endl; std::cout << “freqState.tdp = ” << freqState.tdp << std::endl; std::cout << “freqState.efficient = ” << freqState.efficient
<< std::endl;
std::cout << “freqState.actual = ” << freqState.actual << std
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
::endl;
158 std::cout << “freqState.throttleReasons = ” << freqState.
throttleReasons << std::endl;
}
VALIDATECALL(zesFrequencyGetRange(handle, &freqRange)); if (verbose) { std::cout << “freqRange.min = ” << freqRange.min << std::endl; std::cout << “freqRange.max = ” << freqRange.max << std::endl;
}
count = 0;
VALIDATECALL(zesFrequencyGetAvailableClocks(handle, &count, nullptr)); std::vector<double> frequency(count);
VALIDATECALL(zesFrequencyGetAvailableClocks(handle, &count, frequency.data())); if (verbose) { for (auto freq : frequency) { std::cout << ” frequency = ” << freq << std::endl;
}
}
if (iamroot) {
// Test setting min and max frequency the same, then restore
originals testFreqRange.min = freqRange.min; testFreqRange.max = freqRange.min; if (verbose) { std::cout << “Setting Frequency Range . min ” <<
testFreqRange.min << std::endl; std::cout << “Setting Frequency Range . max ” <<
testFreqRange.max << std::endl;
}
VALIDATECALL(zesFrequencySetRange(handle, &testFreqRange));
VALIDATECALL(zesFrequencyGetRange(handle, &testFreqRange)); if (verbose) { std::cout << “After Setting Getting Frequency Range . min
” << testFreqRange.min << std::endl; std::cout << “After Setting Getting Frequency Range . max ” << testFreqRange.max << std::endl;
}
testFreqRange.min = freqRange.min; testFreqRange.max = freqRange.max; if (verbose) { std::cout << “Setting Frequency Range . min ” <<
testFreqRange.min << std::endl; std::cout << “Setting Frequency Range . max ” <<
testFreqRange.max << std::endl;
}
VALIDATECALL(zesFrequencySetRange(handle, &testFreqRange));
VALIDATECALL(zesFrequencyGetRange(handle, &testFreqRange)); if (verbose) { std::cout << “After Setting Getting Frequency Range . min
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
” << testFreqRange.min << std::endl;
199 std::cout << “After Setting Getting Frequency Range . max
” << testFreqRange.max << std::endl;
}
} else { std::cout << “Not running as Root. Skipping
zetSysmanFrequencySetRange test.” << std::endl;
}
}
}
bool validateGetenv(const char *name)
{
const char *env = getenv(name); if ((nullptr == env) || (0 == strcmp(“0”, env))) return false;
return (0 == strcmp(“1”, env));
}
int main(int argc, char *argv[])
{ std::vector<ze_device_handle_t> devices; ze_driver_handle_t driver;
if (!validateGetenv(“ZES_ENABLE_SYSMAN”))
{
std::cout << “Must set environment variable ZES_ENABLE_SYSMAN=1”
<< std::endl; exit(0);
}
getDeviceHandles(driver, devices, argc, argv); testSysmanFrequency(devices[0]);
}
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
*****************************************************************
Soham Kulkarni, EE19BTECH11053, IIT Hyderabad

Reviews

There are no reviews yet.

Be the first to review “CS5820 – Solved”

Your email address will not be published. Required fields are marked *