24

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.

3
  • 1
    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. Apr 11, 2017 at 6:55
  • Is there a similar concept in any other open source library that I can check out? Apr 11, 2017 at 13:16
  • 1
    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. Apr 11, 2017 at 22:18

2 Answers 2

23

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.

1
  • 1
    Both the answers are enlightening. But I am still not satisfied. Can you describe it in more detail? Apr 10, 2017 at 17:54
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.