Skip to content

Commit 5c57730

Browse files
Merge branch 'master' into aspect_selector
2 parents 8b09966 + 33031a2 commit 5c57730

File tree

8 files changed

+225
-52
lines changed

8 files changed

+225
-52
lines changed

.github/workflows/conda-package.yml

Lines changed: 111 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,54 @@ env:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14+
os: [ubuntu-latest, windows-latest]
15+
include:
16+
- os: ubuntu-latest
17+
pkgs_dirs: ~/.conda/pkgs
18+
condarc: ~/.condarc
19+
conda-bld: /usr/share/miniconda/conda-bld/linux-64/
20+
- os: windows-latest
21+
pkgs_dirs: C:\Users\runneradmin\.conda\pkgs
22+
condarc: C:\Users\runneradmin\.condarc
23+
conda-bld: C:\Miniconda\conda-bld\win-64\
1424
python: [3.8]
1525
steps:
1626
- uses: actions/checkout@v2
1727
with:
1828
fetch-depth: 0
29+
- uses: conda-incubator/setup-miniconda@v2
30+
with:
31+
auto-activate-base: true
32+
activate-environment: ""
1933

2034
- name: Set pkgs_dirs
2135
run: |
22-
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
36+
echo "pkgs_dirs: [${{ matrix.pkgs_dirs }}]" >> ${{ matrix.condarc }}
2337
- name: Cache conda packages
2438
uses: actions/cache@v2
2539
env:
2640
CACHE_NUMBER: 0 # Increase to reset cache
2741
with:
28-
path: ~/.conda/pkgs
42+
path: ${{ matrix.pkgs_dirs }}
2943
key:
3044
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
3145
restore-keys: |
3246
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
3347
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
34-
35-
- name: Add conda to system path
36-
run: echo $CONDA/bin >> $GITHUB_PATH
3748
- name: Install conda-build
3849
run: conda install conda-build
3950
- name: Build conda package
40-
run: |
41-
CHANNELS="-c intel -c defaults --override-channels"
42-
VERSIONS="--python ${{ matrix.python }}"
43-
TEST="--no-test"
44-
45-
conda build \
46-
$TEST \
47-
$VERSIONS \
48-
$CHANNELS \
49-
conda-recipe
51+
run: conda build --no-test --python ${{ matrix.python }} -c intel -c defaults --override-channels conda-recipe
5052
- name: Upload artifact
5153
uses: actions/upload-artifact@v2
5254
with:
5355
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
54-
path: /usr/share/miniconda/conda-bld/linux-64/${{ env.PACKAGE_NAME }}-*.tar.bz2
56+
path: ${{ matrix.conda-bld }}${{ env.PACKAGE_NAME }}-*.tar.bz2
5557

56-
test:
58+
test_linux:
5759
needs: build
5860
runs-on: ${{ matrix.runner }}
5961

