cogciprocate / ocl

OpenCL for Rust
Other
721 stars 75 forks source link

The large global_id confuses me #226

Closed lpcy closed 9 months ago

lpcy commented 9 months ago

I used code similar to this project example, and set ProQue::builder().dims(10000000000). I found Some global_id will be processed twice, some global_id was not processed. I have discovered a possible boundary point: 2147483648 (2^31). So in opencl, I print global_id:

    size_t gid = get_global_id(0);
    if(gid == 2147483647 || gid == 2147483648){
        printf("gid:%ld\n",gid);
    }

Finally, these were printed: gid:2147483647 gid:2147483647 I am not sure why this situation occurred and how to avoid it. I am using NVIDIA GeForce MX150 and Windows 10 OS.

c0gent commented 9 months ago

Not specific to this library but that is the maximum positive value of a 32 bit signed integer, which is the size used for kernel dimensions on your platform. Try using multiple dimensions such as: ProQue::builder().dims((100000,100000)) and adjust your kernel accordingly. In your kernel you'd use get_global_id(0) to get the first and get_global_id(1) to get the second dimension.

Hope that helps.

lpcy commented 9 months ago

Not specific to this library but that is the maximum positive value of a 32 bit signed integer, which is the size used for kernel dimensions on your platform. Try using multiple dimensions such as: ProQue::builder().dims((100000,100000)) and adjust your kernel accordingly. In your kernel you'd use get_global_id(0) to get the first and get_global_id(1) to get the second dimension.

Hope that helps.

Thank you for your reply. Where can I obtain or calculate this value to determine the maximum support of only 32 bits?

c0gent commented 9 months ago

To be honest I'm not really sure. It's probably correlated with the AddressBits (CL_DEVICE_ADDRESS_BITS) parameter from DeviceInfo (cl_get_device_info) but I can't remember exactly. You can run clinfo or the the info_core example in this project (cargo run --example info_core) to view the AddressBits parameter.

c0gent commented 9 months ago

Let me know what yours lists.

lpcy commented 9 months ago

Let me know what yours lists.


Number of platforms                               2
Platform Name                                   NVIDIA CUDA
Platform Vendor                                 NVIDIA Corporation
Platform Version                                OpenCL 3.0 CUDA 12.3.99
Platform Profile                                FULL_PROFILE
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_fp64 cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid cl_khr_pci_bus_info cl_khr_external_semaphore cl_khr_external_memory cl_khr_external_semaphore_win32 cl_khr_external_memory_win32
Platform Extensions with Version                cl_khr_global_int32_base_atomics                                 0x400000 (1.0.0)
cl_khr_global_int32_extended_atomics                             0x400000 (1.0.0)
cl_khr_local_int32_base_atomics                                  0x400000 (1.0.0)
cl_khr_local_int32_extended_atomics                              0x400000 (1.0.0)
cl_khr_fp64                                                      0x400000 (1.0.0)
cl_khr_3d_image_writes                                           0x400000 (1.0.0)
cl_khr_byte_addressable_store                                    0x400000 (1.0.0)
cl_khr_icd                                                       0x400000 (1.0.0)
cl_khr_gl_sharing                                                0x400000 (1.0.0)
cl_nv_compiler_options                                           0x400000 (1.0.0)
cl_nv_device_attribute_query                                     0x400000 (1.0.0)
cl_nv_pragma_unroll                                              0x400000 (1.0.0)
cl_nv_d3d10_sharing                                              0x400000 (1.0.0)
cl_khr_d3d10_sharing                                             0x400000 (1.0.0)
cl_nv_d3d11_sharing                                              0x400000 (1.0.0)
cl_nv_copy_opts                                                  0x400000 (1.0.0)
cl_nv_create_buffer                                              0x400000 (1.0.0)
cl_khr_int64_base_atomics                                        0x400000 (1.0.0)
cl_khr_int64_extended_atomics                                    0x400000 (1.0.0)
cl_khr_device_uuid                                               0x400000 (1.0.0)
cl_khr_pci_bus_info                                              0x400000 (1.0.0)
cl_khr_external_semaphore                                          0x9000 (0.9.0)
cl_khr_external_memory                                             0x9000 (0.9.0)
cl_khr_external_semaphore_win32                                    0x9000 (0.9.0)
cl_khr_external_memory_win32                                       0x9000 (0.9.0)
Platform Numeric Version                        0xc00000 (3.0.0)
Platform Extensions function suffix             NV
Platform Host timer resolution                  0ns
Platform External memory handle types           Opaqe Win32, Opaque Win32 KMT
Platform External semaphore import types        Opaque Win32, Opaque Win32 KMT
Platform External semaphore export types        Opaque Win32, Opaque Win32 KMT

Platform Name Intel(R) OpenCL Platform Vendor ......

