{"id":18356577,"url":"https://github.com/drlukeparry/pyocl","last_synced_at":"2025-08-27T22:40:19.482Z","repository":{"id":164968375,"uuid":"253542291","full_name":"drlukeparry/pyocl","owner":"drlukeparry","description":"Python OpenCL Helper Classes For Productivity","archived":false,"fork":false,"pushed_at":"2020-04-28T08:55:10.000Z","size":41,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T01:58:35.793Z","etag":null,"topics":["opencl","pyopencl","python","simulation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drlukeparry.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-06T15:40:30.000Z","updated_at":"2023-07-26T02:17:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb4df00d-0486-48b7-9cac-f752809d646f","html_url":"https://github.com/drlukeparry/pyocl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drlukeparry/pyocl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyocl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyocl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyocl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyocl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drlukeparry","download_url":"https://codeload.github.com/drlukeparry/pyocl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyocl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272390955,"owners_count":24926557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opencl","pyopencl","python","simulation"],"created_at":"2024-11-05T22:10:52.757Z","updated_at":"2025-08-27T22:40:19.366Z","avatar_url":"https://github.com/drlukeparry.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: https://github.com/drlukeparry/pyocl/workflows/Python%20application/badge.svg\n  :target: https://github.com/drlukeparry/pyocl/actions\n\n.. image:: https://readthedocs.org/projects/pyocl/badge/?version=latest\n    :target: https://pyocl.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\nPyOCL Module Repository\n========================\n\nProvides convenience methods and boiler-plate code for interacting and setting up the OpenCL compute environment based on the capabilities provided\nby `PyOpenCL \u003chttps://documen.tician.de/pyopencl/\u003e`_. This is to aid setting up simulations for use in development. Common routines and flags are enabled for convenience to improve productivity and provide a consistent\nenvironment to develop in.\n\nInstallation\n*************\n\nInstallation is currently supported on Windows and Linux. PyOCL can be installed along with dependencies using\n\n.. code:: bash\n\n    pip install pyocl\n\n\nDepending on your environment, you will need to install the latest version of PyOpenCL with support dependencies. This can be done through\nthe Anaconda distribution,\n\n.. code:: bash\n\n    conda install -c conda-forge pyopencl\n\n\nFor Windows platforms, PyOpenCL generally do not have the GlInterop capabilties compiled in. Binary python package for PyOpenCL that has been\ncompiled with the GlSharing is available via `Christoph Gohlke's repository \u003chttps://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl\u003e`_.\n\n\nUSAGE\n******\n\nThe basic usage for PyOCL is relatively straightforward once an OpenCL environment is available and pyopencl has been installed.\nThe project aims to compliment the pyopencl library to provide additional convenience methods and a concise framework for\nprototyping and developing simulations using OpenCL. The following example demonstrates initiliasing a default GPU\ndevice and accessing the basic components from pyopencl for creating and launching a kernel.\n\n.. code:: python\n\n    import pyocl\n\n    ocl = pyocl.Core(useGpu = True)\n\n    # Get the current selected platform\n    platform = ocl.platform\n\n    # Identify the GPU Devices available\n    gpuDevices = ocl.gpuDevices\n\n    # Number of compute units available on\n    numComputeUnits = ocl.computeUnits\n\n    # Get the current OpenCL device\n    computeDevice = ocl.device\n\n    # Get the OpenCL context for Initialising the Kernel and Command Queue\n    context = ocl.context\n\nThe further usage can be built upon subclassing OpenCLSimBase, to provide the basic mechanism for launching and\n\n.. code:: python\n\n    import pyopencl as cl\n\n    class Sim(pyocl.OpenCLSimBase):\n\n        def __init__(self, u0):\n\n            # Launch the Kernel Generation\n            self.initialiseCL()\n\n            self.initialiseData(u0)\n\n            # Dimensions of the work item\n            self.nx = u0.shape[0]\n            self.ny = u0.shape[1]\n\n        def initialiseData(self, u0):\n            \"\"\"  Uploads initial data to the CL device \"\"\"\n\n            # PyOpenCL flags for transferring data\n            mf = cl.mem_flags\n\n            # Copy from host memory to the device\n            transferFlag = mf.COPY_HOST_PTR\n\n            # Upload data to the device\n            self.u0 = cl.Buffer(self.ocl.context, mf.READ_WRITE | transferFlag, hostbuf=u0)\n\n        @property\n        def kernel(self):\n            # The kernel can be an inbuilt string or be from an external file which is formatted via the Mako Python Library\n\n            from mako.template import Template\n            with open('./kernelSource.cl') as f:\n                code = str(Template(f.read()).render())\n\n            return code\n\n        def launch(self):\n            # Execute program on device\n\n            # Launch the kernel and put on the OpenCL queue for processing\n            ev = self.program.myKernel(self.queue, (self.nx, self.ny), self.workGroupSize, self.u1, self.u0,)\n\n            ev.wait()  # wait for kernel to finish (i.e. synchronous execution)\n\n\n        def download(self):\n            \"\"\" Enables downloading data from CL device to Python \"\"\"\n\n            # Allocate data on the host for result - this does not exist by default\n            u1 = np.empty((self.nx, self.ny), dtype=np.float32)\n\n            #  Transfers a copy from the device buffer (u0) to host array (self.u0)\n            # is_blocking is by default true on transfers between the host\n            cl.enqueue_copy(self.queue, u1, self.u1, is_blocking=True)\n\n            # Return\n            return u1\n\n\nFurther examples can be found in documented  `examples \u003chttps://github.com/drlukeparry/pyocl/tree/master/examples\u003e`_  and also via\nthe project `documentation \u003chttps://pyocl.readthedocs.io/en/latest/\u003e`_.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrlukeparry%2Fpyocl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrlukeparry%2Fpyocl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrlukeparry%2Fpyocl/lists"}