@@ -62,10 +64,10 @@ jobs:
6264
python: [3.8]
6365
experimental: [false]
6466
runner: [ubuntu-latest]
65-
include:
66-
- python: 3.8
67-
experimental: true
68-
runner: [self-hosted, gen9]
67+
# include:
68+
# - python: 3.8
69+
# experimental: true
70+
# runner: [self-hosted, gen9]
6971
continue-on-error: ${{ matrix.experimental }}
7072
env:
7173
CHANNELS: -c intel -c defaults --override-channels
@@ -86,7 +88,6 @@ jobs:
8688
conda index $GITHUB_WORKSPACE/channel
8789
# Test channel
8890
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels
89-
9091
- name: Collect dependencies
9192
run: |
9293
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
@@ -105,7 +106,6 @@ jobs:
105106
restore-keys: |
106107
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
107108
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
108-
109109
- name: Install dpctl
110110
run: |
111111
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
@@ -119,8 +119,67 @@ jobs:
119119
# clinfo -l
120120
python -m pytest --pyargs $MODULE_NAME
121121
122-
upload:
123-
needs: test
122+
test_windows:
123+
needs: build
124+
runs-on: ${{ matrix.runner }}
125+
126+
strategy:
127+
matrix:
128+
python: [3.8]
129+
experimental: [false]
130+
runner: [windows-latest]
131+
continue-on-error: ${{ matrix.experimental }}
132+
env:
133+
CHANNELS: -c intel -c defaults --override-channels
134+
135+
steps:
136+
- name: Download artifact
137+
uses: actions/download-artifact@v2
138+
with:
139+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
140+
- uses: conda-incubator/setup-miniconda@v2
141+
with:
142+
auto-activate-base: true
143+
activate-environment: ""
144+
- name: Install conda-build
145+
run: conda install conda-build
146+
- name: Create conda channel
147+
run: |
148+
mkdir -p $GITHUB_WORKSPACE/channel/win-64
149+
mv ${{ env.PACKAGE_NAME }}-*.tar.bz2 ${{ env.GITHUB_WORKSPACE }}/channel/win-64
150+
conda index ${{ env.GITHUB_WORKSPACE }}/channel
151+
# Test channel
152+
conda search ${{ env.PACKAGE_NAME }} -c ${{ env.GITHUB_WORKSPACE }}/channel --override-channels
153+
- name: Collect dependencies
154+
run: conda install ${{ env.PACKAGE_NAME }} python=${{ matrix.python }} -c ${{ env.GITHUB_WORKSPACE }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile
155+
- name: Set pkgs_dirs
156+
run: |
157+
echo "pkgs_dirs: [C:\Users\runneradmin\.conda\pkgs]" >> C:\Users\runneradmin\.condarc
158+
- name: Cache conda packages
159+
uses: actions/cache@v2
160+
env:
161+
CACHE_NUMBER: 0 # Increase to reset cache
162+
with:
163+
path: C:\Users\runneradmin\.conda\pkgs
164+
key:
165+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
166+
restore-keys: |
167+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
168+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
169+
- name: Install opencl_rt
170+
run: conda install opencl_rt -c intel --override-channels
171+
- name: Install dpctl
172+
run: |
173+
conda install ${{ env.PACKAGE_NAME }} pytest python=${{ matrix.python }} -c ${{ env.GITHUB_WORKSPACE }}/channel ${{ env.CHANNELS }}
174+
# Test installed packages
175+
conda list
176+
- name: Add library
177+
run: echo "OCL_ICD_FILENAMES=C:\Miniconda\Library\lib\intelocl64.dll" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
178+
- name: Run tests
179+
run: python -m pytest --pyargs ${{ env.MODULE_NAME }}
180+
181+
upload_linux:
182+
needs: test_linux
124183
if: ${{ github.ref == 'refs/heads/master' }}
125184
runs-on: ubuntu-latest
126185
strategy:
@@ -143,3 +202,29 @@ jobs:
143202
run: |
144203
conda install anaconda-client
145204
anaconda --token $ANACONDA_TOKEN upload --user dppy --label dev ${PACKAGE_NAME}-*.tar.bz2
205+
206+
upload_windows:
207+
needs: test_windows
208+
if: ${{ github.ref == 'refs/heads/master' }}
209+
runs-on: windows-latest
210+
strategy:
211+
matrix:
212+
python: [3.8]
213+
steps:
214+
- name: Download artifact
215+
uses: actions/download-artifact@v2
216+
with:
217+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
218+
- uses: conda-incubator/setup-miniconda@v2
219+
with:
220+
auto-activate-base: true
221+
activate-environment: ""
222+
- name: Install anaconda-client
223+
run: conda install anaconda-client
224+
225+
- name: Upload
226+
env:
227+
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
228+
run: |
229+
conda install anaconda-client
230+
anaconda --token ${{ env.ANACONDA_TOKEN }} upload --user dppy --label dev ${{ env.PACKAGE_NAME }}-*.tar.bz2

dpctl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
)
6666

6767
from ._device_selection import select_device_with_aspects
68+
from ._sycl_timer import SyclTimer
6869
from ._version import get_versions
6970
from .enum_types import backend_type, device_type, event_status_type
7071

