openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
handle_error.hpp
Go to the documentation of this file.
1// Copyright 2023 Jij Inc.
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef OPENJIJ_UTILITY_GPU_HANDLE_ERROR_HPP__
16#define OPENJIJ_UTILITY_GPU_HANDLE_ERROR_HPP__
17
18#ifdef USE_CUDA
19
20#include <iostream>
21
22
23#include <cublas_v2.h>
24#include <cuda_runtime.h>
25#include <curand.h>
26
27namespace openjij {
28namespace utility {
29namespace cuda {
30
31// macro for detecting errors
32
33#ifndef NDEBUG
34
35#ifndef HANDLE_ERROR_CUDA
36#define HANDLE_ERROR_CUDA(expr) \
37 { \
38 cudaError_t err = (expr); \
39 if (err != cudaSuccess) \
40 std::cerr << "cuda error_code: " << err \
41 << " err_name: " << cudaGetErrorString(err) << " at " \
42 << __FILE__ << " line " << __LINE__ << std::endl; \
43 }
44#endif
45
46#ifndef HANDLE_ERROR_CURAND
47#define HANDLE_ERROR_CURAND(expr) \
48 { \
49 curandStatus_t st = (expr); \
50 if (st != CURAND_STATUS_SUCCESS) \
51 std::cerr << "curand_error: " << st << " at " << __FILE__ << " line " \
52 << __LINE__ << std::endl; \
53 }
54#endif
55
56#ifndef HANDLE_ERROR_CUBLAS
57#define HANDLE_ERROR_CUBLAS(expr) \
58 { \
59 cublasStatus_t st = (expr); \
60 if (st != CUBLAS_STATUS_SUCCESS) \
61 std::cerr << "cublas_error: " << st << " at " << __FILE__ << " line " \
62 << __LINE__ << std::endl; \
63 }
64#endif
65
66#else
67
68#ifndef HANDLE_ERROR_CUDA
69#define HANDLE_ERROR_CUDA(expr) expr
70#endif
71
72#ifndef HANDLE_ERROR_CURAND
73#define HANDLE_ERROR_CURAND(expr) expr
74#endif
75
76#ifndef HANDLE_ERROR_CUBLAS
77#define HANDLE_ERROR_CUBLAS(expr) expr
78#endif
79
80#endif
81} // namespace cuda
82} // namespace utility
83} // namespace openjij
84
85#endif
86#endif
Definition algorithm.hpp:24