Skip to content

Migrate CUDA Driver Backend from Derelict to BindBC#96

Open
badnikhil wants to merge 6 commits into
libmir:masterfrom
badnikhil:migrate_to_bindbc
Open

Migrate CUDA Driver Backend from Derelict to BindBC#96
badnikhil wants to merge 6 commits into
libmir:masterfrom
badnikhil:migrate_to_bindbc

Conversation

@badnikhil
Copy link
Copy Markdown
Contributor

@badnikhil badnikhil commented May 13, 2026

This PR replaces the CUDA driver backend derelict-cuda with the type-safe, dynamically-loaded bindbc-cuda binding.

Major Changes

  • Dependency Upgrade:
    Replaced derelict-cuda with bindbc-cuda in dub.json and implemented library loading using loadCUDA() in Platform.initialise().
  • Type Safety :
    Replaced internal generic void* handle fields in driver wrapper structs (Context, Event, Kernel, Program, Queue) with their corresponding strongly-typed BindBC types (e.g. CUcontext, CUstream).
  • Memory Prefetching :
    Fully implemented the previously stubbed UnifiedBuffer!T.prefetch() method using cuMemPrefetchAsync, enabled by the upgraded binding capability.
  • API Corrections:
    Fixed a bug in Context where cuCtxSetLimit was erroneously used instead of cuCtxGetLimit during property querying.
    Added explicit casts to CUdevice_attribute inside Device attribute queries to satisfy strict type checks.

{
// Stub — intentionally left empty.
// See module documentation for rationale.
status = cast(Status)cuMemPrefetchAsync(cast(CUdeviceptr)raw, _length * T.sizeof, dev.raw, q.raw);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what version of the driver/runtime is this defined? or more accurately, not defined? does it makes sense to rewrite this to check if (cuMemPrefetchAsync) first?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.. Unified Memory came out in CUDA 6 and prefetch APIs were introduced in CUDA 8.0.. i'll update that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants