Repository navigation
Expand file tree
/
Copy pathtest_utils.py
More file actions
94 lines (81 loc) · 2.82 KB
/
Copy pathtest_utils.py
File metadata and controls
94 lines (81 loc) · 2.82 KB
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
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
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
# Data Parallel Control (dpctl)
#
# Copyright 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Defines unit test cases for utility functions."""
import pytest
import dpctl
import dpctl.utils
@pytest.mark.filterwarnings("ignore:.*:RuntimeWarning")
def test_onetrace_enabled():
import os
v_name = "PTI_ENABLE_COLLECTION"
v_v = os.getenv(v_name, None)
with dpctl.utils.onetrace_enabled():
assert os.getenv(v_name, None) == "1"
assert os.getenv(v_name, None) == v_v
def test_intel_device_info():
try:
d = dpctl.select_default_device()
except dpctl.SyclDeviceCreationError:
pytest.skip("Default device could not be created")
descr = dpctl.utils.intel_device_info(d)
assert isinstance(descr, dict)
assert ("device_id" in descr) or not descr
allowed_names = [
"device_id",
"gpu_slices",
"gpu_eu_count",
"gpu_eu_simd_width",
"gpu_hw_threads_per_eu",
"gpu_subslices_per_slice",
"gpu_eu_count_per_subslice",
"max_mem_bandwidth",
"free_memory",
"memory_clock_rate",
"memory_bus_width",
]
for descriptor_name in descr.keys():
test = descriptor_name in allowed_names
err_msg = f"Key '{descriptor_name}' is not recognized"
assert test, err_msg
def test_intel_device_info_validation():
invalid_device = {}
with pytest.raises(TypeError):
dpctl.utils.intel_device_info(invalid_device)
def test_order_manager():
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Queue could not be created for default-selected device")
_som = dpctl.utils.SequentialOrderManager
_mngr = _som[q]
assert isinstance(_mngr.num_host_task_events, int)
assert isinstance(_mngr.num_submitted_events, int)
assert isinstance(_mngr.submitted_events, list)
assert isinstance(_mngr.host_task_events, list)
_mngr.add_event_pair(dpctl.SyclEvent(), dpctl.SyclEvent())
_mngr.add_event_pair([dpctl.SyclEvent()], dpctl.SyclEvent())
_mngr.add_event_pair(dpctl.SyclEvent(), [dpctl.SyclEvent()])
_mngr.wait()
cpy = _mngr.__copy__()
_som.clear()
del cpy
try:
_passed = False
_som[None]
except TypeError:
_passed = True
finally:
assert _passed