JuliaGPU / OpenCL.jl

OpenCL Julia bindings
Other
263 stars 41 forks source link

OpenCL.jl on MacOSX Ventura 13.2 #206

Open dbl001 opened 1 year ago

dbl001 commented 1 year ago

I am getting this error: CLError(code=-1001, CL_PLATFORM_NOT_FOUND_KHR)

% julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.5 (2023-01-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using OpenCL

julia> using OpenCL_jll

julia> OpenCL_jll.libopencl_path
"/Users/davidlaxer/anaconda3/envs/pysr_test/share/julia/artifacts/03fc562e9c69fedb3693d0208ec7ac99f8b4afbc/lib/libOpenCL.1.2.dylib"

julia> OpenCL_jll.libopencl_handle
Ptr{Nothing} @0x00007ff904291f50

julia> OpenCL_jll.libopencl
"/Users/davidlaxer/anaconda3/envs/pysr_test/share/julia/artifacts/03fc562e9c69fedb3693d0208ec7ac99f8b4afbc/lib/libOpenCL.1.2.dylib"

julia> using LinearAlgebra

julia> using OpenCL

julia> const sum_kernel = "
          __kernel void sum(__global const float *a,
                            __global const float *b,
                            __global float *c)
           {
             int gid = get_global_id(0);
             c[gid] = a[gid] + b[gid];
           }
       "
"\n   __kernel void sum(__global const float *a,\n                     __global const float *b,\n                     __global float *c)\n    {\n      int gid = get_global_id(0);\n      c[gid] = a[gid] + b[gid];\n    }\n"

julia> a = rand(Float32, 50_000)
50000-element Vector{Float32}:
 0.66121256
 0.90132254
 0.35581577
 0.20901567
 0.99437934
 0.83242935
 0.48771524
 0.04769355
 0.3306896
 0.5963434
 ⋮
 0.7157939
 0.23979288
 0.88598454
 0.65537304
 0.08828026
 0.53180605
 0.94003445
 0.3585099
 0.63865054

julia> b = rand(Float32, 50_000)
50000-element Vector{Float32}:
 0.8810763
 0.54513806
 0.48156643
 0.8113872
 0.72717685
 0.7854564
 0.05076468
 0.030379891
 0.7369585
 0.2109623
 ⋮
 0.96384215
 0.7917252
 0.75217026
 0.80451506
 0.34378022
 0.6325125
 0.6717335
 0.46685314
 0.6440862

julia> device, ctx, queue = cl.create_compute_context()
ERROR: CLError(code=-1001, CL_PLATFORM_NOT_FOUND_KHR)
Stacktrace:
 [1] macro expansion
   @ ~/anaconda3/envs/pysr_test/share/julia/packages/OpenCL/BTcrM/src/macros.jl:6 [inlined]
 [2] platforms()
   @ OpenCL.cl ~/anaconda3/envs/pysr_test/share/julia/packages/OpenCL/BTcrM/src/platform.jl:43
 [3] create_some_context()
   @ OpenCL.cl ~/anaconda3/envs/pysr_test/share/julia/packages/OpenCL/BTcrM/src/context.jl:277
 [4] create_compute_context()
   @ OpenCL.cl ~/anaconda3/envs/pysr_test/share/julia/packages/OpenCL/BTcrM/src/util.jl:2
 [5] top-level scope
   @ REPL[11]:1

./clinfo
Number of platforms                               1
  Platform Name                                   Apple
  Platform Vendor                                 Apple
  Platform Version                                OpenCL 1.2 (Dec 16 2022 20:35:20)
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event

  Platform Name                                   Apple
Number of devices                                 2
  Device Name                                     Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
  Device Vendor                                   Intel
  Device Vendor ID                                0xffffffff
  Device Version                                  OpenCL 1.2 
  Driver Version                                  1.1
  Device OpenCL C Version                         OpenCL C 1.2 
  Device Type                                     CPU
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               16
  Max clock frequency                             3800MHz
  Device Partition                                (core)
    Max number of sub-devices                     0
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             1024x1x1
  Max work group size                             1024
  Preferred work group size multiple (kernel)     1
  Preferred / native vector sizes                 
    char                                                16 / 16      
    short                                                8 / 8       
    int                                                  4 / 4       
    long                                                 2 / 2       
    half                                                 0 / 0        (n/a)
    float                                                4 / 4       
    double                                               2 / 2        (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                              137438953472 (128GiB)
  Error Correction support                        No
  Max memory allocation                           34359738368 (32GiB)
  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                        64
  Global Memory cache line size                   16777216 bytes
  Image support                                   Yes
    Max number of samplers per kernel             16
    Max size for 1D images from buffer            65536 pixels
    Max 1D or 2D image array size                 2048 images
    Base address alignment for 2D image buffers   1 bytes
    Pitch alignment for 2D image buffers          1 pixels
    Max 2D image size                             8192x8192 pixels
    Max 3D image size                             2048x2048x2048 pixels
    Max number of read image args                 128
    Max number of write image args                8
  Local memory type                               Global
  Local memory size                               32768 (32KiB)
  Max number of constant args                     8
  Max constant buffer size                        65536 (64KiB)
  Max size of kernel argument                     4096 (4KiB)
  Queue properties                                
    Out-of-order execution                        No
    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                            1048576 (1024KiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event 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_byte_addressable_store cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_image2d_from_buffer cl_APPLE_fp64_basic_ops cl_APPLE_fixed_alpha_channel_orders cl_APPLE_biased_fixed_point_image_formats cl_APPLE_command_queue_priority

  Device Name                                     AMD Radeon Pro 5700 XT Compute Engine
  Device Vendor                                   AMD
  Device Vendor ID                                0x1021e00
  Device Version                                  OpenCL 1.2 
  Driver Version                                  1.2 (Jan  6 2023 19:45:55)
  Device OpenCL C Version                         OpenCL C 1.2 
  Device Type                                     GPU
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               40
  Max clock frequency                             1499MHz
  Device Partition                                (core)
    Max number of sub-devices                     0
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             256x256x256
  Max work group size                             256
  Preferred work group size multiple (kernel)     32
  Preferred / native vector sizes                 
    char                                                 4 / 4       
    short                                                2 / 2       
    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               No
    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                                    32, Little-Endian
  Global memory size                              17163091968 (15.98GiB)
  Error Correction support                        No
  Max memory allocation                           4290772992 (3.996GiB)
  Unified memory for Host and Device              No
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       32768 bits (4096 bytes)
  Global Memory cache type                        None
  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
    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                8
  Local memory type                               Local
  Local memory size                               65536 (64KiB)
  Max number of constant args                     8
  Max constant buffer size                        65536 (64KiB)
  Max size of kernel argument                     1024
  Queue properties                                
    Out-of-order execution                        No
    Profiling                                     Yes
  Prefer user sync for interop                    Yes
  Profiling timer resolution                      10ns
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
  printf() buffer size                            134217728 (128MiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event 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_depth_images cl_APPLE_command_queue_priority cl_APPLE_command_queue_select_compute_units cl_khr_fp64

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  Apple
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   Success [P0]
  clCreateContext(NULL, ...) [default]            Success [P0]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  Success (1)
    Platform Name                                 Apple
    Device Name                                   AMD Radeon Pro 5700 XT Compute Engine
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  Success (1)
    Platform Name                                 Apple
    Device Name                                   Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  Success (1)
    Platform Name                                 Apple
    Device Name                                   AMD Radeon Pro 5700 XT Compute Engine
  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)  Success (2)
    Platform Name                                 Apple
    Device Name                                   AMD Radeon Pro 5700 XT Compute Engine
    Device Name                                   Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
(base) davidlaxer@x86_64-apple-darwin13 clinfo % 
bhanukumar314 commented 1 year ago

Hello @dbl001, it seems you're having the same issue I opened in Issue #205 . I think the fix for this problem requires adding a FrameworkProduct to the OpenCL_jll library code in the case where the platform is MacOS; unfortunately at the moment I don't have time or expertise to fix it myself, but perhaps you could take a look at that issue and see if you have the knowledge to fix it?

dbl001 commented 1 year ago

The OpenCL interface in Mathematica 13.2 which uses Apple's OpenCL framework works on my 2021 iMac 27" running MacOS Ventura 13.2 with an AMD Radeon Pro 5700 XT

Screenshot 2023-02-08 at 8 36 44 AM
{"Version" -> "OpenCL 1.2 (Dec 16 2022 20:35:20)", "Name" -> "Apple", 
 "Vendor" -> "Apple", 
 "Extensions" -> {"cl_APPLE_SetMemObjectDestructor", 
   "cl_APPLE_ContextLoggingFunctions", "cl_APPLE_clut", 
   "cl_APPLE_query_kernel_names", "cl_APPLE_gl_sharing", 
   "cl_khr_gl_event"}, 
 1 -> {"Type" -> "CPU", 
   "Name" -> "Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz", 
   "Version" -> "OpenCL 1.2", 
   "Extensions" -> {"cl_APPLE_SetMemObjectDestructor", 
     "cl_APPLE_ContextLoggingFunctions", "cl_APPLE_clut", 
     "cl_APPLE_query_kernel_names", "cl_APPLE_gl_sharing", 
     "cl_khr_gl_event", "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_byte_addressable_store", "cl_khr_int64_base_atomics", 
     "cl_khr_int64_extended_atomics", "cl_khr_3d_image_writes", 
     "cl_khr_image2d_from_buffer", "cl_APPLE_fp64_basic_ops", 
     "cl_APPLE_fixed_alpha_channel_orders", 
     "cl_APPLE_biased_fixed_point_image_formats", 
     "cl_APPLE_command_queue_priority"}, "Driver Version" -> "1.1", 
   "Vendor" -> "Intel", "Profile" -> "FULL_PROFILE", 
   "Vendor ID" -> 4294967295, "Compute Units" -> 16, 
   "Core Count" -> 16, "Maximum Work Item Dimensions" -> 3, 
   "Maximum Work Item Sizes" -> {1024, 1, 1}, 
   "Maximum Work Group Size" -> 1024, 
   "Preferred Vector Width Character" -> 16, 
   "Preferred Vector Width Short" -> 8, 
   "Preferred Vector Width Integer" -> 4, 
   "Preferred Vector Width Long" -> 2, 
   "Preferred Vector Width Float" -> 4, 
   "Preferred Vector Width Double" -> 2, 
   "Maximum Clock Frequency" -> 3800, "Address Bits" -> 64, 
   "Maximum Memory Allocation Size" -> 34359738368, 
   "Image Support" -> True, "Maximum Read Image Arguments" -> 128, 
   "Maximum Write Image Arguments" -> 8, 
   "Maximum Image2D Width" -> 8192, "Maximum Image2D Height" -> 8192, 
   "Maximum Image3D Width" -> 2048, "Maximum Image3D Height" -> 2048, 
   "Maximum Image3D Depth" -> 2048, "Maximum Samplers" -> 16, 
   "Maximum Parameter Size" -> 4096, 
   "Memory Base Address Align" -> 1024, 
   "Memory Data Type Align Size" -> 128, 
   "Floating Point Precision Configuration" -> {"Denorms", "Infinity",
      "NaNs", "Round to Nearest", "Round to Infinity", 
     "Round to Zero", "IEEE754-2008 Fused MAD"}, 
   "Global Memory Cache Type" -> "Read Write", 
   "Global Memory Cache Line Size" -> 16777216, 
   "Global Memory Cache Size" -> 64, 
   "Global Memory Size" -> 137438953472, 
   "Maximum Constant Buffer Size" -> 65536, 
   "Maximum Constant Arguments" -> 8, "Local Memory Type" -> "Global",
    "Local Memory Size" -> 32768, "Error Correction Support" -> False,
    "Profiling Timer Resolution" -> 1, "Endian Little" -> True, 
   "Available" -> True, "Compiler Available" -> True, 
   "Execution Capabilities" -> {"Kernel Execution", 
     "Native Kernel Execution"}, 
   "Command Queue Properties" -> {"Profiling Enabled"}}, 
 2 -> {"Type" -> "GPU", 
   "Name" -> "AMD Radeon Pro 5700 XT Compute Engine", 
   "Version" -> "OpenCL 1.2", 
   "Extensions" -> {"cl_APPLE_SetMemObjectDestructor", 
     "cl_APPLE_ContextLoggingFunctions", "cl_APPLE_clut", 
     "cl_APPLE_query_kernel_names", "cl_APPLE_gl_sharing", 
     "cl_khr_gl_event", "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_depth_images", 
     "cl_APPLE_command_queue_priority", 
     "cl_APPLE_command_queue_select_compute_units", "cl_khr_fp64"}, 
   "Driver Version" -> "1.2 (Jan  6 2023 19:45:55)", 
   "Vendor" -> "AMD", "Profile" -> "FULL_PROFILE", 
   "Vendor ID" -> 16915968, "Compute Units" -> 40, "Core Count" -> 40,
    "Maximum Work Item Dimensions" -> 3, 
   "Maximum Work Item Sizes" -> {256, 256, 256}, 
   "Maximum Work Group Size" -> 256, 
   "Preferred Vector Width Character" -> 4, 
   "Preferred Vector Width Short" -> 2, 
   "Preferred Vector Width Integer" -> 1, 
   "Preferred Vector Width Long" -> 1, 
   "Preferred Vector Width Float" -> 1, 
   "Preferred Vector Width Double" -> 1, 
   "Maximum Clock Frequency" -> 1499, "Address Bits" -> 32, 
   "Maximum Memory Allocation Size" -> 4290772992, 
   "Image Support" -> True, "Maximum Read Image Arguments" -> 128, 
   "Maximum Write Image Arguments" -> 8, 
   "Maximum Image2D Width" -> 16384, 
   "Maximum Image2D Height" -> 16384, "Maximum Image3D Width" -> 2048,
    "Maximum Image3D Height" -> 2048, "Maximum Image3D Depth" -> 2048,
    "Maximum Samplers" -> 16, "Maximum Parameter Size" -> 1024, 
   "Memory Base Address Align" -> 32768, 
   "Memory Data Type Align Size" -> 128, 
   "Floating Point Precision Configuration" -> {"Denorms", "Infinity",
      "NaNs", "Round to Nearest", "Round to Infinity", 
     "Round to Zero"}, "Global Memory Cache Type" -> "None", 
   "Global Memory Cache Line Size" -> 0, 
   "Global Memory Cache Size" -> 0, 
   "Global Memory Size" -> 17163091968, 
   "Maximum Constant Buffer Size" -> 65536, 
   "Maximum Constant Arguments" -> 8, "Local Memory Type" -> "Local", 
   "Local Memory Size" -> 65536, "Error Correction Support" -> False, 
   "Profiling Timer Resolution" -> 10, "Endian Little" -> True, 
   "Available" -> True, "Compiler Available" -> True, 
   "Execution Capabilities" -> {"Kernel Execution"}, 
   "Command Queue Properties" -> {"Profiling Enabled"}}}