{"id":15637137,"url":"https://github.com/ysh329/opencl-101","last_synced_at":"2025-04-13T05:40:57.991Z","repository":{"id":45722728,"uuid":"97831656","full_name":"ysh329/OpenCL-101","owner":"ysh329","description":"Learn OpenCL step by step.","archived":false,"fork":false,"pushed_at":"2022-08-30T05:18:26.000Z","size":487,"stargazers_count":134,"open_issues_count":48,"forks_count":29,"subscribers_count":9,"default_branch":"dev","last_synced_at":"2025-03-26T22:21:39.405Z","etag":null,"topics":["gpu-acceleration","gpu-programming","guides","opencl","scratch","tutorial-code","tutorials"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ysh329.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-20T12:15:23.000Z","updated_at":"2025-03-14T13:32:21.000Z","dependencies_parsed_at":"2023-01-16T16:45:34.112Z","dependency_job_id":null,"html_url":"https://github.com/ysh329/OpenCL-101","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2FOpenCL-101","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2FOpenCL-101/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2FOpenCL-101/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2FOpenCL-101/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysh329","download_url":"https://codeload.github.com/ysh329/OpenCL-101/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670515,"owners_count":21142899,"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","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":["gpu-acceleration","gpu-programming","guides","opencl","scratch","tutorial-code","tutorials"],"created_at":"2024-10-03T11:10:23.659Z","updated_at":"2025-04-13T05:40:57.833Z","avatar_url":"https://github.com/ysh329.png","language":"C","readme":"# OpenCL-101\nLearn OpenCL step by step as below.\n\n1. OpenCL Examples\n2. Installation Guide of OpenCL \n\n# 1. OpenCL Examples\n\n1. [vec-add-standard](./vec-add-standard): An standard OpenCL example, accomplish addition operation of two int-type arrays (vectors).\n2. [vec-add-simple](./vec-add-simple): An simple addition operation of two vectors (NOT recommanded).\n3. [bandwidth](./bandwidth): Measure bandwith for various variable type.\n4. [mat-transpose](./mat-transpose): An demo of matrix transpose with two OpenCL kernels.\n\n# 2. Installation Guide of OpenCL \n\nYou can choose one or two ways to use OpenCL:  \n1. Install OpenCL on Ubuntu 16.04 64-bit  \n2. Using OpenCL by Docker\n3. Using OpenCL by WSL2\n\n## 2.1 Install OpenCL on Ubuntu 16.04 64-bit\n\n```Shell\n# below instructions refer linux安装opencl：ubuntu14.04+opencl1.1 - qccz123456的博客 - CSDN博客\n# http://blog.csdn.net/qccz123456/article/details/52606788\n\n$ sudo apt-get update\n$ sudo apt-get install build-essential g++ cmake\n$ sudo apt-get install clang libclang-3.4-dev libclang-dev libclang1\n$ sudo apt-get install ocl-icd-opencl-dev ocl-icd-libopencl1\n$ sudo apt-get install opencl-headers ocl-icd-dev ocl-icd-libopencl1\n\n# below instructions refer Ubuntu 16.04.2 下为 Intel 显卡启用 OpenCL_Linux教程_Linux公社-Linux系统门户网站\n# http://www.linuxidc.com/Linux/2017-03/141455.htm\n\n$ sudo apt install ocl-icd-libopencl1\n$ sudo apt install opencl-headers\n$ sudo apt install clinfo\n$ sudo apt install ocl-icd-opencl-dev\n$ sudo apt install beignet\n```\n\n## 2.2 Using OpenCL by Docker\n\nUsing Docker is convenient, which you don't need config and install enviroments for all about OpenCL. Of course, [install Docker Community Edition](https://docs.docker.com/) first and then search relative images in [DockerHub](https://hub.docker.com/).\n\nAfter finish Docker installation, please follow [this instruction from chihchun/opencl-intel](https://hub.docker.com/r/chihchun/opencl-intel/). If anything goes normally, using command below in command line: \n\n```Shell\n$ docker run -t -i --device /dev/dri:/dev/dri \\\nchihchun/hashcat-beignet hashcat -b\n```\n\nIt will print similar messages as *Verify installation*.\n\n## 2.3 Verify Installation\n\nUsing instruction below, successful installation will print same following messages:\n```shell\n$ clinfo\n\n# print message below\n\nNumber of platforms                               1\n  Platform Name                                   Intel Gen OCL Driver\n  Platform Vendor                                 Intel\n  Platform Version                                OpenCL 1.2 beignet 1.1.1\n  Platform Profile                                FULL_PROFILE\n  Platform Extensions                             cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_spir cl_khr_icd\n  Platform Extensions function suffix             Intel\n\n  Platform Name                                   Intel Gen OCL Driver\nNumber of devices                                 1\n  Device Name                                     Intel(R) HD Graphics IvyBridge M GT2\n  Device Vendor                                   Intel\n  Device Vendor ID                                0x8086\n  Device Version                                  OpenCL 1.2 beignet 1.1.1\n  Driver Version                                  1.1.1\n  Device OpenCL C Version                         OpenCL C 1.2 beignet 1.1.1\n  Device Type                                     GPU\n  Device Profile                                  FULL_PROFILE\n  Max compute units                               16\n  Max clock frequency                             1000MHz\n  Device Partition                                (core)\n    Max number of sub-devices                     1\n    Supported partition types                     None, None, None\n  Max work item dimensions                        3\n  Max work item sizes                             512x512x512\n  Max work group size                             512\n  Preferred work group size multiple              16\n  Preferred / native vector sizes                 \n    char                                                16 / 8       \n    short                                                8 / 8       \n    int                                                  4 / 4       \n    long                                                 2 / 2       \n    half                                                 0 / 8        (n/a)\n    float                                                4 / 4       \n    double                                               0 / 2        (n/a)\n  Half-precision Floating-point support           (n/a)\n  Single-precision Floating-point support         (core)\n    Denormals                                     No\n    Infinity and NANs                             Yes\n    Round to nearest                              Yes\n    Round to zero                                 No\n    Round to infinity                             No\n    IEEE754-2008 fused multiply-add               No\n    Support is emulated in software               No\n    Correctly-rounded divide and sqrt operations  No\n  Double-precision Floating-point support         (n/a)\n  Address bits                                    32, Little-Endian\n  Global memory size                              2147483648 (2GiB)\n  Error Correction support                        No\n  Max memory allocation                           1073741824 (1024MiB)\n  Unified memory for Host and Device              Yes\n  Minimum alignment for any data type             128 bytes\n  Alignment of base address                       1024 bits (128 bytes)\n  Global Memory cache type                        Read/Write\n  Global Memory cache size                        8192\n  Global Memory cache line                        64 bytes\n  Image support                                   Yes\n    Max number of samplers per kernel             16\n    Max size for 1D images from buffer            65536 pixels\n    Max 1D or 2D image array size                 2048 images\n    Max 2D image size                             8192x8192 pixels\n    Max 3D image size                             8192x8192x2048 pixels\n    Max number of read image args                 128\n    Max number of write image args                8\n  Local memory type                               Global\n  Local memory size                               65536 (64KiB)\n  Max constant buffer size                        134217728 (128MiB)\n  Max number of constant args                     8\n  Max size of kernel argument                     1024\n  Queue properties                                \n    Out-of-order execution                        No\n    Profiling                                     Yes\n  Prefer user sync for interop                    Yes\n  Profiling timer resolution                      80ns\n  Execution capabilities                          \n    Run OpenCL kernels                            Yes\n    Run native kernels                            Yes\n    SPIR versions                                 \u003cprintDeviceInfo:138: get   SPIR versions size : error -30\u003e\n  printf() buffer size                            1048576 (1024KiB)\n  Built-in kernels                                __cl_copy_region_align4;__cl_copy_region_align16;__cl_cpy_region_unalign_same_offset;__cl_copy_region_unalign_dst_offset;__cl_copy_region_unalign_src_offset;__cl_copy_buffer_rect;__cl_copy_image_1d_to_1d;__cl_copy_image_2d_to_2d;__cl_copy_image_3d_to_2d;__cl_copy_image\n_2d_to_3d;__cl_copy_image_3d_to_3d;__cl_copy_image_2d_to_buffer;__cl_copy_image_3d_to_buffer;__cl_copy_buffer_to_image_2d;__cl_copy_buffer_to_image_3d;__cl_fill_region_unalign;__cl_fill_region_align2;__cl_fill_region_align4;__cl_fill_region_align8_2;__cl_fill_region_align8_4;__cl_fill_region_align8_8;__cl_fill_region_\nalign8_16;__cl_fill_region_align128;__cl_fill_image_1d;__cl_fill_image_1d_array;__cl_fill_image_2d;__cl_fill_image_2d_array;__cl_fill_image_3d;\n  Device Available                                Yes\n  Compiler Available                              Yes\n  Linker Available                                Yes\n  Device Extensions                               cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_spir cl_khr_icd\n\nNULL platform behavior\n  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  Intel Gen OCL Driver\n  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   Success [Intel]\n  clCreateContext(NULL, ...) [default]            Success [Intel]\n  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform\n  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  Success (1)\n    Platform Name                                 Intel Gen OCL Driver\n    Device Name                                   Intel(R) HD Graphics IvyBridge M GT2\n  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform\n  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No devices found in platform\n  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  Success (1)\n    Platform Name                                 Intel Gen OCL Driver\n    Device Name                                   Intel(R) HD Graphics IvyBridge M GT2\n\nICD loader properties\n  ICD loader Name                                 OpenCL ICD Loader\n  ICD loader Vendor                               OCL Icd free software\n  ICD loader Version                              2.2.8\n  ICD loader Profile                              OpenCL 1.2\n        NOTE:   your OpenCL library declares to support OpenCL 1.2,\n                but it seems to support up to OpenCL 2.1 too.  \n\n```\n\n\n## How to compile OpenCL example in GCC?  \nPrecisely, the kernel compilation in OpenCL is make in running time (library call). \n\nIn Gcc, for compilation, you only need the headers (aviables on Kronos site). But for linkage, you have to install OpenCL compatible driver.\n\nin the Makefile :  \n* for Mac OSX : -framework OpenCL \n* for Linux : -lOpenCL\n\nref: How to compile OpenCL example in GCC?  \nhttps://forums.khronos.org/showthread.php/5728-How-to-compile-OpenCL-example-in-GCC\n\n# 3. Using OpenCL by WSL2\n\n- guide: https://devblogs.microsoft.com/commandline/oneapi-l0-openvino-and-opencl-coming-to-the-windows-subsystem-for-linux-for-intel-gpus/\n- link: https://www.intel.com/content/www/us/en/artificial-intelligence/harness-the-power-of-intel-igpu-on-your-machine.html\n\n# Other problems\n\n## git error: unable to auto-detect email address\n\n```shell\nyuanshuai@firefly:~/code/OpenCL-101$ git commit -m \"update README.md\"\n\n*** Please tell me who you are.\n\nRun\n\n  git config --global user.email \"you@example.com\"\n  git config --global user.name \"Your Name\"\n\nto set your account's default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: unable to auto-detect email address (got 'yuanshuai@firefly.(none)')\n```\n\nAfter following instructions above, it still occured same error message. I reset `user.email` and `user.name` using `git config --local user.email \"you@example.com\"` and `git config --local user.name \"Your name\"` and it's okay!\n\nref: git中报unable to auto-detect email address 错误的解决拌办法 - liufangbaishi2014的博客 - CSDN博客\nhttp://blog.csdn.net/liufangbaishi2014/article/details/50037507\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysh329%2Fopencl-101","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysh329%2Fopencl-101","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysh329%2Fopencl-101/lists"}