kunzmi / managedCuda

ManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.
Other
449 stars 80 forks source link

Wrap cuDeviceGetCount() #4

Closed keldor314 closed 8 years ago

keldor314 commented 8 years ago

cuDeviceGetCount() is rather important for creating contexts when you want to support multiple devices. You have no idea how many GPUs your user has plugged in! Using the method from DriverAPINativeMethods is of course clunky, since you're going to then have to deal with cuInit() most of the time.

Is there any chance of adding a proper DeviceGetCount() function to the managed API?

From:

 static member Contexts =
    let devCount = ref 0
    DriverAPINativeMethods.cuInit(CUInitializationFlags.None) |> ignore
    DriverAPINativeMethods.DeviceManagement.cuDeviceGetCount(devCount) |> ignore
    //Error handling??!
    [|
        for n in [0..!devCount-1] do
            yield new CudaContext (n)
    |]

To:

static member Contexts =
    [|
        for n in [0..DeviceGetCount()-1] do
            yield new CudaContext (n)
    |]
kunzmi commented 8 years ago

The CudaContext class has a static method GetDeviceCount() that does exactly what you want to have^^

keldor314 commented 8 years ago

It does? I guess I overlooked it. Neat!