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

ManagedCuda exception #35

Open
Marcoozvn opened this issue Dec 10, 2023 · 1 comment
Open

ManagedCuda exception #35

Marcoozvn opened this issue Dec 10, 2023 · 1 comment

Comments

@Marcoozvn
Copy link

Marcoozvn commented Dec 10, 2023

Hello, could you help me with this exception?

ManagedCuda.CudaException: 'ErrorInvalidHandle: This indicates that a resource handle passed to the API call was not valid. Resource handles are opaque types like CUstream and CUevent.'

It was raised here:
public float RunSafe(NPPImage_32fC1 imgIn, NPPImage_32fC3 imgOut, float3 blackPoint, float3 scale)

I'm running using a NVIDIA RTX A3000 GPU with 6GB of memory.

@kunzmi
Copy link
Owner

kunzmi commented Dec 11, 2023

Hi,

this sounds again like the context creation error we had already in some other issue, I just don't find it right now. The problem is that newer Cuda versions than the one I use in this old project create a PrimaryContext for the Cuda libraries like NPP and CUFFT.
So the trick is to also use a PrimaryContext and not a standard context with ImageStackAligntor.
Try to modify line 203 of ImagePresenterDX.xaml.cs from

_ctx = new CudaContext(cudaDevices[0], _device.ComPointer, CUCtxFlags.BlockingSync, CudaContext.DirectXVersion.D3D9);

to

_ctx = new PrimaryContext(0); //choose what ever deviceID you need, this old managedCuda version does not allow to create primary context from CUdevice
_ctx.SetCurrent();

Doing so, NPP will run on the same context as the normal Cuda code and the error message should disappear.

Cheers,
Michael

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