Skip to content

Commit e2dbe8d

Browse files
author
david.algis
committed
✨ Add cufft check
1 parent eb41df1 commit e2dbe8d

File tree

10 files changed

+128
-54
lines changed

10 files changed

+128
-54
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.5 KB
Binary file not shown.
39 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-512 Bytes
Binary file not shown.
39 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Plugin/Utilities/include/cuda_include.h

Lines changed: 128 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,95 @@
44
#include <string>
55

66
// use this macro if you want to check cuda function
7-
#define CUDA_CHECK(ans) { gpuAssert((ans), __FILE__, __LINE__); }
7+
#define CUDA_CHECK(ans) { cudaAssert((ans), __FILE__, __LINE__); }
8+
#define CUFFT_CHECK(ans) { cufftAssert((int)(ans), __FILE__, __LINE__); }
89

9-
inline void gpuAssert(cudaError_t code, const char* file, int line)
10+
11+
inline void cudaAssert(cudaError_t code, const char* file, int line)
12+
{
13+
if (code != cudaSuccess)
14+
{
15+
char buffer[2048];
16+
sprintf_s(buffer, "Cuda error: %i %s %s %d\n", code, cudaGetErrorString(code), file, line);
17+
std::string strError(buffer);
18+
Log::log().debugLogError(buffer);
19+
}
20+
}
21+
22+
inline void cufftAssert(int cufftResult, const char* file, int line)
1023
{
11-
if (code != cudaSuccess)
12-
{
13-
char buffer[2048];
14-
sprintf_s(buffer, "Cuda error: %i %s %s %d\n", code, cudaGetErrorString(code), file, line);
15-
std::string strError(buffer);
16-
Log::log().debugLogError(buffer);
17-
}
24+
25+
if (cufftResult != 0)
26+
{
27+
std::string cufftInterpret;
28+
switch (cufftResult)
29+
{
30+
case(0):
31+
cufftInterpret = "The cuFFT operation was successful";
32+
break;
33+
case(1):
34+
cufftInterpret = "cuFFT was passed an invalid plan handle";
35+
break;
36+
case(2):
37+
cufftInterpret = "cuFFT failed to allocate GPU or CPU memory";
38+
break;
39+
case(3):
40+
cufftInterpret = "No longer used";
41+
break;
42+
case(4):
43+
cufftInterpret = "User specified an invalid pointer or parameter";
44+
break;
45+
case(5):
46+
cufftInterpret = "Driver or internal cuFFT library error";
47+
break;
48+
case(6):
49+
cufftInterpret = "Failed to execute an FFT on the GPU";
50+
break;
51+
case(7):
52+
cufftInterpret = "The cuFFT library failed to initialize";
53+
break;
54+
case(8):
55+
cufftInterpret = "User specified an invalid transform size";
56+
break;
57+
case(9):
58+
cufftInterpret = "No longer used";
59+
break;
60+
case(10):
61+
cufftInterpret = "Missing parameters in call";
62+
break;
63+
case(11):
64+
cufftInterpret = "Execution of a plan was on different GPU than plan creation";
65+
break;
66+
case(12):
67+
cufftInterpret = "Internal plan database error";
68+
break;
69+
case(13):
70+
cufftInterpret = "No workspace has been provided prior to plan execution";
71+
break;
72+
case(14):
73+
cufftInterpret = "Function does not implement functionality for parameters given.";
74+
break;
75+
case(15):
76+
cufftInterpret = "Used in previous versions.";
77+
break;
78+
case(16):
79+
cufftInterpret = "Operation is not supported for parameters given.";
80+
break;
81+
default:
82+
cufftInterpret = "Unknown error.";
83+
break;
84+
}
85+
char buffer[2048];
86+
sprintf_s(buffer, "Cufft error: %i %s %s %d\n", cufftResult, cufftInterpret, file, line);
87+
std::string strError(buffer);
88+
Log::log().debugLogError(buffer);
89+
}
90+
1891
}
1992

2093

