-
Notifications
You must be signed in to change notification settings - Fork 30
Improve examples #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Improve examples #390
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
edd57cc
modified sycl_buffer Cython example
oleksandr-pavlyk d1b097e
changes blacksholes example to adapt to change in memory buffer inter…
oleksandr-pavlyk f432fe5
Python examples expanded:
oleksandr-pavlyk aaef5ef
hindsided black formatting
oleksandr-pavlyk fc1d299
Merge remote-tracking branch 'origin/master' into improve-examples
oleksandr-pavlyk c33e261
Added _runner utility file to examples/python
oleksandr-pavlyk 0c9d8a0
replaced get_sycl_device() method use with property .sycl_device use
oleksandr-pavlyk ae51b45
added license header to _runner
oleksandr-pavlyk e6270e4
Examples for creation of sycl_queue
oleksandr-pavlyk 8e44952
Renamed create_sycl_queues to lsplatforms
oleksandr-pavlyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Data Parallel Control (dpctl) | ||
# | ||
# Copyright 2020-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. | ||
|
||
"""Examples illustrating SYCL device selection features provided by dpctl. | ||
""" | ||
|
||
import dpctl | ||
|
||
|
||
def print_device(d): | ||
if type(d) is not dpctl.SyclDevice: | ||
raise ValueError | ||
print("Name: ", d.name) | ||
print("Vendor: ", d.vendor) | ||
print("Driver version: ", d.driver_version) | ||
print("Backend: ", d.backend) | ||
print("Max EU: ", d.max_compute_units) | ||
|
||
|
||
def create_default_device(): | ||
""" | ||
Create default SyclDevice using `cl::sycl::default_selector`. | ||
|
||
Device created can be influenced by environment variable | ||
SYCL_DEVICE_FILTER, which determines SYCL devices seen by the | ||
SYCL runtime. | ||
""" | ||
d1 = dpctl.SyclDevice() | ||
d2 = dpctl.select_default_device() | ||
assert d1 == d2 | ||
print_device(d1) | ||
return d1 | ||
|
||
|
||
def create_gpu_device(): | ||
""" | ||
Create a GPU device. | ||
|
||
Device created can be influenced by environment variable | ||
SYCL_DEVICE_FILTER, which determines SYCL devices seen by the | ||
SYCL runtime. | ||
""" | ||
d1 = dpctl.SyclDevice("gpu") | ||
d2 = dpctl.select_gpu_device() | ||
assert d1 == d2 | ||
print_device(d1) | ||
return d1 | ||
|
||
|
||
def create_gpu_device_if_present(): | ||
""" | ||
Select from union of two selections using default_selector. | ||
If a GPU device is available, it will be selected, if not, | ||
a CPU device will be selected, if available, otherwise an error | ||
will be raised. | ||
|
||
Device created can be influenced by environment variable | ||
SYCL_DEVICE_FILTER, which determines SYCL devices seen by the | ||
SYCL runtime. | ||
""" | ||
d = dpctl.SyclDevice("gpu,cpu") | ||
print("Selected " + ("GPU" if d.is_gpu else "CPU") + " device") | ||
|
||
|
||
def custom_select_device(): | ||
""" | ||
Programmatically select among available devices. | ||
|
||
Device created can be influenced by environment variable | ||
SYCL_DEVICE_FILTER, which determines SYCL devices seen by the | ||
SYCL runtime. | ||
""" | ||
# select devices that support half-precision computation | ||
devs = [d for d in dpctl.get_devices() if d.has_aspect_fp16] | ||
# choose the device with highest default_selector score | ||
max_score = 0 | ||
selected_dev = None | ||
for d in devs: | ||
if d.default_selector_score > max_score: | ||
max_score = d.default_selector_score | ||
selected_dev = d | ||
if selected_dev: | ||
print_device(selected_dev) | ||
return selected_dev | ||
oleksandr-pavlyk marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.