-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunc_Test.cu
More file actions
152 lines (93 loc) · 2.85 KB
/
Func_Test.cu
File metadata and controls
152 lines (93 loc) · 2.85 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
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
146
147
148
149
150
151
#include <iostream>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include "Loop.h"
#include "mycuda.cuh"
#include <stdio.h>
#define LOOP_EXEC(func,arg, arg_bytes,n) loop_helper<<<ceildiv(n,256),256>>>(func, arg, arg_bytes)
class Runme {
public:
__device__ void operator() ( void* INPUT, unsigned n ,unsigned size)
{
struct arg * The_Array = (struct arg*) INPUT;
int ID = size;
if(ID < 2){
The_Array->c[ID] = The_Array->a[ID] + The_Array->b[ID];
}
}
};
void Test( thrust::device_vector<int> &A , void(*f)(int*,int) )
{
int * GG = thrust::raw_pointer_cast(&A[0]);
std::cout<<"Stalling"<<std::endl;
dim3 Block ( 4 , 1);
(*f)<<<Block,1>>>(GG, 4);
std::cout<<"this is the silliest thing, I have every done"<<std::endl;
}
template <typename T>
void * arg_pass( T &a )
{
T *i; // So Nasty
CUDACALL(cudaMalloc( (void**)&i, sizeof(T) ));
CUDACALL( cudaMemcpy(i , &a , sizeof(T) , cudaMemcpyHostToDevice));
return i;
}
template <typename T>
void * Something( T &a)
{
cudaMemcpyToSymbol( &a , sizeof(T));
}
int main()
{
cudaDeviceReset();
struct arg a;
a.a = (unsigned int*)loop_malloc( 2);
a.b = (unsigned int*)loop_malloc( 2);
a.c = (unsigned int*)loop_malloc(2);
std::cout << a.a << std::endl;
unsigned int *d = new unsigned int[2];
std::cout<< "ARG is" <<&a <<std::endl;
GENDATA(a.a);
GENDATA(a.b);
std::cout << "HERE" <<std::endl;
//loop_exec( Runme() , arg_pass(a) , 2 , 2);
LOOP_EXEC(Runme(), arg_pass(a), 2 ,2);
std::cout<< "WHAT THE" << std::endl;
cudaDeviceSynchronize();
std::cout << a.a << std::endl;
CUDACALL( cudaMemcpy(d , a.c , 2*sizeof(unsigned) , cudaMemcpyDeviceToHost));
//printf( "%d , %d\n", d[0] , d[1]);
std::cout<< d[0] << " , " << d[1] <<std::endl;
return 0;
}
typedef void (*loop_kernal_func)(void*,unsigned,unsigned) ;
template<class O> __global__
void loop_helper( O op,
void* arg, unsigned arg_bytes)
{
unsigned i = CUDAINDEX;
op( arg , arg_bytes, i);
}
template<class O> void loop_exec( O op,
void* arg, unsigned arg_bytes,
unsigned n)
{
loop_kernal_func *h_f , *d_f;
//this should be constant memory.
/*
h_f = (loop_kernal_func*)malloc(sizeof(loop_kernal_func));
h_f[0] = loop_kernal;
CUDACALL(cudaMalloc((void**)&d_f,sizeof(loop_kernal_func)));
//std::cout<< "Here1"<<std::endl;
CUDACALL(cudaMemcpy( d_f , h_f , sizeof(loop_kernal_func) ,cudaMemcpyHostToDevice ));
//std::cout<< "Here2"<<std::endl;
*/
CUDACALL(cudaMallocManaged(&h_f , sizeof(loop_kernal_func)));
//h_f[0] = loop_kernal;
//CUDALAUNCH( loop_helper , n , (h_f,arg, arg_bytes));
loop_helper<<< ceildiv((n), 256), 256 >>>(O(),arg, arg_bytes);
//std::cout<< "Here3"<<std::endl;
//CUDALAUNCH( (*loop_kernal) , n , (arg, arg_bytes,-1));
//not sure what else to put. I really would like to work in a class for this part
// Going to have to talk it out via email... I guess
}