84eff8b1
Pavel Govyadinov
Merged only the n...
|
1
2
3
4
5
6
7
8
9
10
|
#include <assert.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
#include <stim/visualization/colormap.h>
#include <sstream>
#include <stim/math/vector.h>
#include <stim/cuda/cudatools/devices.h>
#include <stim/cuda/cudatools/threads.h>
#include <stim/cuda/cuda_texture.cuh>
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
11
|
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
12
13
14
15
16
|
float* print;
///Initialization function, allocates the memory and passes the necessary
///handles from OpenGL and Cuda.
///@param DIM_Y --integer controlling how much memory to allocate.
|
e45b97ce
Pavel Govyadinov
safety commit, I ...
|
17
|
void initArray(int x, int y)
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
18
|
{
|
e45b97ce
Pavel Govyadinov
safety commit, I ...
|
19
|
cudaMalloc( (void**) &print, x*y*sizeof(float)); ///temporary
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
20
21
22
23
24
25
26
27
|
}
///Deinit function that frees the memery used and releases the texture resource
///back to OpenGL.
void cleanUP()
{
cudaFree(print); ///temporary
}
|
5de3a9c2
Pavel Govyadinov
CHECKPOINT: befo...
|
28
|
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
29
30
31
32
33
34
35
36
37
38
|
__device__
float templ(int x, int max_x)
{
if(x < max_x/6 || x > max_x*5/6 || (x > max_x*2/6 && x < max_x*4/6))
{
return 1.0;
}else{
return 0.0;
}
}
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
39
40
41
42
43
44
45
46
|
///Find the difference of the given set of samples and the template
///using cuda acceleration.
///@param stim::cuda::cuda_texture t --stim texture that holds all the references
/// to the data.
///@param float* result --a pointer to the memory that stores the result.
__global__
//void get_diff (float *result)
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
47
|
void get_diff (cudaTextureObject_t texIn, float *print, int dx)
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
48
49
50
|
{
int x = threadIdx.x + blockIdx.x * blockDim.x;
int y = threadIdx.y + blockIdx.y * blockDim.y;
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
51
|
int idx = y*dx+x;
|
c0e09133
Pavel Govyadinov
STABLE: made temp...
|
52
|
// int idx = y*16+x;
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
53
|
|
59781ee3
Pavel Govyadinov
fixed a stask bug...
|
54
|
float valIn = tex2D<unsigned char>(texIn, x, y);
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
55
56
|
float templa = templ(x, 32)*255.0;
print[idx] = abs(valIn-templa); ///temporary
|
e45b97ce
Pavel Govyadinov
safety commit, I ...
|
57
|
//print[idx] = abs(templa); ///temporary
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
58
59
60
|
}
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
61
|
void test(cudaTextureObject_t tObj, int x, int y, std::string nam)
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
62
63
64
|
{
//Bind the Texture in GL and allow access to cuda.
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
65
66
67
|
//initialize the return arrays.
|
e45b97ce
Pavel Govyadinov
safety commit, I ...
|
68
69
70
|
initArray(x,y);
dim3 numBlocks(1, y);
dim3 threadsPerBlock(x, 1);
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
71
|
int max_threads = stim::maxThreadsPerBlock();
|
1306fd96
Pavel Govyadinov
minor bug fixes i...
|
72
73
|
//dim3 threads(max_threads, 1);
//dim3 blocks(x / threads.x + 1, y);
|
1306fd96
Pavel Govyadinov
minor bug fixes i...
|
74
75
|
//dim3 numBlocks(2, 2);
//dim3 threadsPerBlock(8, 108);
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
76
77
78
|
// get_diff <<< blocks, threads >>> (tx.getTexture(), print);
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
79
|
get_diff <<< numBlocks, threadsPerBlock >>> (tObj, print, x);
|
c0e09133
Pavel Govyadinov
STABLE: made temp...
|
80
81
82
83
|
cudaDeviceSynchronize();
stringstream name; //for debugging
name << nam.c_str();
|
4166e973
Pavel Govyadinov
Added debug tags ...
|
84
|
stim::gpu2image<float>(print, name.str(),x,y,0,255);
|
c0e09133
Pavel Govyadinov
STABLE: made temp...
|
85
|
|
c0e09133
Pavel Govyadinov
STABLE: made temp...
|
86
87
|
cleanUP();
}
|