What is a CUDA context?
Asked Answered
O

2

28

Can anyone please explain or refer me some good source about what is a CUDA context? I searched CUDA developer guide and I was not satisfied with it.

Any explanation or help will be great.

Obloquy answered 6/4, 2017 at 2:28 Comment(3)
There is no public information on the contents of a cuda context which is, by its nature, subject to change to include new features. I don't see any better way to describe it, nor do I understand what is missing, and what you did expect.Unemployed
Is there a similar concept in any other open source library that I can check out?Obloquy
I would consider the opencl context quite similar indeed. khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/…. To my knowledge, open source implementation of opencl exist.Unemployed
U
26

The cuda API exposes features of a stateful library: two consecutive calls relate one-another. In short, the context is its state.

The runtime API is a wrapper/helper of the driver API. You can see in the driver API that the context is explicitly made available, and you can have a stack of contexts for convenience. There is one specific context which is shared between driver and runtime API (See primary context)).

The context holds all the management data to control and use the device. For instance, it holds the list of allocated memory, the loaded modules that contain device code, the mapping between CPU and GPU memory for zero copy, etc.

Finally, note that this post is more from experience than documentation-proofed.

Unemployed answered 6/4, 2017 at 9:36 Comment(2)
Both the answers are enlightening. But I am still not satisfied. Can you describe it in more detail?Obloquy
What confuses me is that the driver API has cuCtxSynchronize which synchronizes the context (I guess the primary context) without making explicit the context nor even the device (which device? I guess all devices.)Oiler
R
4

essentially, a data structure that holds information relevant to mantaining a consistent state between the calls that you make, e.g. (open) (execute) (close)

This is so that the functions that you invoke can send the signals in the right direction even if you don't specifically tell them what that direction is.

Rabies answered 6/4, 2017 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.