Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why cuD3D11GetDevice success, but still got a 0 device? #124

Open
GF-Huang opened this issue Feb 19, 2024 · 3 comments
Open

Why cuD3D11GetDevice success, but still got a 0 device? #124

GF-Huang opened this issue Feb 19, 2024 · 3 comments

Comments

@GF-Huang
Copy link

image

@kunzmi
Copy link
Owner

kunzmi commented Feb 19, 2024

0 is a perfectly valid device value, they are more or less equal to the device ID.
(In very old Cuda versions, the value used to be a 32-bit pointer, hence the name in the structure, but in current versions, the value mostly corresponds to the device ID)

Michael

@GF-Huang
Copy link
Author

But the Pointer is zero as an IntPtr which used for other 3rd library, is it really OK?

For example MarshalInterface<IDirect3DDevice>.FromAbi(device.Pointer) will return null.

@kunzmi
Copy link
Owner

kunzmi commented Feb 19, 2024

CUdevice.Pointer is just an int, not an IntPtr. CUdevice is also a Cuda specific type and is not supposed to be used outside of the Cuda API. Your example with MarshalInterface<IDirect3DDevice>.FromAbi(device.Pointer) can't work with a Cuda-API provided value, it will only work with adapter.NativePointer.

In the orginal C++ header CUdevice is defined as following:

typedef int CUdevice_v1;                                     /**< CUDA device */
typedef CUdevice_v1 CUdevice;                                /**< CUDA device */

As C# does not have something like a typedef in C++, I use structs to define the custom type. At the end it is just an int. Hope that clarifies things.

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

No branches or pull requests

2 participants