Skip to content

Expose OpenCL platform and device information - #2112

Merged
shimat merged 1 commit into
mainfrom
feature/ocl-device-info
Aug 6, 2026
Merged

Expose OpenCL platform and device information#2112
shimat merged 1 commit into
mainfrom
feature/ocl-device-info

Conversation

@shimat

@shimat shimat commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • expose Cv2.Ocl.GetPlatformsInfo() as read-only platform and device snapshots
  • add OclPlatformInfo, OclDeviceInfo, and OclDeviceTypes
  • keep native OpenCL handles internal and return an empty list when OpenCL is unavailable
  • add coverage for platform and device snapshot retrieval

Follow-up to #2111.

Validation

  • cmake --build src\build --config Release --target OpenCvSharpExtern
  • dotnet build src\OpenCvSharp\OpenCvSharp.csproj -c Release --no-restore
  • dotnet test test\OpenCvSharp.Tests\OpenCvSharp.Tests.csproj -c Release --no-restore --filter "FullyQualifiedName~OpenCvSharp.Tests.Core.OclTest" (3 passed)
  • git diff --check

Summary by CodeRabbit

  • New Features
    • Added OpenCL platform discovery with read-only platform and device information.
    • Exposes platform metadata, device types, versions, availability, compute capabilities, and memory details.
    • Added device type classifications, including CPU, GPU, accelerator, and integrated or discrete GPU.
    • Gracefully returns an empty result when OpenCL is unavailable.

@shimat shimat added the enhancement New feature or improvement to OpenCvSharp label Aug 6, 2026
@shimat shimat self-assigned this Aug 6, 2026
@shimat
shimat marked this pull request as ready for review August 6, 2026 13:50
@shimat
shimat merged commit a390f59 into main Aug 6, 2026
16 of 17 checks passed
@shimat
shimat deleted the feature/ocl-device-info branch August 6, 2026 13:50
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bdf6f7d-21a2-4137-acc9-032a33ec95ff

📥 Commits

Reviewing files that changed from the base of the PR and between 2deb9fc and 8b57532.

📒 Files selected for processing (6)
  • src/OpenCvSharp/Internal/PInvoke/NativeMethods/core/NativeMethods_core_Ocl.cs
  • src/OpenCvSharp/Modules/core/Cv2.Ocl.cs
  • src/OpenCvSharp/Modules/core/Enum/OclDeviceTypes.cs
  • src/OpenCvSharp/Modules/core/OclPlatformInfo.cs
  • src/OpenCvSharpExtern/core_ocl.h
  • test/OpenCvSharp.Tests/core/OclTest.cs

📝 Walkthrough

Walkthrough

This PR adds OpenCL platform and device enumeration to the managed API. It introduces immutable snapshot types, native wrappers, P/Invoke declarations, managed conversion logic, and a test for available and unavailable OpenCL runtimes.

Changes

OpenCL platform snapshot enumeration

Layer / File(s) Summary
Managed snapshot contracts
src/OpenCvSharp/Modules/core/Enum/OclDeviceTypes.cs, src/OpenCvSharp/Modules/core/OclPlatformInfo.cs
Adds the public OclDeviceTypes flags enum and the immutable OclPlatformInfo and OclDeviceInfo records for platform and device snapshots.
Native enumeration bridge
src/OpenCvSharpExtern/core_ocl.h, src/OpenCvSharp/Internal/PInvoke/NativeMethods/core/NativeMethods_core_Ocl.cs
Adds native wrappers and P/Invoke declarations to allocate a platform-info vector, read platform and device fields by index, get vector size, and release the vector.
Managed enumeration API and validation
src/OpenCvSharp/Modules/core/Cv2.Ocl.cs, test/OpenCvSharp.Tests/core/OclTest.cs
Adds Cv2.Ocl.GetPlatformsInfo, converts native platform and device data into managed records, returns an empty result when OpenCL is unavailable, disposes the native vector, and validates the snapshots in a test.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Cv2.Ocl
  participant NativeMethods
  participant OpenCvSharpExtern
  participant OpenCV OCL

  Caller->>Cv2.Ocl: GetPlatformsInfo()
  alt OpenCL unavailable
    Cv2.Ocl-->>Caller: empty result
  else OpenCL available
    Cv2.Ocl->>NativeMethods: core_ocl_getPlatformsInfo()
    NativeMethods->>OpenCvSharpExtern: get native platform vector
    OpenCvSharpExtern->>OpenCV OCL: query platforms and devices
    OpenCV OCL-->>OpenCvSharpExtern: platform/device metadata
    OpenCvSharpExtern-->>NativeMethods: vector handle and indexed fields
    NativeMethods-->>Cv2.Ocl: native values
    Cv2.Ocl->>NativeMethods: vector size and indexed reads
    Cv2.Ocl->>Cv2.Ocl: build OclPlatformInfo and OclDeviceInfo
    Cv2.Ocl->>NativeMethods: core_ocl_PlatformInfoVector_delete()
    Cv2.Ocl-->>Caller: IReadOnlyList<OclPlatformInfo>
  end
Loading

Possibly related PRs

  • shimat/opencvsharp#2111: It changes the same OpenCL interop surface and Cv2.Ocl area, with related native and managed wiring.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ocl-device-info

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to OpenCvSharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant