Beispiel #1
0
# limitations under the License.

import dpctl
import syclbuffer as sb
import numpy as np

X = np.full((10**4, 4098), 1e-4, dtype="d")

# warm-up
print("=" * 10 + " Executing warm-up " + "=" * 10)
print("NumPy result: ", X.sum(axis=0))

dpctl.set_default_queue("opencl", "cpu", 0)
print("SYCL({}) result: {}".format(
    dpctl.get_current_queue().get_sycl_device().get_device_name(),
    sb.columnwise_total(X),
))

dpctl.set_default_queue("opencl", "gpu", 0)
print("SYCL({}) result: {}".format(
    dpctl.get_current_queue().get_sycl_device().get_device_name(),
    sb.columnwise_total(X),
))

import timeit

print("Times for 'opencl:cpu:0'")
print(
    timeit.repeat(
        stmt="sb.columnwise_total(X)",
        setup='dpctl.set_default_queue("opencl", "cpu", 0); '
Beispiel #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.

import syclbuffer as sb
import numpy as np

X = np.random.randn(100, 4)

print("Result computed by NumPy")
print(X.sum(axis=0))
print("Result computed by SYCL extension")
print(sb.columnwise_total(X))

print("")
# controlling where to offload
import dpctl

with dpctl.device_context("opencl:gpu"):
    print("Running on: ",
          dpctl.get_current_queue().get_sycl_device().get_device_name())
    print(sb.columnwise_total(X))

with dpctl.device_context("opencl:cpu"):
    print("Running on: ",
          dpctl.get_current_queue().get_sycl_device().get_device_name())
    print(sb.columnwise_total(X))
Beispiel #3
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.

import numpy as np
import syclbuffer as sb

import dpctl

X = np.random.randn(100, 4)

print("Result computed by NumPy")
print(X.sum(axis=0))
print("Result computed by SYCL extension using default offloading target")
print(sb.columnwise_total(X))

print("")

# controlling where to offload

q = dpctl.SyclQueue("opencl:gpu")
print("Running on: ", q.sycl_device.name)
print(sb.columnwise_total(X, queue=q))

q = dpctl.SyclQueue("opencl:cpu")
print("Running on: ", q.sycl_device.name)
print(sb.columnwise_total(X, queue=q))
Beispiel #4
0
import numpy as np
import syclbuffer as sb

import dpctl

X = np.full((10 ** 4, 4098), 1e-4, dtype="d")

# warm-up
print("=" * 10 + " Executing warm-up " + "=" * 10)
print("NumPy result: ", X.sum(axis=0))

q = dpctl.SyclQueue("opencl:cpu")
print(
    "SYCL({}) result: {}".format(
        q.sycl_device.name,
        sb.columnwise_total(X, queue=q),
    )
)

q = dpctl.SyclQueue("opencl:gpu")
print(
    "SYCL({}) result: {}".format(
        q.sycl_device.name,
        sb.columnwise_total(X, queue=q),
    )
)


print("Times for 'opencl:cpu'")
print(
    timeit.repeat(