7.1
general documentation
cs_base_cuda.h
Go to the documentation of this file.
1 #ifndef __CS_BASE_CUDA_H__
2 #define __CS_BASE_CUDA_H__
3 
4 /*============================================================================
5  * Definitions, global variables, and base functions for CUDA
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2021 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #include "cs_defs.h"
31 
32 /*----------------------------------------------------------------------------
33  * Standard C library headers
34  *----------------------------------------------------------------------------*/
35 
36 #include <stdio.h>
37 
38 /*----------------------------------------------------------------------------
39  * Local headers
40  *----------------------------------------------------------------------------*/
41 
42 #include "cs_log.h"
43 
44 /*=============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 #define CS_CUDA_CHECK(a) { \
49  cudaError_t ret_code = a; \
50  if (cudaSuccess != ret_code) { \
51  bft_error(__FILE__, __LINE__, 0, "[CUDA error] %d: %s\n running: %s", \
52  ret_code, ::cudaGetErrorString(ret_code), #a); \
53  } \
54  }
55 
56 #define CS_CUDA_CHECK_CALL(a, file_name, line_num) { \
57  cudaError_t ret_code = a; \
58  if (cudaSuccess != ret_code) { \
59  bft_error(file_name, line_num, 0, "[CUDA error] %d: %s\n running: %s", \
60  ret_code, ::cudaGetErrorString(ret_code), #a); \
61  } \
62  }
63 
64 /* For all current compute capabilities, the warp size is 32; If it ever
65  changes, it can be obtained through cudaDeviceProp, so we could then
66  replace this macro with a global variable */
67 
68 #define CS_CUDA_WARP_SIZE 32
69 
70 /*----------------------------------------------------------------------------*/
71 
73 
74 /*============================================================================
75  * Type definitions
76  *============================================================================*/
77 
78 /*=============================================================================
79  * Global variable definitions
80  *============================================================================*/
81 
82 extern int cs_glob_cuda_device_id;
83 
84 /* Other device parameters */
85 
88 extern int cs_glob_cuda_max_blocks;
89 extern int cs_glob_cuda_n_mp; /* Number of multiprocessors */
90 
91 /*============================================================================
92  * Semi-private function prototypes
93  *
94  * The following functions are intended to be used by the common
95  * host-device memory management functions from cs_base_accel.c, and
96  * not directly by the user.
97  *============================================================================*/
98 
99 #if defined(HAVE_CUDA)
100 
101 /*----------------------------------------------------------------------------*/
119 /*----------------------------------------------------------------------------*/
120 
121 void *
122 cs_cuda_mem_malloc_device(size_t n,
123  const char *var_name,
124  const char *file_name,
125  int line_num);
126 
127 /*----------------------------------------------------------------------------*/
145 /*----------------------------------------------------------------------------*/
146 
147 void *
148 cs_cuda_mem_malloc_host(size_t n,
149  const char *var_name,
150  const char *file_name,
151  int line_num);
152 
153 /*----------------------------------------------------------------------------*/
171 /*----------------------------------------------------------------------------*/
172 
173 void *
174 cs_cuda_mem_malloc_managed(size_t n,
175  const char *var_name,
176  const char *file_name,
177  int line_num);
178 
179 /*----------------------------------------------------------------------------*/
197 /*----------------------------------------------------------------------------*/
198 
199 void
200 cs_cuda_mem_free(void *p,
201  const char *var_name,
202  const char *file_name,
203  int line_num);
204 
205 /*----------------------------------------------------------------------------*/
223 /*----------------------------------------------------------------------------*/
224 
225 void
226 cs_cuda_mem_free_host(void *p,
227  const char *var_name,
228  const char *file_name,
229  int line_num);
230 
231 /*----------------------------------------------------------------------------*/
243 /*----------------------------------------------------------------------------*/
244 
245 void
246 cs_cuda_copy_h2d(void *dst,
247  const void *src,
248  size_t size);
249 
250 /*----------------------------------------------------------------------------*/
265 /*----------------------------------------------------------------------------*/
266 
267 void
268 cs_cuda_copy_h2d_async(void *dst,
269  const void *src,
270  size_t size);
271 
272 /*----------------------------------------------------------------------------*/
286 /*----------------------------------------------------------------------------*/
287 
288 void
289 cs_cuda_copy_d2h(void *dst,
290  const void *src,
291  size_t size);
292 
293 /*----------------------------------------------------------------------------*/
307 /*----------------------------------------------------------------------------*/
308 
309 void
310 cs_cuda_copy_d2h_async(void *dst,
311  const void *src,
312  size_t size);
313 
314 /*----------------------------------------------------------------------------*/
328 /*----------------------------------------------------------------------------*/
329 
330 void
331 cs_cuda_prefetch_h2d(void *dst,
332  size_t size);
333 
334 /*----------------------------------------------------------------------------*/
348 /*----------------------------------------------------------------------------*/
349 
350 void
351 cs_cuda_prefetch_d2h(void *dst,
352  size_t size);
353 
354 /*----------------------------------------------------------------------------*/
366 /*----------------------------------------------------------------------------*/
367 
368 void
369 cs_cuda_copy_d2d(void *dst,
370  const void *src,
371  size_t size);
372 
373 #endif
374 
375 /*=============================================================================
376  * Public function prototypes
377  *============================================================================*/
378 
379 #if defined(HAVE_CUDA)
380 
381 /*----------------------------------------------------------------------------*/
387 /*----------------------------------------------------------------------------*/
388 
389 void
390 cs_base_cuda_device_info(cs_log_t log_id);
391 
392 /*----------------------------------------------------------------------------*/
398 /*----------------------------------------------------------------------------*/
399 
400 void
401 cs_base_cuda_version_info(cs_log_t log_id);
402 
403 /*----------------------------------------------------------------------------*/
409 /*----------------------------------------------------------------------------*/
410 
411 void
412 cs_base_cuda_compiler_info(cs_log_t log_id);
413 
414 /*----------------------------------------------------------------------------*/
423 /*----------------------------------------------------------------------------*/
424 
425 int
426 cs_base_cuda_select_default_device(void);
427 
428 /*----------------------------------------------------------------------------*/
434 /*----------------------------------------------------------------------------*/
435 
436 int
437 cs_base_cuda_get_device(void);
438 
439 #endif
440 
441 /*----------------------------------------------------------------------------*/
442 
444 
445 #endif /* __CS_BASE_CUDA_H__ */
int cs_glob_cuda_device_id
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
int cs_glob_cuda_max_blocks
int cs_glob_cuda_n_mp
Definition: cs_field_pointer.h:67
int cs_glob_cuda_max_threads_per_block
cs_log_t
Definition: cs_log.h:48
int cs_glob_cuda_max_block_size
#define END_C_DECLS
Definition: cs_defs.h:511