An easy way to run OpenCL kernel files
Project description
OpenCL Kernel Python Wrapper
Install
Requirements
- OpenCL GPU hardware
- numpy
- cmake(if compile from source)
Install from wheel
pip install pyoclk
or download wheel from release and install
Compile from source
Clone this repo
clone by http
git clone --recursive https://github.com/jinmingyi1998/opencl_kernels.git
with ssh
git clone --recursive git@github.com:jinmingyi1998/opencl_kernels.git
Install
cd opencl_kernels
python setup.py install
DO NOT move this directory after install
Usage
Kernel File:
a file named add.cl
kernel void add(global float*a, global float*out, int int_arg, float float_arg){
int x = get_global_id(0);
if(x==0){
printf(" accept int arg: %d, accept float arg: %f\n",int_arg,float_arg);
}
out[x] = a[x] * float_arg + int_arg;
}
Python Code
OOP Style
import numpy as np
import oclk
a = np.random.rand(100, 100).reshape([10, -1])
a = np.ascontiguousarray(a, np.float32)
out = np.zeros(a.shape)
out = np.ascontiguousarray(out, np.float32)
runner = oclk.Runner()
runner.load_kernel("add.cl", "add", "")
timer = oclk.TimerArgs(
enable=True,
warmup=10,
repeat=50,
name='add_kernel'
)
runner.run(
kernel_name="add",
input=[
{"name": "a", "value": a, },
{"name": "out", "value": out, },
{"name": "int_arg", "value": 1, "type": "int"},
{"name": "float_arg", "value": 12.34}
],
output=['out'],
local_work_size=[1, 1],
global_work_size=a.shape,
timer=timer
)
# check result
a = a.reshape([-1])
out = out.reshape([-1])
print(a[:8])
print(out[:8])
Call with Functions
import numpy as np
import oclk
a = np.random.rand(100, 100).reshape([10, -1])
a = np.ascontiguousarray(a,np.float32)
out = np.zeros_like(a)
out = np.ascontiguousarray(out,np.float32)
oclk.init()
oclk.load_kernel("add.cl", "add", "")
r = oclk.run(
kernel_name="add",
input=[
{"name": "a", "value": a, },
{"name": "out", "value": out, },
{"name": "int_arg", "value": 1, },
{"name": "float_arg", "value": 12.34}
],
output=['out'],
local_work_size=[1, 1],
global_work_size=a.shape
)
# check result
a = a.reshape([-1])
out = out.reshape([-1])
print(a[:8])
print(out[:8])
Kernel Benchmark
- write a config like bench_add.yaml
- run
python -m oclk.benchmark examples/bench_add.yaml
Python api Usage
API
example
import numpy as np
a = np.zeros([16, 16, 16], dtype=np.float32)
b = np.zeros([16, 16, 16], dtype=np.float32)
c = np.zeros([16, 16, 16], dtype=np.float32)
a = np.ascontiguousarray(a,dtype=np.float32)
b = np.ascontiguousarray(b,dtype=np.float32)
c = np.ascontiguousarray(c,dtype=np.float32)
run(kernel_name='add',
input=[
{"name": "a", "value": a, },
{"name": "b", "value": b, },
{"name": "int_arg", "value": 1, "type": "int"},
{"name": "float_arg", "value": 12.34},
{"name": "c", "value": c}
],
output=['c'],
local_work_size=[1, 1, 1],
global_work_size=a.shape
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for pyoclk-1.1.3-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdcda187bb766e68811f5d01fab8ff62a46c34c86b3a0e9c8c193526131b08e6 |
|
MD5 | 63202a260df0160278cc6b533fdaed71 |
|
BLAKE2b-256 | b18d66b0ec8295d68182edf7e1596542ebbc8eca71851b950b3be11a4d4ffffd |
Close
Hashes for pyoclk-1.1.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3dc5f133ecadac6c93558aed62803fd412834fd0d1e7debd75289a10e2beb73 |
|
MD5 | 6328ca53d9d1d250564efef03f51fc10 |
|
BLAKE2b-256 | d857da0181d7f4b04974a6029a642f40a2523d7efd35459ab2e38b613b0aef10 |
Close
Hashes for pyoclk-1.1.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24b7a43b252e81132e190a42731111cdbd4fa4663fd03db70d0df85a14f22a72 |
|
MD5 | 0e7b3e1cfbc947f66d07c19a45d75261 |
|
BLAKE2b-256 | e131131dd1fd3fecfcfa49500b3a306b0ac60b858226981983467632ad0a9a35 |
Close
Hashes for pyoclk-1.1.3-cp310-cp310-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72e56b7b93719f52ed201d4888e5fd32d49de9a76fde56343ad66d3aef70ae07 |
|
MD5 | eeb90c2b63daf37e568dfb79d63f09d8 |
|
BLAKE2b-256 | 77607367494043dacc578490b0ecca2c50ca0f01ac5414727626408243456ffc |
Close
Hashes for pyoclk-1.1.3-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a753aa9f4b462d6acd8ff2333866b5fb4ff283a48f0b0f4eb841d5ffcc9f4c6 |
|
MD5 | aebd9bc990d799b722e62c2f256d5012 |
|
BLAKE2b-256 | f4cb237bf8410ac48f778c5056538aca70c7424d72d0bc2626db243f0a789c52 |
Close
Hashes for pyoclk-1.1.3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31fa6214fbc9ceea72c7fe1cc596bb06ca3fd1f21770c143652532059566b81d |
|
MD5 | 03410567a46d451137ddd4cc4adaf77b |
|
BLAKE2b-256 | b20b8e888d3307386aa25bc430e8db3ca2f244aa575307ad8aec6ebd5590c830 |
Close
Hashes for pyoclk-1.1.3-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aa8534c6f4a9f9b7c0499e8531b31d62ac27e766ea9abd63687c22f2e67f5ac |
|
MD5 | 79a40604c7d7a35a7f83e5b6472f92ce |
|
BLAKE2b-256 | 36b1c6dbe5ffdab79e9fad521c40ba770005449f3b8e1634840a85230762b9d1 |
Close
Hashes for pyoclk-1.1.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b60bbd6d932f337e711d3a91f43b6be7d42d8dc658fcc843e315ee2f20a55f8 |
|
MD5 | 394c5fbda3cc5b4c6b7645c3762ef2b7 |
|
BLAKE2b-256 | eca48074fd82789095694e347a5fdb33c4dcc2d22c7c4734526e4b87e51f88ae |
Close
Hashes for pyoclk-1.1.3-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de978646d0294e9abf3775f9a563b5ec36236447266e674ee6fef561b35a3f9b |
|
MD5 | 7d9c295c9f52f0a2a7609857619cfc4c |
|
BLAKE2b-256 | 3c0095b2a7e8d59da74fe47bb24b1ba634c7717b13e434eba651884381dad796 |
Close
Hashes for pyoclk-1.1.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 040089f795fadf9d2fbcb92041c560c869e55d7ff901815cf0285c965c271bb9 |
|
MD5 | f17869132c2c42e89297261be00ef805 |
|
BLAKE2b-256 | 9cb109b1b51a16d7729abbd67a5ec21ec72aeba44b59d02d51ca83f3dca23bd9 |
Close
Hashes for pyoclk-1.1.3-cp36-cp36m-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca8d9715b70190c1472baceb02404743403f07ddddbfb03862668e4613ae8ab0 |
|
MD5 | 2692c9386213ff845d829a46b2361f56 |
|
BLAKE2b-256 | f06a21b6744a0fa1427615684b6d13873e035c70dec5608740fdb40e4659889b |
Close
Hashes for pyoclk-1.1.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b18d7e942a433571c17d3be427da239d4e36b20e9ce6256327ac121883527da |
|
MD5 | ce1b5c1964d1a5c7dc4dffaa7738bfdc |
|
BLAKE2b-256 | 8ce3fafcf94af668983a61fef1c5ffc226121b293d8f0936dac2d4590517debd |