tutility.cu - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
HTML git clone git://src.adamsgaard.dk/sphere
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tutility.cu (1837B)
---
1 #include <iostream>
2 #include "sphere.h"
3
4 // MISC. UTILITY FUNCTIONS
5
6 // Error handler for CUDA GPU calls.
7 // Returns error number, filename and line number containing the error to the
8 // terminal. Please refer to CUDA_Toolkit_Reference_Manual.pdf, section
9 // 4.23.3.3 enum cudaError for error discription. Error enumeration starts from
10 // 0.
11 void DEM::diagnostics()
12 {
13 // Retrieve information from device to host and run diagnostic tests
14 transferFromGlobalDeviceMemory();
15 checkValues();
16
17 // Clean up memory before exiting
18 if (fluid == 1 && cfd_solver == 0) {
19 freeNSmemDev();
20 freeNSmem();
21 }
22 if (fluid == 1 && cfd_solver == 1) {
23 freeDarcyMemDev();
24 freeDarcyMem();
25 }
26 freeGlobalDeviceMemory();
27 // CPU memory freed upon object destruction
28 }
29
30 void DEM::checkForCudaErrors(const char* checkpoint_description,
31 const int run_diagnostics)
32 {
33 cudaError_t err = cudaGetLastError();
34 if (err != cudaSuccess) {
35 std::cerr << "\nCuda error detected, checkpoint: "
36 << checkpoint_description << "\nError string: "
37 << cudaGetErrorString(err) << std::endl;
38
39 if (run_diagnostics == 1)
40 diagnostics();
41
42 exit(EXIT_FAILURE);
43 }
44 }
45
46 void DEM::checkForCudaErrorsIter(const char* checkpoint_description,
47 const unsigned int iteration,
48 const int run_diagnostics)
49 {
50 cudaError_t err = cudaGetLastError();
51 if (err != cudaSuccess) {
52 std::cerr << "\nCuda error detected, checkpoint: "
53 << checkpoint_description << "\nduring iteration " << iteration
54 << "\nError string: " << cudaGetErrorString(err) << std::endl;
55
56 if (run_diagnostics == 1)
57 diagnostics();
58
59 exit(EXIT_FAILURE);
60 }
61 }
62
63 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4