-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDefines.cpp
More file actions
54 lines (47 loc) · 1.1 KB
/
Copy pathDefines.cpp
File metadata and controls
54 lines (47 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "StdAfx.h"
#include "Defines.h"
#include <stdio.h>
#include <stdexcept>
#include <cuda_runtime.h>
#include <iostream>
#include <stdarg.h>
#ifdef ISWINDOWS
#include <Windows.h>
#endif
namespace CudaTracerLib {
void __ThrowCudaErrors__(const char* file, int line, ...)
{
va_list ap;
va_start(ap, line);
int arg = va_arg(ap, int);
va_end(ap);
cudaError_t r = arg == -1 ? cudaGetLastError() : (cudaError_t)arg;
if (r)
{
const char* msg = cudaGetErrorString(r);
auto er = format("In file '%s' at line %d : %s\n", file, line, msg);
std::cout << er;
throw std::runtime_error(er);
}
}
static void* zeroBuf = 0;
static size_t zeroBufLength = 0;
void CudaSetToZero_FreeBuffer()
{
if (zeroBuf)
free(zeroBuf);
}
void CudaSetToZero(void* dest, size_t length)
{
if (!zeroBuf || zeroBufLength < length)
{
if (zeroBuf)
free(zeroBuf);
zeroBufLength = RND_16(DMAX2(length, zeroBufLength));
zeroBuf = malloc(zeroBufLength);
for (int i = 0; i < zeroBufLength / 8; i++)
*((unsigned long long*)zeroBuf + i) = 0;
}
ThrowCudaErrors(cudaMemcpy(dest, zeroBuf, length, cudaMemcpyHostToDevice));
}
}