Lattice Microbes 2.5
This is for whole cell modeling
Loading...
Searching...
No Matches
lm_cuda.h
Go to the documentation of this file.
1/*
2 * University of Illinois Open Source License
3 * Copyright 2008-2018 Luthey-Schulten Group,
4 * All rights reserved.
5 *
6 * Developed by: Luthey-Schulten Group
7 * University of Illinois at Urbana-Champaign
8 * http://www.scs.uiuc.edu/~schulten
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy of
11 * this software and associated documentation files (the Software), to deal with
12 * the Software without restriction, including without limitation the rights to
13 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 * of the Software, and to permit persons to whom the Software is furnished to
15 * do so, subject to the following conditions:
16 *
17 * - Redistributions of source code must retain the above copyright notice,
18 * this list of conditions and the following disclaimers.
19 *
20 * - Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimers in the documentation
22 * and/or other materials provided with the distribution.
23 *
24 * - Neither the names of the Luthey-Schulten Group, University of Illinois at
25 * Urbana-Champaign, nor the names of its contributors may be used to endorse or
26 * promote products derived from this Software without specific prior written
27 * permission.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32 * THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35 * OTHER DEALINGS WITH THE SOFTWARE.
36 *
37 * Author(s): Elijah Roberts
38 */
39
40#ifndef LM_CUDAHELPER_H_
41#define LM_CUDAHELPER_H_
42
43#include <string>
44#include <cuda.h>
45#include <cuda_runtime.h>
46#include "core/Exceptions.h"
47
48namespace lm
49{
50
55{
56public:
57 CUDAException(cudaError_t error, const char * file, const int line) : Exception("CUDA error",cudaGetErrorString(error),file,line) {}
58};
59
64{
65public:
66 CUDADriverException(CUresult error, const char * file, const int line) : Exception("CUDA driver error", error,file,line) {}
67};
68
72class CUDA
73{
74public:
75 static CUresult _cuda_dret_;
76
77 static int getNumberDevices();
78 static void setCurrentDevice(int device);
79 static int getCurrentDevice();
80 static size_t getFreeMemory(int device);
81 static void getComputeCapabilities(int device, int * major, int * minor);
82 static void printCapabilities(int device);
83 static std::string getCapabilitiesString(int device);
84};
85
86}
87
88// Macros for wrapping CUDA calls within an exception handler.
89#define CUDA_EXCEPTION_CHECK(cuda_call) {if ((cuda_call) != cudaSuccess) throw lm::CUDAException(cudaGetLastError(),__FILE__,__LINE__);}
90#define CUDA_EXCEPTION_DRIVER_CHECK(cuda_call) {if ((::lm::CUDA::_cuda_dret_=cuda_call) != CUDA_SUCCESS) throw lm::CUDADriverException(::lm::CUDA::_cuda_dret_,__FILE__,__LINE__);}
91#define CUDA_EXCEPTION_EXECUTE(cuda_exec) {cuda_exec; if (cudaPeekAtLastError() != cudaSuccess) throw lm::CUDAException(cudaGetLastError(),__FILE__,__LINE__);}
92#define CUDA_EXCEPTION_CHECK_NOTHROW(cuda_call) do { \
93 if ((cuda_call) != cudaSuccess) { \
94 fprintf(stderr, "Cuda error in destructor: %s @ %s:%d\n", cudaGetErrorString(cudaGetLastError()), __FILE__, __LINE__); \
95 std::terminate(); \
96 } \
97} while (0)
98
99#endif /*LM_CUDAHELPER_H_*/
CUDADriverException(CUresult error, const char *file, const int line)
Definition lm_cuda.h:66
CUDAException(cudaError_t error, const char *file, const int line)
Definition lm_cuda.h:57
Definition lm_cuda.h:73
static int getCurrentDevice()
static void setCurrentDevice(int device)
static int getNumberDevices()
static void getComputeCapabilities(int device, int *major, int *minor)
static void printCapabilities(int device)
static size_t getFreeMemory(int device)
static CUresult _cuda_dret_
Definition lm_cuda.h:75
static std::string getCapabilitiesString(int device)
Exception(const char *message="")
Create an Exception.
Definition Exceptions.h:62
Definition Capsule.cpp:46