forked from Celebrandil/CudaSift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cudaImage.h
83 lines (66 loc) · 2.34 KB
/
cudaImage.h
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
/**
* Author: Marten Bjorkman
* Contributor: Ethan Stewart
*
* This file consists of a class CudaImage and some functions
* which may pad the allocation to ensure that corresponding
* pointers in any given row will continue to meet the alignment
* requirements for coalescing as the address is updated from row to row.
*/
#ifndef CUDASIFT_CUDAIMAGE_H
#define CUDASIFT_CUDAIMAGE_H
/**
* The CudaImage defines a class that performs memory allocation
* and data transfer between host and device
* @Param width Requested pitched allocation width(in bytes)
* @Param height Requested pitched allocation height
* @Param pitch Pitch for allocation
* @param h_data Pointer to allocated host memory
* @param d_data Pointer to allocated pitched device memory
* @param t_data Pointer to allocated texture memory
* @Param d_internalAlloc Boolean value indicating whether to call the Allocate method to allocate memory on the device
* @Param h_internalAlloc Boolean value indicating whether to call the Allocate method to allocate memory on the host
*/
class CudaImage {
public:
int width, height, pitch;
float *h_data;
float *d_data;
float *t_data;
bool d_internalAlloc;
bool h_internalAlloc;
public:
CudaImage();
~CudaImage();
/**
* Allocate host memory and device memory.
* Parameter withHost indicates whether to allocate host memory.
* Destructor will free space for devMem and hostMem.
* Both devMem and hostMem could be NULL.
*/
void Allocate(int width, int height, int pitch, bool withHost, float *devMem = NULL, float *hostMem = NULL);
/**
* Copy data from host to device.Pay attention to width,
* height, pitch, once not corrected, it may break down.
* @return Time for coping data.
*/
double Download();
/**
* Copy data from device to host.
* @return Time for coping data.
*/
double Readback();
double InitTexture();
/**
* Copy data from device to host.
* @return Time for coping data.
*/
double CopyToTexture(CudaImage &dst, bool host);
};
int iDivUp(int dividend, int divisor);
int iDivDown(int dividend, int divisor);
int iAlignUp(int number, int alignment);
int iAlignDown(int number, int alignment);
void StartTimer(unsigned int *hTimer);
double StopTimer(unsigned int hTimer);
#endif // CUDASIFT_CUDAIMAGE_H