-
Notifications
You must be signed in to change notification settings - Fork 7
/
archAPI.cxx
executable file
·147 lines (116 loc) · 2.01 KB
/
archAPI.cxx
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* archAPI.cxx
*
* Created on: Apr 10, 2018
* Author: snytav
*/
#include<stdlib.h>
#include<string.h>
#ifndef __CUDAC__
void BlockThreadSynchronize(){}
#endif
#ifndef __CUDAC__
double MultiThreadAdd(double *address, double val)
{
double assumed,old=*address;
#ifdef OMP_THREADS
#pragma omp critical
{
#endif
*address += val;
old = *address;
#ifdef OMP_THREADS
}
#endif
return old;
}
#endif
const char *getErrorString(int err)
{
return "";
}
int SetDevice(int n){return 0;}
#ifndef __CUDACC__
void AsyncCopy(double *dst,double *src,int n,int size)
{
int j;
for(j = 0;j < size;j++)
{
dst[j] = src[j];
}
}
int MemoryCopy(void* dst,void *src,size_t size,int dir)
{
memcpy(dst,src,size);
return 0;
}
#endif
#ifndef __CUDACC__
int MemoryAllocate(void** dst,size_t size)
{
*dst = malloc(size);
return 0;
}
#endif
#ifndef __CUDACC__
int GetDeviceMemory(size_t *m_free,size_t *m_total)
{
*m_free = 0;
*m_total = 0;
return 0;
}
#endif
#ifndef __CUDACC__
int MemorySet(void *s, int c, size_t n)
{
memset(s,c,n);
return 0;
}
#endif
#ifndef __CUDACC__
int DeviceSynchronize()
{
return 0;
}
int ThreadSynchronize()
{
return 0;
}
int getLastError()
{
return 0;
}
#endif
#ifdef __CUDACC__
__device__ void BlockThreadSynchronize()
{
__syncthreads();
}
#else
void BlockThreadSynchronize(){}
#endif
#ifdef __CUDACC__
__device__ double MultiThreadAdd(double *address, double val)
{
double assumed,old=*address;
do {
assumed=old;
old= __longlong_as_double(atomicCAS((unsigned long long int*)address,
__double_as_longlong(assumed),
__double_as_longlong(val+assumed)));
}while (assumed!=old);
*address += val;
old = *address;
return old;
}
#else
double MultiThreadAdd(double *address, double val){*address += val;}
#endif
#ifdef __CUDACC__
const char *getErrorString(int err)
{
return cudaGetErrorString((cudaError_t)err);
}
#else
const char *getErrorString(int err){return "";}
#endif