21-
/// <summary>
94+
95+
/// <summary>
2296
/// Get thedim grid to use for a dispatch, from a multiple of
2397
/// dim block that are used by the kernel, and the number of
2498
/// calculation that has to be done.
@@ -39,55 +113,55 @@ inline void gpuAssert(cudaError_t code, const char* file, int line)
39113
/// </param>
40114
/// <returns>The dim of grid to use in dispatch</returns>
41115
inline dim3 calculateDimGrid(dim3 dimBlock, dim3 numCalculation, bool getUp = true,
42-
bool mustDoAllCalculation = false)
116+
bool mustDoAllCalculation = false)
43117
{
44-
int addFactor = getUp ? 1 : 0;
45-
float invDimBlockX = 1.0f / dimBlock.x;
46-
float invDimBlockY = 1.0f / dimBlock.y;
47-
float invDimBlockZ = 1.0f / dimBlock.z;
118+
int addFactor = getUp ? 1 : 0;
119+
float invDimBlockX = 1.0f / dimBlock.x;
120+
float invDimBlockY = 1.0f / dimBlock.y;
121+
float invDimBlockZ = 1.0f / dimBlock.z;
48122

49-
if (mustDoAllCalculation)
50-
{
51-
if (numCalculation.x % dimBlock.x != 0 ||
52-
numCalculation.y % dimBlock.y != 0 ||
53-
numCalculation.z % dimBlock.z != 0)
54-
{
55-
Log::log().debugLogError(
56-
"Number of threads per block (" + std::to_string(dimBlock.x) +
57-
", " + std::to_string(dimBlock.y) + ", " +
58-
std::to_string(dimBlock.z) +
59-
")"
60-
" is not a multiple of (" +
61-
std::to_string(numCalculation.x) + ", " +
62-
std::to_string(numCalculation.y) + ", " +
63-
std::to_string(numCalculation.z) +
64-
")"
65-
", therefore the compute shader will not compute on all data.");
66-
}
67-
}
123+
if (mustDoAllCalculation)
124+
{
125+
if (numCalculation.x % dimBlock.x != 0 ||
126+
numCalculation.y % dimBlock.y != 0 ||
127+
numCalculation.z % dimBlock.z != 0)
128+
{
129+
Log::log().debugLogError(
130+
"Number of threads per block (" + std::to_string(dimBlock.x) +
131+
", " + std::to_string(dimBlock.y) + ", " +
132+
std::to_string(dimBlock.z) +
133+
")"
134+
" is not a multiple of (" +
135+
std::to_string(numCalculation.x) + ", " +
136+
std::to_string(numCalculation.y) + ", " +
137+
std::to_string(numCalculation.z) +
138+
")"
139+
", therefore the compute shader will not compute on all data.");
140+
}
141+
}
68142

69-
unsigned int multipleDimBlockX =
70-
dimBlock.x * ((int)(numCalculation.x * invDimBlockX) + addFactor);
71-
//unsigned int multipleDimBlockX =
72-
// dimBlock.x * (numCalculation.x / dimBlock.x) + addFactor);
73-
// TODO remove dimBlock.x above and bellow
74-
unsigned int dimGridX = multipleDimBlockX / dimBlock.x;
143+
unsigned int multipleDimBlockX =
144+
dimBlock.x * ((int)(numCalculation.x * invDimBlockX) + addFactor);
145+
//unsigned int multipleDimBlockX =
146+
// dimBlock.x * (numCalculation.x / dimBlock.x) + addFactor);
147+
// TODO remove dimBlock.x above and bellow
148+
unsigned int dimGridX = multipleDimBlockX / dimBlock.x;
75149

76-
unsigned int multipleDimBlockY =
77-
dimBlock.y * ((int)(numCalculation.y * invDimBlockY) + addFactor);
78-
unsigned int dimGridY = multipleDimBlockY / dimBlock.y;
150+
unsigned int multipleDimBlockY =
151+
dimBlock.y * ((int)(numCalculation.y * invDimBlockY) + addFactor);
152+
unsigned int dimGridY = multipleDimBlockY / dimBlock.y;
79153

80-
unsigned int multipleDimBlockZ =
81-
dimBlock.z * ((int)(numCalculation.z * invDimBlockZ) + addFactor);
82-
unsigned int dimGridZ = multipleDimBlockZ / dimBlock.z;
154+
unsigned int multipleDimBlockZ =
155+
dimBlock.z * ((int)(numCalculation.z * invDimBlockZ) + addFactor);
156+
unsigned int dimGridZ = multipleDimBlockZ / dimBlock.z;
83157

84-
if (dimGridX < 1 || dimGridY < 1 || dimGridZ <1)
85-
{
86-
Log::log().debugLogError(
87-
"Threads group size " + std::to_string(dimGridX) +
88-
std::to_string(dimGridY) + std::to_string(dimGridZ) +
89-
" must be above zero.");
90-
}
158+
if (dimGridX < 1 || dimGridY < 1 || dimGridZ < 1)
159+
{
160+
Log::log().debugLogError(
161+
"Threads group size " + std::to_string(dimGridX) +
162+
std::to_string(dimGridY) + std::to_string(dimGridZ) +
163+
" must be above zero.");
164+
}
91165

92-
return dim3{dimGridX, dimGridY, dimGridZ};
166+
return dim3{ dimGridX, dimGridY, dimGridZ };
93167
}

0 commit comments

Comments
 (0)