Platform Name NVIDIA CUDA Number of devices 1 Device Name NVIDIA GeForce MX150 Device Vendor NVIDIA Corporation Device Vendor ID 0x10de Device Version OpenCL 3.0 CUDA Device UUID 62600c5b-dfa8-6d14-1aac-3dc6e0cb4d11 Driver UUID 62600c5b-dfa8-6d14-1aac-3dc6e0cb4d11 Valid Device LUID Yes Device LUID 6c1a-e60400000000 Device Node Mask 0x1 Device Numeric Version 0xc00000 (3.0.0) Driver Version 546.17 Device OpenCL C Version OpenCL C 1.2 Device OpenCL C all versions OpenCL C 0x400000 (1.0.0) OpenCL C 0x401000 (1.1.0) OpenCL C 0x402000 (1.2.0) OpenCL C 0xc00000 (3.0.0) Device OpenCL C features opencl_c_fp64 0xc00000 (3.0.0) opencl_c_images 0xc00000 (3.0.0) opencl_c_int64 0xc00000 (3.0.0) opencl_c_3d_image_writes 0xc00000 (3.0.0) Latest conformance test passed v2022-10-05-00 Device Type GPU Device Topology (NV) PCI-E, 0000:01:00.0 Device PCI bus info (KHR) PCI-E, 0000:01:00.0 Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 3 Max clock frequency 1037MHz Compute Capability (NV) 6.1 Device Partition (core) Max number of sub-devices 1 Supported partition types None Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 1024x1024x64 Max work group size 1024 Preferred work group size multiple (device) 32 Preferred work group size multiple (kernel) 32 Warp size (NV) 32 Max sub-groups per work group 0 Preferred / native vector sizes char 1 / 1 short 1 / 1 int 1 / 1 long 1 / 1 half 0 / 0 (n/a) float 1 / 1 double 1 / 1 (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 External memory handle types Opaqe Win32, Opaque Win32 KMT External semaphore import types Opaque Win32, Opaque Win32 KMT External semaphore export types Opaque Win32, Opaque Win32 KMT Global memory size 2147352576 (2GiB) Error Correction support No Max memory allocation 536838144 (512MiB) Unified memory for Host and Device No Integrated memory (NV) No Shared Virtual Memory (SVM) capabilities (core) Coarse-grained buffer sharing Yes Fine-grained buffer sharing No Fine-grained system sharing No Atomics No Minimum alignment for any data type 128 bytes Alignment of base address 4096 bits (512 bytes) Preferred alignment for atomics SVM 0 bytes Global 0 bytes Local 0 bytes Atomic memory capabilities relaxed, work-group scope Atomic fence capabilities relaxed, acquire/release, work-group scope Max size for global variable 0 Preferred total size of global vars 0 Global Memory cache type Read/Write Global Memory cache size 147456 (144KiB) Global Memory cache line size 128 bytes Image support Yes Max number of samplers per kernel 32 Max size for 1D images from buffer 268435456 pixels Max 1D or 2D image array size 2048 images Base address alignment for 2D image buffers 0 bytes Pitch alignment for 2D image buffers 0 pixels Max 2D image size 16384x32768 pixels Max 3D image size 16384x16384x16384 pixels Max number of read image args 256 Max number of write image args 16 Max number of read/write image args 0 Pipe support No Max number of pipe args 0 Max active pipe reservations 0 Max pipe packet size 0 Local memory type Local Local memory size 49152 (48KiB) Registers per block (NV) 65536 Max number of constant args 9 Max constant buffer size 65536 (64KiB) Generic address space support No Max size of kernel argument 4352 (4.25KiB) Queue properties (on host) Out-of-order execution Yes Profiling Yes Device enqueue capabilities (n/a) Queue properties (on device) Out-of-order execution No Profiling No Preferred size 0 Max size 0 Max queues on device 0 Max events on device 0 Prefer user sync for interop No Profiling timer resolution 1000ns Execution capabilities Run OpenCL kernels Yes Run native kernels No Non-uniform work-groups No Work-group collective functions No Sub-group independent forward progress No Kernel execution timeout (NV) Yes Concurrent copy and kernel execution (NV) Yes Number of async copy engines 5 IL version (n/a) ILs with version (n/a) printf() buffer size 1048576 (1024KiB) Built-in kernels (n/a) Built-in kernels with version (n/a) 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_fp64 cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid cl_khr_pci_bus_info cl_khr_external_semaphore cl_khr_external_memory cl_khr_external_semaphore_win32 cl_khr_external_memory_win32 Device Extensions with Version cl_khr_global_int32_base_atomics 0x400000 (1.0.0) cl_khr_global_int32_extended_atomics 0x400000 (1.0.0) cl_khr_local_int32_base_atomics 0x400000 (1.0.0) cl_khr_local_int32_extended_atomics 0x400000 (1.0.0) cl_khr_fp64 0x400000 (1.0.0) cl_khr_3d_image_writes 0x400000 (1.0.0) cl_khr_byte_addressable_store 0x400000 (1.0.0) cl_khr_icd 0x400000 (1.0.0) cl_khr_gl_sharing 0x400000 (1.0.0) cl_nv_compiler_options 0x400000 (1.0.0) cl_nv_device_attribute_query 0x400000 (1.0.0) cl_nv_pragma_unroll 0x400000 (1.0.0) cl_nv_d3d10_sharing 0x400000 (1.0.0) cl_khr_d3d10_sharing 0x400000 (1.0.0) cl_nv_d3d11_sharing 0x400000 (1.0.0) cl_nv_copy_opts 0x400000 (1.0.0) cl_nv_create_buffer 0x400000 (1.0.0) cl_khr_int64_base_atomics 0x400000 (1.0.0) cl_khr_int64_extended_atomics 0x400000 (1.0.0) cl_khr_device_uuid 0x400000 (1.0.0) cl_khr_pci_bus_info 0x400000 (1.0.0) cl_khr_external_semaphore 0x9000 (0.9.0) cl_khr_external_memory 0x9000 (0.9.0) cl_khr_external_semaphore_win32 0x9000 (0.9.0) cl_khr_external_memory_win32 0x9000 (0.9.0)

Platform Name Intel(R) OpenCL Number of devices 2 ....

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 [NV] clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) No platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) No platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) Invalid device type for platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) No platform

nishuzumi commented 5 months ago

Same, I think there has some problem when compile