I was doing a simple test to determine the limits of OpenCL nested parallelism on an AMD RX5700XT.
Below is my code.
#define LOOP_SZ 1024
kernel void _test_loop(global float *gpu_buf, int k) {
gpu_buf[k % 256] = k;
printf("k: %d, LOOP_SZ: %d, k < LOOP_SZ, %d\n", k, LOOP_SZ, k < LOOP_SZ);
if (k < LOOP_SZ) {
queue_t q = get_default_queue();
int err = enqueue_kernel(q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
ndrange_1D(1),
^{
_test_loop(gpu_buf, k+1);
});
printf("Error: %d\n", err);
switch(err) {
case CLK_INVALID_QUEUE:
break;
case CLK_INVALID_NDRANGE:
break;
case CLK_INVALID_EVENT_WAIT_LIST:
break;
case CLK_DEVICE_QUEUE_FULL:
printf("device queue\n");
break;
case CLK_INVALID_ARG_SIZE:
break;
case CLK_EVENT_ALLOCATION_FAILURE:
break;
case CLK_OUT_OF_RESOURCES:
printf("resources\n");
break;
default:
printf("other\n");
}
}
}
kernel void test_loop(global float *gpu_buf) {
printf("k: %d\n", 0);
queue_t q = get_default_queue();
enqueue_kernel(q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
ndrange_1D(1),
^{
_test_loop(gpu_buf, 0);
});
}
I end up with a strange error code -101. I looked this up and could not find an OpenCL error code to match.
Has anyone encountered this OpenCL error code before. Does anyone know if there is a limit to nested parallelism on the RX5700XT.
Also, this code would always fail at k=127 which is why I think it is a nested parallelism depth issue as 0-127 is a binary boundary. In this case, 2^7. This would make sense if nested parallelism depth was handled using an 8-bit number where one bit was a boolean flag.
I also seem to be running into the same issue. This time it is not about nested parallelism depth but about the amount queued.
kernel void _test_loop_2(global float *gpu_buf, int k);
kernel void test_loop_2(global float *gpu_buf) {
queue_t q = get_default_queue();
for (int i = 0; i < LOOP_SZ; i++) {
_test_loop_2(gpu_buf, i);
}
}
kernel void _test_loop_2_work(global float *gpu_buf, int k) {
gpu_buf[k % 256] = k % 256;
}
kernel void _test_loop_2(global float *gpu_buf, int k) {
printf("k: %d\n", k);
queue_t q = get_default_queue();
int err = enqueue_kernel(q, CLK_ENQUEUE_FLAGS_NO_WAIT,
ndrange_1D(1),
^{
_test_loop_2_work(gpu_buf, k);
});
}
This will go through all k, but it will stop queuing kernels. I checked the queue size. Changing it led to no change in results. It will change the gpu_buf up to 127 and then stop. Adding a printf for err will show that at 128 through the end, it starts to error with the same -101 error code. This seems strange to me. My only thoughts is that this is related to a limit on the number of nested kernels that can be launch (not their depth). I have not found AMD documentation on this. Even so, 128 kernels seems too small a limit for nested parallelism.
Hi @acminor ,
Thank you for reporting it. Please provide your setup details such as OS, driver version etc. and attach the clinfo output.
Please also share the host-side code that was used to call the kernel.
Thanks.
According to clinfo, I am running the 3180.7 (PAL, LC) OpenCL driver (Platform version: OpenCL 2.1 AMD-APP (3180.7).
I am unsure if I am using a specific AMDGPU driver or the builtin kernel driver. I know that I installed the OpenCL components which is why I list that clinfo version.
I am running Ubuntu 20.04.1 with Linux kernel 5.6.15-050615-generic (which I believe is not the default Linux kernel).
If you need more information, let me know.
Number of platforms 2
Platform Name AMD Accelerated Parallel Processing
Platform Vendor Advanced Micro Devices, Inc.
Platform Version OpenCL 2.1 AMD-APP (3180.7)
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd cl_amd_event_callback cl_amd_offline_devices
Platform Host timer resolution 1ns
Platform Extensions function suffix AMD
Platform Name Portable Computing Language
Platform Vendor The pocl project
Platform Version OpenCL 1.2 pocl 1.4, None+Asserts, LLVM 9.0.1, RELOC, SLEEF, DISTRO, POCL_DEBUG
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd
Platform Extensions function suffix POCL
Platform Name AMD Accelerated Parallel Processing
Number of devices 1
Device Name gfx1010
Device Vendor Advanced Micro Devices, Inc.
Device Vendor ID 0x1002
Device Version OpenCL 2.0 AMD-APP (3180.7)
Driver Version 3180.7 (PAL,LC)
Device OpenCL C Version OpenCL C 2.0
Device Type GPU
Device Board Name (AMD) AMD Radeon RX 5700 XT
Device Topology (AMD) PCI-E, 2f:00.0
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Linker Available Yes
Max compute units 20
SIMD per compute unit (AMD) 4
SIMD width (AMD) 32
SIMD instruction width (AMD) 1
Max clock frequency 2100MHz
Graphics IP (AMD) 10.10
Device Partition (core)
Max number of sub-devices 20
Supported partition types None
Supported affinity domains (n/a)
Max work item dimensions 3
Max work item sizes 1024x1024x1024
Max work group size 256
Preferred work group size (AMD) 256
Max work group size (AMD) 1024
Preferred work group size multiple 32
Wavefront width (AMD) 32
Preferred / native vector sizes
char 4 / 4
short 2 / 2
int 1 / 1
long 1 / 1
half 1 / 1 (cl_khr_fp16)
float 1 / 1
double 1 / 1 (cl_khr_fp64)
Half-precision Floating-point support (cl_khr_fp16)
Denormals No
Infinity and NANs No
Round to nearest No
Round to zero No
Round to infinity No
IEEE754-2008 fused multiply-add No
Support is emulated in software No
Single-precision Floating-point support (core)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Correctly-rounded divide and sqrt operations Yes
Double-precision Floating-point support (cl_khr_fp64)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Address bits 64, Little-Endian
Global memory size 8573157376 (7.984GiB)
Global free memory (AMD) 8306688 (7.922GiB)
Global memory channels (AMD) 8
Global memory banks per channel (AMD) 4
Global memory bank width (AMD) 256 bytes
Error Correction support No
Max memory allocation 7059013632 (6.574GiB)
Unified memory for Host and Device No
Shared Virtual Memory (SVM) capabilities (core)
Coarse-grained buffer sharing Yes
Fine-grained buffer sharing Yes
Fine-grained system sharing No
Atomics No
Minimum alignment for any data type 128 bytes
Alignment of base address 2048 bits (256 bytes)
Preferred alignment for atomics
SVM 0 bytes
Global 0 bytes
Local 0 bytes
Max size for global variable 6353112064 (5.917GiB)
Preferred total size of global vars 8573157376 (7.984GiB)
Global Memory cache type Read/Write
Global Memory cache size 16384 (16KiB)
Global Memory cache line size 64 bytes
Image support Yes
Max number of samplers per kernel 16
Max size for 1D images from buffer 134217728 pixels
Max 1D or 2D image array size 2048 images
Base address alignment for 2D image buffers 256 bytes
Pitch alignment for 2D image buffers 256 pixels
Max 2D image size 16384x16384 pixels
Max 3D image size 2048x2048x2048 pixels
Max number of read image args 128
Max number of write image args 64
Max number of read/write image args 64
Max number of pipe args 16
Max active pipe reservations 16
Max pipe packet size 2764046336 (2.574GiB)
Local memory type Local
Local memory size 65536 (64KiB)
Local memory syze per CU (AMD) 65536 (64KiB)
Local memory banks (AMD) 32
Max number of constant args 8
Max constant buffer size 7059013632 (6.574GiB)
Preferred constant buffer size (AMD) 16384 (16KiB)
Max size of kernel argument 1024
Queue properties (on host)
Out-of-order execution No
Profiling Yes
Queue properties (on device)
Out-of-order execution Yes
Profiling Yes
Preferred size 262144 (256KiB)
Max size 8388608 (8MiB)
Max queues on device 1
Max events on device 1024
Prefer user sync for interop Yes
Number of P2P devices (AMD) 0
P2P devices (AMD) <printDeviceInfo:147: get number of CL_DEVICE_P2P_DEVICES_AMD : error -30>
Profiling timer resolution 1ns
Profiling timer offset since Epoch (AMD) 1613489455036584008ns (Tue Feb 16 09:30:55 2021)
Execution capabilities
Run OpenCL kernels Yes
Run native kernels No
Thread trace supported (AMD) Yes
Number of async queues (AMD) 4
Max real-time compute queues (AMD) 1
Max real-time compute units (AMD) 0
printf() buffer size 4194304 (4MiB)
Built-in kernels (n/a)
Device Extensions cl_khr_fp64 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_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_khr_gl_depth_images cl_amd_device_attribute_query cl_amd_media_ops cl_amd_media_ops2 cl_khr_image2d_from_buffer cl_khr_subgroups cl_khr_gl_event cl_khr_depth_images cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_amd_copy_buffer_p2p
Platform Name Portable Computing Language
Number of devices 1
Device Name pthread-AMD Ryzen 5 3600 6-Core Processor
Device Vendor AuthenticAMD
Device Vendor ID 0x6c636f70
Device Version OpenCL 1.2 pocl HSTR: pthread-x86_64-pc-linux-gnu-znver1
Driver Version 1.4
Device OpenCL C Version OpenCL C 1.2 pocl
Device Type CPU
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Linker Available Yes
Max compute units 12
Max clock frequency 3600MHz
Device Partition (core)
Max number of sub-devices 12
Supported partition types equally, by counts
Supported affinity domains (n/a)
Max work item dimensions 3
Max work item sizes 4096x4096x4096
Max work group size 4096
Preferred work group size multiple 8
Preferred / native vector sizes
char 16 / 16
short 16 / 16
int 8 / 8
long 4 / 4
half 0 / 0 (n/a)
float 8 / 8
double 4 / 4 (cl_khr_fp64)
Half-precision Floating-point support (n/a)
Single-precision Floating-point support (core)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Correctly-rounded divide and sqrt operations Yes
Double-precision Floating-point support (cl_khr_fp64)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Address bits 64, Little-Endian
Global memory size 31542484992 (29.38GiB)
Error Correction support No
Max memory allocation 8589934592 (8GiB)
Unified memory for Host and Device Yes
Minimum alignment for any data type 128 bytes
Alignment of base address 1024 bits (128 bytes)
Global Memory cache type Read/Write
Global Memory cache size 16777216 (16MiB)
Global Memory cache line size 64 bytes
Image support Yes
Max number of samplers per kernel 16
Max size for 1D images from buffer 536870912 pixels
Max 1D or 2D image array size 2048 images
Max 2D image size 16384x16384 pixels
Max 3D image size 2048x2048x2048 pixels
Max number of read image args 128
Max number of write image args 128
Local memory type Global
Local memory size 8388608 (8MiB)
Max number of constant args 8
Max constant buffer size 8388608 (8MiB)
Max size of kernel argument 1024
Queue properties
Out-of-order execution Yes
Profiling Yes
Prefer user sync for interop Yes
Profiling timer resolution 1ns
Execution capabilities
Run OpenCL kernels Yes
Run native kernels Yes
printf() buffer size 16777216 (16MiB)
Built-in kernels (n/a)
Device Extensions cl_khr_byte_addressable_store 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_3d_image_writes cl_khr_fp64 cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp64
NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) No platform
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) No platform
clCreateContext(NULL, ...) [default] No platform
clCreateContext(NULL, ...) [other] Success [AMD]
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) Success (1)
Platform Name AMD Accelerated Parallel Processing
Device Name gfx1010
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) Success (1)
Platform Name AMD Accelerated Parallel Processing
Device Name gfx1010
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) Success (1)
Platform Name AMD Accelerated Parallel Processing
Device Name gfx1010
Thank you for the above information. Could you please also provide the host-side code?
Snippet for the opencl_base.h I used in programming the example.
https://gitlab.com/-/snippets/2078483
Snippet for the actual host code (some stuff commented out because it related to other kernels I was testing). If it does not compile, it will probably be because I commented out a variable.
https://gitlab.com/-/snippets/2078485
The OpenCL kernels are above. See the comment in the code about switching out the two different kernels.
The directory structure of the original code:
- dir
-- opencl_base.h
-- dir
--- test1.c
It was compiled with "clang -lOpenCL test1.c". (Clang version 10.0.0-4ubuntu1).
Thank you for sharing the source files. We'll look into this and get back to you shortly.
Could you please try the below and let me know your observations?
1. When checking the error code for enqueue_kernel, check for CLK_ENQUEUE_FAILURE which represents the generic error code.
Please note: enqueue_kernel may not provide any extra error information when "-g" compilation option is used. As per the spec, it's an optional feature, not a requirement. Hence, implementation may ignore it. You may find a similar discussion here: https://community.amd.com/t5/opencl/device-queue-is-not-blocking-if-it-is-full-some-child-kernels/td...
2. When creating the device queue, set the queue size (in "cl_queue_properties") to its maximum limit (as per the above clinfo, the max. limit is 8388608 byte or 8MB).
(P.S. I also observed an error when queue size was set as the "preferred size". When I increased its value to the max. limit, the code ran successfully.)
Thanks.