]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/doc/first-invocation-nvidia-cublas-library-api.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / libgomp / doc / first-invocation-nvidia-cublas-library-api.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6First invocation: NVIDIA CUBLAS library API
7*******************************************
8
9In this first use case (see below), a function in the CUBLAS library is called
10prior to any of the functions in the OpenACC library. More specifically, the
11function ``cublasCreate()``.
12
13When invoked, the function initializes the library and allocates the
14hardware resources on the host and the device on behalf of the caller. Once
15the initialization and allocation has completed, a handle is returned to the
16caller. The OpenACC library also requires initialization and allocation of
17hardware resources. Since the CUBLAS library has already allocated the
18hardware resources for the device, all that is left to do is to initialize
19the OpenACC library and acquire the hardware resources on the host.
20
21Prior to calling the OpenACC function that initializes the library and
22allocate the host hardware resources, you need to acquire the device number
23that was allocated during the call to ``cublasCreate()``. The invoking of the
24runtime library function ``cudaGetDevice()`` accomplishes this. Once
25acquired, the device number is passed along with the device type as
26parameters to the OpenACC library function ``acc_set_device_num()``.
27
28Once the call to ``acc_set_device_num()`` has completed, the OpenACC
29library uses the context that was created during the call to
30``cublasCreate()``. In other words, both libraries will be sharing the
31same context.
32
33.. code-block:: c++
34
35 /* Create the handle */
36 s = cublasCreate(&h);
37 if (s != CUBLAS_STATUS_SUCCESS)
38 {
39 fprintf(stderr, "cublasCreate failed %d\n", s);
40 exit(EXIT_FAILURE);
41 }
42
43 /* Get the device number */
44 e = cudaGetDevice(&dev);
45 if (e != cudaSuccess)
46 {
47 fprintf(stderr, "cudaGetDevice failed %d\n", e);
48 exit(EXIT_FAILURE);
49 }
50
51 /* Initialize OpenACC library and use device 'dev' */
3ed1b4ce 52 acc_set_device_num(dev, acc_device_nvidia);