-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmat.h
38 lines (35 loc) · 1011 Bytes
/
submat.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
#ifndef SUBMAT_H
#define SUBMAT_H
#include "mat.h"
/* This class only is available on the GPU
Gets the BLOCK_SIZE x BLOCK_SIZE submatrix of a matrix that is
located col sub-matrices to the right and row sub-matrices down
from the upper-left corner of A */
class subMatrix {
public:
/* Member Data */
int width;
int height;
int stride;
float* elements;
__device__
subMatrix(Matrix A, int sub_size, int row, int col)
{
width = sub_size;
height = sub_size;
stride = A.stride;
// memory at spot
elements = &A.elements[stride * width * row + height * col];
}
//Get matrix element
__device__ inline float GetElem(const int row, const int col)
{
return elements[row * stride + col];
}
//Set a matrix element
__device__ inline void SetElem(const int row, const int col, const float value)
{
elements[row * stride + col] = value;
}
};
#endif