Skip to content

Commit

Permalink
Merge pull request #303 from clEsperanto/enh-execute-function
Browse files Browse the repository at this point in the history
update anchor default value
  • Loading branch information
StRigaud authored Jan 28, 2025
2 parents 7650417 + 2cb7143 commit 28056a5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 67 deletions.
142 changes: 80 additions & 62 deletions demos/api/execute_custom_opencl_kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"id": "48b37b2b-e1ef-4cdf-b3ec-a3be0d461782",
"metadata": {},
"outputs": [
Expand All @@ -23,7 +23,7 @@
"text/plain": [
"(OpenCL) NVIDIA GeForce RTX 4090 (OpenCL 3.0 CUDA)\n",
"\tVendor: NVIDIA Corporation\n",
"\tDriver Version: 535.216.01\n",
"\tDriver Version: 535.230.02\n",
"\tDevice Type: GPU\n",
"\tCompute Units: 128\n",
"\tGlobal Memory Size: 24217 MB\n",
Expand All @@ -32,7 +32,7 @@
"\tImage Support: Yes"
]
},
"execution_count": 11,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -59,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 2,
"id": "c2590fc6-17e8-464c-91e2-fe2eebe70aa9",
"metadata": {},
"outputs": [],
Expand All @@ -84,58 +84,60 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 3,
"id": "07a27608-7cb4-4b1a-991c-ea8a1bb5d35c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0mcle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnative_execute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0manchor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'/data/clesperanto/pyclesperanto/pyclesperanto/_functionalities.py'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mkernel_source\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mkernel_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mglobal_size\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mlocal_size\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mparameters\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpyclesperanto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pyclesperanto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_Device\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\n",
"Execute an OpenCL kernel from a file or a string\n",
"\n",
"Call, build, and execute a kernel compatible with OpenCL language.\n",
"The kernel can be called from a file or a string.\n",
"\n",
"The parameters must still be passed as a dictionary with the correct types and order.\n",
"Buffer parameters must be passed as Array objects. Scalars must be passed as Python native float or int.\n",
"\n",
"Warning: Only 1D buffers are supported for now.\n",
"\n",
"Parameters\n",
"----------\n",
"anchor : str, default = '__file__'\n",
" Enter __file__ when calling this method and the corresponding open.cl\n",
" file lies in the same folder as the python file calling it.\n",
" Ignored if kernel_source is a string.\n",
"kernel_source : str\n",
" Filename of the open.cl file to be called or string containing the open.cl source code\n",
"kernel_name : str\n",
" Kernel method inside the open.cl file to be called\n",
" most clij/clesperanto kernel functions have the same name as the file they are in\n",
"global_size : tuple (z,y,x), default = (1, 1, 1)\n",
" Global_size according to OpenCL definition (usually shape of the destination image).\n",
"local_size : tuple (z,y,x), default = (1, 1, 1)\n",
" Local_size according to OpenCL definition (usually default is good).\n",
"parameters : dict(str, [Array, float, int])\n",
" Dictionary containing parameters. Take care: They must be of the\n",
" right type and in the right order as specified in the open.cl file.\n",
"device : Device, default = None\n",
" The device to execute the kernel on. If None, use the current device\n",
"\u001b[0;31mFile:\u001b[0m /data/clesperanto/pyclesperanto/pyclesperanto/_functionalities.py\n",
"\u001b[0;31mType:\u001b[0m function"
]
"data": {
"text/plain": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0mcle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnative_execute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0manchor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mkernel_source\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mkernel_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mglobal_size\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mlocal_size\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mparameters\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpyclesperanto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pyclesperanto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_Device\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\n",
"Execute an OpenCL kernel from a file or a string\n",
"\n",
"Call, build, and execute a kernel compatible with OpenCL language.\n",
"The kernel can be called from a file or a string.\n",
"\n",
"The parameters must still be passed as a dictionary with the correct types and order.\n",
"Buffer parameters must be passed as Array objects. Scalars must be passed as Python native float or int.\n",
"\n",
"Warning: Only 1D buffers are supported for now.\n",
"\n",
"Parameters\n",
"----------\n",
"anchor : str, default = '__file__'\n",
" Enter __file__ when calling this method and the corresponding open.cl\n",
" file lies in the same folder as the python file calling it.\n",
" Ignored if kernel_source is a string.\n",
"kernel_source : str\n",
" Filename of the open.cl file to be called or string containing the open.cl source code\n",
"kernel_name : str\n",
" Kernel method inside the open.cl file to be called\n",
" most clij/clesperanto kernel functions have the same name as the file they are in\n",
"global_size : tuple (z,y,x), default = (1, 1, 1)\n",
" Global_size according to OpenCL definition (usually shape of the destination image).\n",
"local_size : tuple (z,y,x), default = (1, 1, 1)\n",
" Local_size according to OpenCL definition (usually default is good).\n",
"parameters : dict(str, [Array, float, int])\n",
" Dictionary containing parameters. Take care: They must be of the\n",
" right type and in the right order as specified in the open.cl file.\n",
"device : Device, default = None\n",
" The device to execute the kernel on. If None, use the current device\n",
"\u001b[0;31mFile:\u001b[0m /data/clesperanto/pyclesperanto/pyclesperanto/_functionalities.py\n",
"\u001b[0;31mType:\u001b[0m function"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
Expand Down Expand Up @@ -164,7 +166,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"id": "a88d0327-71c1-461f-8419-5a194ae4076f",
"metadata": {},
"outputs": [],
Expand All @@ -190,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 5,
"id": "6080dfd1-e7e7-411d-bf89-5981bafecd2d",
"metadata": {},
"outputs": [],
Expand All @@ -215,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 6,
"id": "c6bc9100-6f34-41f4-9431-86fd20d2c731",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -311,7 +313,7 @@
" 6., 6.]], dtype=float32)"
]
},
"execution_count": 16,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -339,7 +341,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 7,
"id": "7ca02bc3-dbb4-4968-9632-dd80263114d9",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -375,7 +377,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 8,
"id": "d8b463cf-09bc-455b-81c6-977d1469ed7e",
"metadata": {},
"outputs": [],
Expand All @@ -391,7 +393,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 9,
"id": "f2eb9383-8b6b-47a2-aed4-952d8e368a50",
"metadata": {},
"outputs": [],
Expand All @@ -406,7 +408,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 10,
"id": "1294b0dd-5585-49ff-bbab-9a8a209c5cbf",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -502,7 +504,7 @@
" 6., 6.]], dtype=float32)"
]
},
"execution_count": 20,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -511,11 +513,27 @@
"print(\"output array:\", arr_c.shape)\n",
"cle.pull(arr_c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3b27527-cd91-408f-bc1c-aa0302fc8c96",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "99b3f364-409b-4156-a882-74a37b48ee8b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "skbe",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
10 changes: 5 additions & 5 deletions pyclesperanto/_functionalities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def execute(
anchor=__file__,
anchor=None,
kernel_source: str = "",
kernel_name: str = "",
global_size: tuple = (1, 1, 1),
Expand All @@ -28,12 +28,12 @@ def execute(
Parameters
----------
anchor : str, default = '__file__'
Enter __file__ when calling this method and the corresponding open.cl
anchor : str, default = 'None'
Use __file__ when calling this method and the corresponding open.cl
file lies in the same folder as the python file calling it.
Ignored if kernel_source is a string.
kernel_source : str
Filename of the open.cl file to be called or string containing the open.cl source code
Filename of the open.cl file to be called, or string containing the open.cl source code
kernel_name : str
Kernel method inside the open.cl file to be called
most clij/clesperanto kernel functions have the same name as the file they are in
Expand Down Expand Up @@ -78,7 +78,7 @@ def load_file(anchor, filename):


def native_execute(
anchor=__file__,
anchor=None,
kernel_source: str = "",
kernel_name: str = "",
global_size: tuple = (1, 1, 1),
Expand Down

0 comments on commit 28056a5

Please sign in to comment.