Skip to content

badnikhil/bindbc-cuda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bindbc-cuda

DUB Package License

Static and dynamic D bindings for the NVIDIA CUDA Driver API, compatible with @nogc, nothrow, and -betterC.

Features

  • Dynamic loading — Load nvcuda.dll / libcuda.so at runtime via bindbc-loader.
  • Static linking — Link against the CUDA driver library at compile time.
  • BetterC compatible — Zero D runtime dependency.
  • Versioned symbols — Binds to the modern _v2 Driver API entry points.
  • Multi-version support — Covers CUDA 10.0 through 12.4.

Adding to your project

dub.json

"dependencies": {
    "bindbc-cuda": "~>1.0"
}

dub.sdl

dependency "bindbc-cuda" version="~>1.0"

Selecting a CUDA version

Pass the appropriate version identifier to target a specific CUDA release:

"versions": ["CUDA_120"]

The default (no version set) targets CUDA 10.0.

Static binding

To link against the CUDA driver library at compile time instead of loading it dynamically at runtime:

"subConfigurations": {
    "bindbc-cuda": "static"
}

Configurations

Configuration Description
dynamic Dynamic binding via bindbc-loader (default)
dynamicBC Dynamic binding with -betterC
static Static (link-time) binding
staticBC Static binding with -betterC

Usage

import bindbc.cuda;

void main() {
    auto ret = loadCUDA();

    if(ret == CUDASupport.noLibrary) {
        // CUDA driver library not found on this system.
        return;
    }
    if(ret == CUDASupport.badLibrary) {
        // Library found but one or more symbols failed to bind.
        return;
    }

    // Driver API is ready.
    cuInit(0);

    int count;
    cuDeviceGetCount(&count);

    CUdevice dev;
    cuDeviceGet(&dev, 0);

    char[256] name;
    cuDeviceGetName(name.ptr, cast(int)name.length, dev);
}

Folder structure

bindbc-cuda/
├── dub.json
├── README.md
└── source/
    └── bindbc/
        └── cuda/
            ├── package.d       — Public import aggregator
            ├── config.d        — Version selection, staticBinding flag
            ├── types.d         — Opaque handles, enums, flags
            └── binddynamic.d   — Dynamic symbol loading via bindbc-loader

License

Distributed under the Boost Software License, Version 1.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages