Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AlephCuda.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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#ifndef _IALEPH_CUDA_H_
8#define _IALEPH_CUDA_H_
9
10#include <set>
11#include <vector>
12#include <algorithm>
13#include <stdio.h>
14
15#include <cuda.h>
16#include <cublas.h>
17#include <cuda_runtime.h>
18
19#define CNC_ASSERT(isOK, message) \
20 if (!(isOK)) { \
21 (void)printf("ERROR!! Assert '%s' failed\n%s\n", \
22 #isOK, message); \
23 return false; \
24 }
25
26//---------------------------------------------------------------------------//
27
28template <class T, class S> inline S* CNCallocate_and_copy(const T* in, int size)
29{
30
31 S* out = new S[size];
32 for (int i = 0; i < size; i++) {
33 out[i] = (S)in[i];
34 }
35 return out;
36}
37
38//---------------------------------------------------------------------------//
39
40template <class T> T* CNCallocate(long number)
41{
42 return new T[number];
43}
44
45//---------------------------------------------------------------------------//
46
47template <class T> void CNCdeallocate(T*& addr)
48{
49 delete[] addr;
50 addr = NULL; // makes it possible to track
51 // access to deallocated memory.
52}
53
54//---------------------------------------------------------------------------//
55
56template <class T> void CNCreallocate(T*& addr, long old_number, long new_number)
57{
58 T* new_addr = new T[new_number];
59 for (int i = 0; i < old_number; i++) {
60 new_addr[i] = addr[i];
61 }
62 delete[] addr;
63 addr = new_addr;
64}
65
66#include "arcane/aleph/cuda/AlephCudaVector.h"
67#include "arcane/aleph/cuda/AlephCudaMatrix.h"
68#include "arcane/aleph/cuda/AlephCudaMatrixCrs.h"
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73namespace Arcane
74{
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79class Cuda
80{
81 public:
82
83 Cuda();
84 ~Cuda();
85 void cnc_cuda_set_dim_vec_from_n(long);
86 void convert_matrix(const CNC_Matrix& rhs, CNC_MatrixCRS<double>& A, bool separate_diag);
87 bool solve(CNC_MatrixCRS<double>& A,
88 const CNC_Vector<double>& b,
90 const unsigned int nb_iter_max,
91 const double epsilon,
92 Integer& nb_iteration,
93 Real* residual_norm);
94 void cublas_get_error(cublasStatus_t);
95
96 public:
97
98 void* gpu_r;
99 void* gpu_d;
100 void* gpu_h;
101 void* gpu_Ad;
102 void* gpu_diag_inv;
103 void* gpu_b;
104 void* gpu_x;
105 void* gpu_temp;
106 void* gpu_temp0;
107 void* gpu_temp1;
108 void* gpu_res0;
109};
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114} // namespace Arcane
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119#endif
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.