Skip to content

Commit

Permalink
add jupyter notebooks for many python samples (#96)
Browse files Browse the repository at this point in the history
* initial jupyter notebooks for enumopencl and mandelbrot

* updated a bunch of samples and added a bunch of descriptive text

* update copyright dates, switch to SPDX license identifiers
  • Loading branch information
bashbaug authored Jan 1, 2024
1 parent efeae73 commit 75034a7
Show file tree
Hide file tree
Showing 17 changed files with 1,102 additions and 198 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ external/OpenCL-Headers/
external/OpenCL-ICD-Loader/
install/
*~
.ipynb_checkpoints
20 changes: 2 additions & 18 deletions samples/python/00_enumopencl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# Copyright (c) 2019-2021 Ben Ashbaugh
# Copyright (c) 2019-2024 Ben Ashbaugh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# SPDX-License-Identifier: MIT

add_opencl_python_sample(
NUMBER 00
Expand Down
115 changes: 115 additions & 0 deletions samples/python/00_enumopencl/enumopencl.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d0b4a6b7-3ba6-4cc0-8b3c-ba4638247b3d",
"metadata": {},
"source": [
"# enumopencl\n",
"\n",
"### Copyright Information"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "163deb93-0c32-40c7-aaf0-a427b453ccc3",
"metadata": {},
"outputs": [],
"source": [
"# Copyright (c) 2024 Ben Ashbaugh\n",
"#\n",
"# SPDX-License-Identifier: MIT"
]
},
{
"cell_type": "markdown",
"id": "79250647-6a73-42d0-aee8-051aae55a2a8",
"metadata": {},
"source": [
"## Sample Purpose\n",
"\n",
"This is a very simple sample that demonstrates how to enumerate the OpenCL platforms that are installed on a machine, and the OpenCL devices that these platforms expose.\n",
"\n",
"This is a good first sample to run to verify that OpenCL is correctly installed on your machine, and that your environment is correctly setup.\n",
"\n",
"## Sample\n",
"\n",
"The first thing we will do is to import pyopencl so we have access to OpenCL from Python."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c728115-6d8e-4e4c-a4f8-55a6580864f7",
"metadata": {},
"outputs": [],
"source": [
"import pyopencl as cl"
]
},
{
"cell_type": "markdown",
"id": "b343a628-3e47-4704-8e69-049200236316",
"metadata": {},
"source": [
"Assuming that this worked correctly, we can now query the installed OpenCL platforms. An OpenCL platform is an OpenCL implementation for a specific device or collection of devices. There may be an OpenCL platform from a specific device vendor, a specific class of devices from that vendor, or even a specific device. For example, if you have a CPU from one vendor and a GPU from another vendor, you may need to install two OpenCL platforms to enumerate both devices.\n",
"\n",
"If no platforms are found then either no OpenCL platforms are installed or there is a problem with your installation.\n",
"\n",
"For each of the platforms that we find we will print information about the platform and information about each of the devices that the platform supports."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23b4e3c9-0d34-43af-95fb-2a207d6942fc",
"metadata": {},
"outputs": [],
"source": [
"for p, platform in enumerate(cl.get_platforms()):\n",
" print(\"Platform[{}]:\".format(p))\n",
" print(\" Name: \" + platform.get_info(cl.platform_info.NAME))\n",
" print(\" Vendor: \" + platform.get_info(cl.platform_info.VENDOR))\n",
" print(\" Driver Version: \" + platform.get_info(cl.platform_info.VERSION))\n",
" for d, device in enumerate(platform.get_devices()):\n",
" print(\"Device[{}]:\".format(d))\n",
" print(\" Type: \" + cl.device_type.to_string(device.get_info(cl.device_info.TYPE)))\n",
" print(\" Name: \" + device.get_info(cl.device_info.NAME))\n",
" print(\" Vendor: \" + device.get_info(cl.device_info.VENDOR))\n",
" print(\" Device Version: \" + device.get_info(cl.device_info.VERSION))\n",
" print(\" Driver Version: \" + device.get_info(cl.device_info.DRIVER_VERSION))\n",
" print()"
]
},
{
"cell_type": "markdown",
"id": "d447785a-0580-423a-b56e-63bb424fe608",
"metadata": {},
"source": [
"If you see at least one platform and device listed above, great, your installation is working!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
20 changes: 2 additions & 18 deletions samples/python/00_enumopencl/enumopencl.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
#!/usr/bin/env python

# Copyright (c) 2019-2021 Ben Ashbaugh
# Copyright (c) 2019-2024 Ben Ashbaugh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# SPDX-License-Identifier: MIT

import pyopencl as cl

Expand Down
20 changes: 2 additions & 18 deletions samples/python/01_copybuffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# Copyright (c) 2019-2021 Ben Ashbaugh
# Copyright (c) 2019-2024 Ben Ashbaugh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# SPDX-License-Identifier: MIT

add_opencl_python_sample(
NUMBER 01
Expand Down
Loading

0 comments on commit 75034a7

Please sign in to comment.