Skip to content

Commit dddfdf3

Browse files
committed
Merge remote-tracking branch 'origin/main' into matrixperf-i8
2 parents 7e95831 + d56380b commit dddfdf3

138 files changed

Lines changed: 738 additions & 182 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2024 Ben Ashbaugh
1+
# Copyright (c) 2019-2025 Ben Ashbaugh
22
#
33
# SPDX-License-Identifier: MIT
44

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2024 Ben Ashbaugh
3+
Copyright (c) 2019-2025 Ben Ashbaugh
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Simple OpenCL<sup>TM</sup> Samples
22

3-
[![build](https://github.com/bashbaug/SimpleOpenCLSamples/workflows/build/badge.svg?branch=main)](https://github.com/bashbaug/SimpleOpenCLSamples/actions?query=workflow%3Abuild+branch%3Amain)
3+
[![build](https://github.com/bashbaug/SimpleOpenCLSamples/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/bashbaug/SimpleOpenCLSamples/actions?query=workflow%3Abuild+branch%3Amain)
44

55
This repo contains simple OpenCL samples that demonstrate how to build
66
OpenCL applications using only the Khronos-provided headers and libs.

docs/env/ubuntu/24.04.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Ubuntu 24.04 Setup Instructions
2+
3+
## Verify Hardware Support
4+
5+
Most modern GPUs support OpenCL. For integrated graphics devices (iGPUs), use `lscpu` to get the processor SKU. Detailed information for Intel SKUs is available from [ark.intel.com](ark.intel.com). Detailed information for AMD processors is available from [AMD's product page](https://www.amd.com/en/products/specifications/processors).
6+
7+
## Build Dependencies
8+
9+
OCL Headers:
10+
11+
```bash
12+
sudo apt install opencl-c-headers opencl-clhpp-headers
13+
```
14+
15+
The OpenCL API has its own set of header files; the above command installs both C and C++ headers files. The C header can be found in `<CL/cl.h>`; the C++ header is in `<CL/opencl.hpp>`.
16+
17+
OCL ICD Loader:
18+
19+
```bash
20+
sudo apt install ocl-icd-opencl-dev
21+
```
22+
23+
OpenCL applications generally link against an OpenCL Installable Compute Device (ICD) loader instead of a specific OpenCL implementation; see [https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc](https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc) for more information about this system.
24+
25+
## Runtime Dependencies
26+
27+
OpenCL requires a compute runtime to manage the interaction between the OpenCL API and the GPU.
28+
29+
### OCL ICD Loader
30+
31+
```bash
32+
sudo apt install ocl-icd-libopencl1
33+
```
34+
35+
OpenCL applications generally link against an OpenCL Installable Compute Device (ICD) loader instead of a specific OpenCL implementation; see [https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc](https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc) for more information about this system.
36+
37+
### AMD Compute Runtime
38+
39+
AMD supports OpenCL through their ROCm platform. Installation instructions are [here](https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu).
40+
41+
### Intel Compute Runtime
42+
43+
Intel's OpenCL support is provided through the NEO compute runtime. Download packages from the project's [GitHub releases page](https://github.com/intel/compute-runtime/releases).
44+
45+
### Nvidia Compute Runtime
46+
47+
Nvidia provides OpenCL support through their proprietary driver, available from the [graphics-drivers PPA](https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa).
48+
49+
```bash
50+
sudo add-apt-repository ppa:graphics-drivers/ppa
51+
sudo apt update
52+
sudo apt install nvidia-graphics-drivers-<version>
53+
```
54+
55+
### Configure Permissions
56+
57+
```bash
58+
sudo usermod -a -G video $USER
59+
sudo usermod -a -G render $USER
60+
```
61+
62+
Users running OpenCL applications on a GPU require additional permissions granted by the groups above.
63+
64+
## Verification
65+
66+
The `clinfo` utility can be used to verify the environment has been properly configured.
67+
68+
```bash
69+
$ sudo apt install clinfo
70+
$ clinfo
71+
<platform information should show here>
72+
```
73+
74+
## Troubleshooting
75+
76+
If `clinfo` indicates there are 0 supported platforms:
77+
78+
1. Verify your host has OpenCL-capable hardware attached
79+
2. Verify clinfo is running as a user with appropriate group membership
80+
3. Verify new group membership has been applied (this may require logout or reboot)
81+
4. Verify the correct compute runtime is installed
82+
5. Check the kernel log (`sudo dmesg`) for related errors

include/CL/opencl.hpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@ CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_
17761776
#if defined(cl_khr_command_buffer)
17771777
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR, cl_device_command_buffer_capabilities_khr)
17781778
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR, cl_command_queue_properties)
1779+
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR, cl_command_queue_properties)
17791780
CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_QUEUES_KHR, cl::vector<CommandQueue>)
17801781
CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_NUM_QUEUES_KHR, cl_uint)
17811782
CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR, cl_uint)
@@ -2441,7 +2442,7 @@ class Device : public detail::Wrapper<cl_device_id>
24412442
getInfo(cl_int* err = nullptr) const
24422443
{
24432444
typename detail::param_traits<
2444-
detail::cl_device_info, name>::param_type param;
2445+
detail::cl_device_info, name>::param_type param{};
24452446
cl_int result = getInfo(name, &param);
24462447
if (err != nullptr) {
24472448
*err = result;
@@ -2700,7 +2701,7 @@ class Platform : public detail::Wrapper<cl_platform_id>
27002701
getInfo(cl_int* err = nullptr) const
27012702
{
27022703
typename detail::param_traits<
2703-
detail::cl_platform_info, name>::param_type param;
2704+
detail::cl_platform_info, name>::param_type param{};
27042705
cl_int result = getInfo(name, &param);
27052706
if (err != nullptr) {
27062707
*err = result;
@@ -3389,7 +3390,7 @@ class Context
33893390
getInfo(cl_int* err = nullptr) const
33903391
{
33913392
typename detail::param_traits<
3392-
detail::cl_context_info, name>::param_type param;
3393+
detail::cl_context_info, name>::param_type param{};
33933394
cl_int result = getInfo(name, &param);
33943395
if (err != nullptr) {
33953396
*err = result;
@@ -3472,7 +3473,7 @@ class Context
34723473
cl_int* err = nullptr) const
34733474
{
34743475
typename detail::param_traits<
3475-
detail::cl_image_requirements_info_ext, type>::param_type param;
3476+
detail::cl_image_requirements_info_ext, type>::param_type param{};
34763477
cl_int result = getImageRequirementsInfoExt(type, &param, flags, properties, image_format, image_desc);
34773478
if (err != nullptr) {
34783479
*err = result;
@@ -3590,7 +3591,7 @@ class Event : public detail::Wrapper<cl_event>
35903591
getInfo(cl_int* err = nullptr) const
35913592
{
35923593
typename detail::param_traits<
3593-
detail::cl_event_info, name>::param_type param;
3594+
detail::cl_event_info, name>::param_type param{};
35943595
cl_int result = getInfo(name, &param);
35953596
if (err != nullptr) {
35963597
*err = result;
@@ -3613,7 +3614,7 @@ class Event : public detail::Wrapper<cl_event>
36133614
getProfilingInfo(cl_int* err = nullptr) const
36143615
{
36153616
typename detail::param_traits<
3616-
detail::cl_profiling_info, name>::param_type param;
3617+
detail::cl_profiling_info, name>::param_type param{};
36173618
cl_int result = getProfilingInfo(name, &param);
36183619
if (err != nullptr) {
36193620
*err = result;
@@ -3779,7 +3780,7 @@ class Memory : public detail::Wrapper<cl_mem>
37793780
getInfo(cl_int* err = nullptr) const
37803781
{
37813782
typename detail::param_traits<
3782-
detail::cl_mem_info, name>::param_type param;
3783+
detail::cl_mem_info, name>::param_type param{};
37833784
cl_int result = getInfo(name, &param);
37843785
if (err != nullptr) {
37853786
*err = result;
@@ -4692,7 +4693,7 @@ class Image : public Memory
46924693
getImageInfo(cl_int* err = nullptr) const
46934694
{
46944695
typename detail::param_traits<
4695-
detail::cl_image_info, name>::param_type param;
4696+
detail::cl_image_info, name>::param_type param{};
46964697
cl_int result = getImageInfo(name, &param);
46974698
if (err != nullptr) {
46984699
*err = result;
@@ -5560,7 +5561,7 @@ class Pipe : public Memory
55605561
getInfo(cl_int* err = nullptr) const
55615562
{
55625563
typename detail::param_traits<
5563-
detail::cl_pipe_info, name>::param_type param;
5564+
detail::cl_pipe_info, name>::param_type param{};
55645565
cl_int result = getInfo(name, &param);
55655566
if (err != nullptr) {
55665567
*err = result;
@@ -5667,7 +5668,7 @@ class Sampler : public detail::Wrapper<cl_sampler>
56675668
getInfo(cl_int* err = nullptr) const
56685669
{
56695670
typename detail::param_traits<
5670-
detail::cl_sampler_info, name>::param_type param;
5671+
detail::cl_sampler_info, name>::param_type param{};
56715672
cl_int result = getInfo(name, &param);
56725673
if (err != nullptr) {
56735674
*err = result;
@@ -5875,7 +5876,7 @@ class Kernel : public detail::Wrapper<cl_kernel>
58755876
getInfo(cl_int* err = nullptr) const
58765877
{
58775878
typename detail::param_traits<
5878-
detail::cl_kernel_info, name>::param_type param;
5879+
detail::cl_kernel_info, name>::param_type param{};
58795880
cl_int result = getInfo(name, &param);
58805881
if (err != nullptr) {
58815882
*err = result;
@@ -5897,7 +5898,7 @@ class Kernel : public detail::Wrapper<cl_kernel>
58975898
getArgInfo(cl_uint argIndex, cl_int* err = nullptr) const
58985899
{
58995900
typename detail::param_traits<
5900-
detail::cl_kernel_arg_info, name>::param_type param;
5901+
detail::cl_kernel_arg_info, name>::param_type param{};
59015902
cl_int result = getArgInfo(argIndex, name, &param);
59025903
if (err != nullptr) {
59035904
*err = result;
@@ -5921,7 +5922,7 @@ class Kernel : public detail::Wrapper<cl_kernel>
59215922
getWorkGroupInfo(const Device& device, cl_int* err = nullptr) const
59225923
{
59235924
typename detail::param_traits<
5924-
detail::cl_kernel_work_group_info, name>::param_type param;
5925+
detail::cl_kernel_work_group_info, name>::param_type param{};
59255926
cl_int result = getWorkGroupInfo(device, name, &param);
59265927
if (err != nullptr) {
59275928
*err = result;
@@ -6755,7 +6756,7 @@ class Program : public detail::Wrapper<cl_program>
67556756
getInfo(cl_int* err = nullptr) const
67566757
{
67576758
typename detail::param_traits<
6758-
detail::cl_program_info, name>::param_type param;
6759+
detail::cl_program_info, name>::param_type param{};
67596760
cl_int result = getInfo(name, &param);
67606761
if (err != nullptr) {
67616762
*err = result;
@@ -6778,7 +6779,7 @@ class Program : public detail::Wrapper<cl_program>
67786779
getBuildInfo(const Device& device, cl_int* err = nullptr) const
67796780
{
67806781
typename detail::param_traits<
6781-
detail::cl_program_build_info, name>::param_type param;
6782+
detail::cl_program_build_info, name>::param_type param{};
67826783
cl_int result = getBuildInfo(device, name, &param);
67836784
if (err != nullptr) {
67846785
*err = result;
@@ -6811,7 +6812,7 @@ class Program : public detail::Wrapper<cl_program>
68116812

68126813
for (const cl::Device &d : devs) {
68136814
typename detail::param_traits<
6814-
detail::cl_program_build_info, name>::param_type param;
6815+
detail::cl_program_build_info, name>::param_type param{};
68156816
result = getBuildInfo(d, name, &param);
68166817
devInfo.push_back(
68176818
std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>
@@ -7598,7 +7599,7 @@ class CommandQueue : public detail::Wrapper<cl_command_queue>
75987599
getInfo(cl_int* err = nullptr) const
75997600
{
76007601
typename detail::param_traits<
7601-
detail::cl_command_queue_info, name>::param_type param;
7602+
detail::cl_command_queue_info, name>::param_type param{};
76027603
cl_int result = getInfo(name, &param);
76037604
if (err != nullptr) {
76047605
*err = result;
@@ -9269,7 +9270,7 @@ class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
92699270
getInfo(cl_int* err = nullptr) const
92709271
{
92719272
typename detail::param_traits<
9272-
detail::cl_command_queue_info, name>::param_type param;
9273+
detail::cl_command_queue_info, name>::param_type param{};
92739274
cl_int result = getInfo(name, &param);
92749275
if (err != nullptr) {
92759276
*err = result;
@@ -10765,7 +10766,7 @@ class CommandBuffer : public detail::Wrapper<cl_command_buffer_khr>
1076510766
getInfo(cl_int* err = nullptr) const
1076610767
{
1076710768
typename detail::param_traits<
10768-
detail::cl_command_buffer_info_khr, name>::param_type param;
10769+
detail::cl_command_buffer_info_khr, name>::param_type param{};
1076910770
cl_int result = getInfo(name, &param);
1077010771
if (err != nullptr) {
1077110772
*err = result;

include/getenv_util.hpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
// Copyright (c) 2022-2025 Ben Ashbaugh
3+
//
4+
// SPDX-License-Identifier: MIT
5+
*/
6+
#pragma once
7+
8+
#include <stdlib.h>
9+
#include <string.h>
10+
11+
#include <string>
12+
13+
#if defined(_WIN32)
14+
15+
#include <windows.h>
16+
17+
#define GETENV( _name, _value ) _dupenv_s( &_value, NULL, _name )
18+
#define FREEENV( _value ) free( _value )
19+
20+
#else
21+
22+
#define GETENV( _name, _value ) _value = getenv(_name)
23+
#define FREEENV( _value ) (void)_value
24+
25+
#endif
26+
27+
static inline bool getControlFromEnvironment(
28+
const char* name,
29+
void* pValue,
30+
size_t size )
31+
{
32+
char* envVal = NULL;
33+
GETENV( name, envVal );
34+
35+
if( envVal != NULL )
36+
{
37+
if( size == sizeof(unsigned int) )
38+
{
39+
unsigned int* puVal = (unsigned int*)pValue;
40+
*puVal = atoi(envVal);
41+
}
42+
else if( strlen(envVal) < size )
43+
{
44+
char* pStr = (char*)pValue;
45+
strcpy( pStr, envVal );
46+
}
47+
48+
FREEENV( envVal );
49+
return true;
50+
}
51+
52+
return false;
53+
}
54+
55+
template <class T>
56+
static bool getControl(
57+
const char* name,
58+
T& value )
59+
{
60+
unsigned int readValue = 0;
61+
bool success = getControlFromEnvironment( name, &readValue, sizeof(readValue) );
62+
if( success )
63+
{
64+
value = readValue;
65+
}
66+
67+
return success;
68+
}
69+
70+
template <>
71+
bool getControl<bool>(
72+
const char* name,
73+
bool& value )
74+
{
75+
unsigned int readValue = 0;
76+
bool success = getControlFromEnvironment( name, &readValue, sizeof(readValue) );
77+
if( success )
78+
{
79+
value = ( readValue != 0 );
80+
}
81+
82+
return success;
83+
}
84+
85+
template <>
86+
bool getControl<std::string>(
87+
const char* name,
88+
std::string& value )
89+
{
90+
char readValue[256] = "";
91+
bool success = getControlFromEnvironment( name, readValue, sizeof(readValue) );
92+
if( success )
93+
{
94+
value = readValue;
95+
}
96+
97+
return success;
98+
}

include/layer_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
// Copyright (c) 2022-2024 Ben Ashbaugh
2+
// Copyright (c) 2022-2025 Ben Ashbaugh
33
//
44
// SPDX-License-Identifier: MIT
55
*/

include/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
// Copyright (c) 2021-2024 Ben Ashbaugh
2+
// Copyright (c) 2021-2025 Ben Ashbaugh
33
//
44
// SPDX-License-Identifier: MIT
55
*/

0 commit comments

Comments
 (0)