@@ -90,7 +91,7 @@
9091
]
9192
__all__ += [
9293
"SyclEvent",
93-
"SyclEventRaw",
94+
"SyclTimer",
9495
]
9596
__all__ += [
9697
"get_platforms",

examples/python/sycl_timer.py renamed to dpctl/_sycl_timer.py

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,65 @@
1717

1818
import timeit
1919

20-
import dpctl
20+
from . import SyclQueue
2121

2222

2323
class SyclTimer:
24-
def __init__(self, host_time=timeit.default_timer, time_scale=1):
25-
self.timer = host_time
24+
"""
25+
SyclTimer(host_timer=timeit.default_timer, time_scale=1)
26+
Python class to measure device time of execution of commands submitted to
27+
:class:`dpctl.SyclQueue` as well as the wall-time.
28+
29+
:Example:
30+
.. code-block:: python
31+
32+
import dpctl
33+
34+
# Create a default SyclQueue
35+
q = dpctl.SyclQueue(property='enable_profiling')
36+
37+
# create the timer
38+
miliseconds_sc = 1e-3
39+
timer = dpctl.SyclTimer(time_scale = miliseconds_sc)
40+
41+
# use the timer
42+
with timer(queue=q):
43+
code_block
44+
45+
# retrieve elapsed times in miliseconds
46+
sycl_dt, wall_dt = timer.dt
47+
48+
Remark:
49+
The timer synchronizes the queue at the entrance and the
50+
exit of the context.
51+
52+
Args:
53+
host_timer (callable): A callable such that host_timer() returns current
54+
host time in seconds.
55+
time_scale (int, float): Ratio of the unit of time of interest and
56+
one second.
57+
"""
58+
59+
def __init__(self, host_timer=timeit.default_timer, time_scale=1):
60+
self.timer = host_timer
2661
self.time_scale = time_scale
62+
self.queue = None
2763

2864
def __call__(self, queue=None):
29-
if isinstance(queue, dpctl.SyclQueue):
65+
if isinstance(queue, SyclQueue):
3066
if queue.has_enable_profiling:
3167
self.queue = queue
3268
else:
3369
raise ValueError(
34-
"The queue does not contain the enable_profiling property"
70+
"The given queue was not created with the "
71+
"enable_profiling property"
3572
)
3673
else:
37-
raise ValueError(
38-
"The passed queue must be <class 'dpctl._sycl_queue.SyclQueue'>"
74+
raise TypeError(
75+
"The passed queue must have type dpctl.SyclQueue, "
76+
"got {}".format(type(queue))
3977
)
40-
return self.__enter__()
78+
return self
4179

4280
def __enter__(self):
4381
self.event_start = self.queue.submit_barrier()
@@ -48,6 +86,7 @@ def __exit__(self, *args):
4886
self.event_finish = self.queue.submit_barrier()
4987
self.host_finish = self.timer()
5088

89+
@property
5190
def dt(self):
5291
self.event_start.wait()
5392
self.event_finish.wait()

dpctl/tensor/_usmarray.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,17 @@ cdef class usm_ndarray:
130130
cdef Py_ssize_t _offset = offset
131131
cdef Py_ssize_t ary_min_displacement = 0
132132
cdef Py_ssize_t ary_max_displacement = 0
133+
cdef Py_ssize_t tmp = 0
133134
cdef char * data_ptr = NULL
134135

135136
self._reset()
136137
if (not isinstance(shape, (list, tuple))
137138
and not hasattr(shape, 'tolist')):
138-
raise TypeError("Argument shape must be a list of a tuple.")
139+
try:
140+
tmp = <Py_ssize_t> shape
141+
shape = [shape, ]
142+
except Exception:
143+
raise TypeError("Argument shape must be a list or a tuple.")
139144
nd = len(shape)
140145
typenum = dtype_to_typenum(dtype)
141146
itemsize = type_bytesize(typenum)

dpctl/tests/test_sycl_event.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,26 @@ def test_profiling_info():
157157
assert event.profiling_info_end
158158
else:
159159
pytest.skip("No OpenCL CPU queues available")
160+
161+
162+
def test_sycl_timer():
163+
try:
164+
q = dpctl.SyclQueue(property="enable_profiling")
165+
except dpctl.SyclQueueCreationError:
166+
pytest.skip("Queue creation of default device failed")
167+
timer = dpctl.SyclTimer()
168+
m1 = dpctl_mem.MemoryUSMDevice(256 * 1024, queue=q)
169+
m2 = dpctl_mem.MemoryUSMDevice(256 * 1024, queue=q)
170+
with timer(q):
171+
# device task
172+
m1.copy_from_device(m2)
173+
# host task
174+
[x ** 2 for x in range(1024)]
175+
host_dt, device_dt = timer.dt
176+
assert host_dt > device_dt
177+
q_no_profiling = dpctl.SyclQueue()
178+
assert q_no_profiling.has_enable_profiling is False
179+
with pytest.raises(ValueError):
180+
timer(queue=q_no_profiling)
181+
with pytest.raises(TypeError):
182+
timer(queue=None)

dpctl/tests/test_sycl_kernel_submit.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ def test_create_program_from_source(self):
3737
size_t index = get_global_id(0); \
3838
c[index] = d*a[index] + b[index]; \
3939
}"
40-
q = dpctl.SyclQueue("opencl:gpu")
40+
q = dpctl.SyclQueue("opencl:gpu", property="enable_profiling")
4141
prog = dpctl_prog.create_program_from_source(q, oclSrc)
4242
axpyKernel = prog.get_sycl_kernel("axpy")
4343

44-
bufBytes = 1024 * np.dtype("i").itemsize
44+
n_elems = 1024 * 512
45+
bufBytes = n_elems * np.dtype("i").itemsize
4546
abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
4647
bbuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
4748
cbuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
48-
a = np.ndarray((1024), buffer=abuf, dtype="i")
49-
b = np.ndarray((1024), buffer=bbuf, dtype="i")
50-
c = np.ndarray((1024), buffer=cbuf, dtype="i")
51-
a[:] = np.arange(1024)
52-
b[:] = np.arange(1024, 0, -1)
49+
a = np.ndarray((n_elems,), buffer=abuf, dtype="i")
50+
b = np.ndarray((n_elems,), buffer=bbuf, dtype="i")
51+
c = np.ndarray((n_elems,), buffer=cbuf, dtype="i")
52+
a[:] = np.arange(n_elems)
53+
b[:] = np.arange(n_elems, 0, -1)
5354
c[:] = 0
5455
d = 2
5556
args = []
@@ -59,10 +60,17 @@ def test_create_program_from_source(self):
5960
args.append(c.base)
6061
args.append(ctypes.c_int(d))
6162

62-
r = [1024]
63+
r = [
64+
n_elems,
65+
]
6366

64-
q.submit(axpyKernel, args, r)
65-
self.assertTrue(np.allclose(c, a * d + b))
67+
timer = dpctl.SyclTimer()
68+
with timer(q):
69+
q.submit(axpyKernel, args, r)
70+
ref_c = a * d + b
71+
host_dt, device_dt = timer.dt
72+
self.assertTrue(host_dt > device_dt)
73+
self.assertTrue(np.allclose(c, ref_c))
6674

6775

6876
if __name__ == "__main__":

0 commit comments

Comments
 (0)