Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
CudaAccelerator.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* CudaAccelerator.h (C) 2000-2025 */
9/* */
10/* Backend 'CUDA' pour les accélérateurs. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CUDA_CUDAACCELERATOR_H
13#define ARCANE_CUDA_CUDAACCELERATOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/NotSupportedException.h"
20#include "arcane/utils/FatalErrorException.h"
21
22#include <iostream>
23
24#include <cuda_runtime.h>
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29#ifdef ARCANE_COMPONENT_arcane_cuda
30#define ARCANE_CUDA_EXPORT ARCANE_EXPORT
31#else
32#define ARCANE_CUDA_EXPORT ARCANE_IMPORT
33#endif
34
35namespace Arcane::Accelerator::Cuda
36{
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41extern "C++" ARCANE_CUDA_EXPORT void
42arcaneCheckCudaErrors(const TraceInfo& ti,cudaError_t e);
43
44extern "C++" ARCANE_CUDA_EXPORT void
45arcaneCheckCudaErrorsNoThrow(const TraceInfo& ti,cudaError_t e);
46
48#define ARCANE_CHECK_CUDA(result) \
49 Arcane::Accelerator::Cuda::arcaneCheckCudaErrors(A_FUNCINFO,result)
50
52#define ARCANE_CHECK_CUDA_NOTHROW(result) \
53 Arcane::Accelerator::Cuda::arcaneCheckCudaErrorsNoThrow(A_FUNCINFO,result)
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58extern "C++" ARCANE_CUDA_EXPORT Arccore::IMemoryAllocator*
59getCudaMemoryAllocator();
60
62extern "C++" ARCANE_CUDA_EXPORT Arccore::IMemoryAllocator*
63getCudaDeviceMemoryAllocator();
64
66extern "C++" ARCANE_CUDA_EXPORT Arccore::IMemoryAllocator*
67getCudaUnifiedMemoryAllocator();
68
70extern "C++" ARCANE_CUDA_EXPORT Arccore::IMemoryAllocator*
71getCudaHostPinnedMemoryAllocator();
72
73extern "C++" ARCANE_CUDA_EXPORT void
74initializeCudaMemoryAllocators();
75
76extern "C++" ARCANE_CUDA_EXPORT void
77finalizeCudaMemoryAllocators(ITraceMng* tm);
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82#if defined(CUDART_VERSION) && CUDART_VERSION >= 13000
83#define ARCANE_USING_CUDA13_OR_GREATER
84#endif
85
86// A partir de CUDA 13, il y a un nouveau type cudaMemLocation
87// pour les méthodes telles cudeMemAdvise ou cudaMemPrefetch
88#if defined(ARCANE_USING_CUDA13_OR_GREATER)
89inline cudaMemLocation
90_getMemoryLocation(int device_id)
91{
92 cudaMemLocation mem_location;
93 mem_location.type = cudaMemLocationTypeDevice;
94 mem_location.id = device_id;
95 if (device_id == cudaCpuDeviceId)
96 mem_location.type = cudaMemLocationTypeHost;
97 else {
98 mem_location.type = cudaMemLocationTypeDevice;
99 mem_location.id = device_id;
100 }
101 return mem_location;
102}
103#else
104inline int
105_getMemoryLocation(int device_id)
106{
107 return device_id;
108}
109#endif
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114} // End namespace Arcane::accelerator::cuda
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119#endif
Interface du gestionnaire de traces.