|
| 1 | +# Data Parallel Control (dpctl) |
| 2 | +# |
| 3 | +# Copyright 2020-2021 Intel Corporation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | + |
| 18 | +import numba_dppy as dppy |
| 19 | +import numpy as np |
| 20 | +from sycl_timer import SyclTimer |
| 21 | + |
| 22 | +import dpctl |
| 23 | + |
| 24 | + |
| 25 | +@dppy.kernel |
| 26 | +def dppy_gemm(a, b, c): |
| 27 | + i = dppy.get_global_id(0) |
| 28 | + j = dppy.get_global_id(1) |
| 29 | + if i >= c.shape[0] or j >= c.shape[1]: |
| 30 | + return |
| 31 | + c[i, j] = 0 |
| 32 | + for k in range(c.shape[0]): |
| 33 | + c[i, j] += a[i, k] * b[k, j] |
| 34 | + |
| 35 | + |
| 36 | +X = 1024 |
| 37 | +Y = 16 |
| 38 | +global_size = X, X |
| 39 | + |
| 40 | +griddim = X, X |
| 41 | +blockdim = Y, Y |
| 42 | + |
| 43 | +a = np.arange(X * X, dtype=np.float32).reshape(X, X) |
| 44 | +b = np.array(np.random.random(X * X), dtype=np.float32).reshape(X, X) |
| 45 | +c = np.ones_like(a).reshape(X, X) |
| 46 | + |
| 47 | +q = dpctl.SyclQueue("opencl:gpu", property="enable_profiling") |
| 48 | +with dpctl.device_context(q): |
| 49 | + timers = SyclTimer(time_scale=1) |
| 50 | + with timers(q): |
| 51 | + dppy_gemm[griddim, blockdim](a, b, c) |
| 52 | + host_time, device_time = timers.dt() |
| 53 | + print("Wall time: ", host_time, "\n", "Device time: ", device_time) |
0 commit comments