Skip to content

Commit 86596c6

Browse files
committed
fixing gpu multiplication
1 parent 8dd7480 commit 86596c6

File tree

9 files changed

+56
-56
lines changed

9 files changed

+56
-56
lines changed

src/arithmetic.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Matrix Matrix::T() const {
2828
uint64_t *this_blocks = blocks;
2929
uint64_t *res_blocks = res.blocks;
3030

31-
uint16_t _width = width;
32-
uint16_t _height = height;
31+
int _width = width;
32+
int _height = height;
3333

3434
int16_t i, j;
3535
#if defined(_OPENMP) && defined(TARGET)
@@ -67,7 +67,7 @@ Matrix Matrix::operator~() const {
6767
uint64_t *this_blocks = blocks;
6868
uint64_t *res_blocks = res.blocks;
6969

70-
uint16_t _size = width * height;
70+
int _size = width * height;
7171

7272
int16_t n;
7373
#if defined(_OPENMP) && defined(TARGET)
@@ -97,7 +97,7 @@ Vector Vector::operator~() const {
9797
uint8_t *this_blocks = blocks;
9898
uint8_t *res_blocks = res.blocks;
9999

100-
uint16_t _height = height;
100+
int _height = height;
101101

102102
int16_t i;
103103
#if defined(_OPENMP) && defined(TARGET)

src/binary_arithmetic.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ constructors
2525
*/
2626

2727

28-
Matrix::Matrix(uint16_t _height, uint16_t _width) : height(_height), width(_width) {
28+
Matrix::Matrix(int _height, int _width) : height(_height), width(_width) {
2929
blocks = (uint64_t *) calloc(height * width, sizeof(uint64_t));
3030
if (blocks == NULL) throw std::bad_alloc();
3131
#ifdef MPIENABLED
@@ -38,7 +38,7 @@ Matrix::Matrix(uint16_t _height, uint16_t _width) : height(_height), width(_widt
3838
#endif
3939
}
4040

41-
Matrix::Matrix(uint16_t _size) : height(_size), width(_size) {
41+
Matrix::Matrix(int _size) : height(_size), width(_size) {
4242
blocks = (uint64_t *) calloc(_size * _size, sizeof(uint64_t));
4343
if (blocks == NULL) throw std::bad_alloc();
4444
#ifdef MPIENABLED
@@ -51,7 +51,7 @@ Matrix::Matrix(uint16_t _size) : height(_size), width(_size) {
5151
#endif
5252
}
5353

54-
Vector::Vector(uint16_t _size): height(_size) {
54+
Vector::Vector(int _size): height(_size) {
5555
blocks = (uint8_t *) calloc(height, sizeof(uint64_t));
5656
if (blocks == NULL) throw std::bad_alloc();
5757
#ifdef MPIENABLED
@@ -81,7 +81,7 @@ Matrix::Matrix(Matrix const& other) : height(other.height), width(other.width) {
8181
memcpy(blocks, other.blocks, height * width * sizeof(uint64_t)); //copy blocks
8282

8383
#if defined(_OPENMP) && defined(TARGET)
84-
uint16_t _size = height * width;
84+
int _size = height * width;
8585
uint64_t *this_blocks = blocks;
8686
#pragma omp target enter data map(to:this_blocks[:_size])
8787
#endif
@@ -98,7 +98,7 @@ Vector::Vector(Vector const& other) : height(other.height) {
9898
memcpy(blocks, other.blocks, height * sizeof(uint8_t)); //copy blocks
9999

100100
#if defined(_OPENMP) && defined(TARGET)
101-
uint16_t _height = height;
101+
int _height = height;
102102
uint8_t *this_blocks = blocks;
103103
#pragma omp target enter data map(to:this_blocks[:_height])
104104
#endif
@@ -112,7 +112,7 @@ destructors
112112

113113
Matrix::~Matrix(){
114114
#if defined(_OPENMP) && defined(TARGET)
115-
uint16_t _size = height * width;
115+
int _size = height * width;
116116
uint64_t *this_blocks = blocks;
117117
#pragma omp target exit data map(delete:this_blocks[:_size])
118118
#endif
@@ -121,7 +121,7 @@ Matrix::~Matrix(){
121121

122122
Vector::~Vector(){
123123
#if defined(_OPENMP) && defined(TARGET)
124-
uint16_t _height = height;
124+
int _height = height;
125125
uint8_t *this_blocks = blocks;
126126
#pragma omp target exit data map(delete:this_blocks[:_height])
127127
#endif

src/binary_arithmetic.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ slice struct
1717

1818
struct vector_slice {
1919
Vector *vect;
20-
uint16_t start, length;
20+
int start, length;
2121

2222
//constructor
23-
vector_slice(uint16_t _start, uint16_t _length, Vector *_vect) : start(_start), length(_length), vect(_vect) {}
23+
vector_slice(int _start, int _length, Vector *_vect) : start(_start), length(_length), vect(_vect) {}
2424

2525
operator Vector() const; //implicite comvertion
2626
vector_slice& operator=(Vector const& other); //assignment operators
@@ -29,10 +29,10 @@ struct vector_slice {
2929

3030
struct matrix_slice {
3131
Matrix *mat;
32-
uint16_t start_i, start_j, length_i, length_j;
32+
int start_i, start_j, length_i, length_j;
3333

3434
//constructor
35-
matrix_slice(uint16_t _start_i, uint16_t _start_j, uint16_t _length_i, uint16_t _length_j, Matrix *_mat) : start_i(_start_i), start_j(_start_j), length_i(_length_i), length_j(_length_j), mat(_mat) {}
35+
matrix_slice(int _start_i, int _start_j, int _length_i, int _length_j, Matrix *_mat) : start_i(_start_i), start_j(_start_j), length_i(_length_i), length_j(_length_j), mat(_mat) {}
3636

3737
operator Matrix() const; //implicite comvertion
3838
matrix_slice& operator=(Matrix const& other); //assignment operators
@@ -47,13 +47,13 @@ assignment struct
4747

4848
struct bool_from_byte {
4949
uint8_t *byte;
50-
uint16_t i;
50+
int i;
5151

5252
//util operations
5353
Utils* utils;
5454

5555
//constructor
56-
bool_from_byte(int16_t _i, uint8_t *_byte) : i(_i), byte(_byte) {}
56+
bool_from_byte(int _i, uint8_t *_byte) : i(_i), byte(_byte) {}
5757

5858
operator bool() const; //implicite comvertion
5959
bool_from_byte& operator=(bool value); //assignment operators
@@ -65,13 +65,13 @@ struct bool_from_byte {
6565

6666
struct bool_from_word {
6767
uint64_t *word;
68-
uint16_t i, j;
68+
int i, j;
6969

7070
//util operations
7171
Utils* utils;
7272

7373
//constructor
74-
bool_from_word(int16_t _i, int16_t _j, uint64_t *_word) : i(_i), j(_j), word(_word) {}
74+
bool_from_word(int _i, int _j, uint64_t *_word) : i(_i), j(_j), word(_word) {}
7575

7676
operator bool() const; //implicite comvertion
7777
bool_from_word& operator=(bool value); //assignment operators
@@ -121,15 +121,15 @@ class Matrix {
121121
uint64_t *blocks;
122122

123123
//Stupid way of accessing Matrix elements, only for testing or debugging !
124-
bool_from_word operator()(uint16_t i, uint16_t j) const;
124+
bool_from_word operator()(int i, int j) const;
125125

126126
//size
127-
const uint16_t height;
128-
const uint16_t width;
127+
const int height;
128+
const int width;
129129

130130
//constructors
131-
Matrix(uint16_t mat_height, uint16_t mat_width);
132-
Matrix(uint16_t size);
131+
Matrix(int mat_height, int mat_width);
132+
Matrix(int size);
133133

134134
//destructor
135135
~Matrix();
@@ -234,13 +234,13 @@ class Vector {
234234
uint8_t *blocks;
235235

236236
//Stupid way of accessing vector elements, only for testing or debugging !
237-
bool_from_byte operator[](uint16_t i) const;
237+
bool_from_byte operator[](int i) const;
238238

239239
//size
240-
const uint16_t height;
240+
const int height;
241241

242242
//constructor
243-
Vector(uint16_t size);
243+
Vector(int size);
244244

245245
//destructor
246246
~Vector();

src/comparisons.inl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool Matrix::operator==(Matrix const& other) const {
2626

2727
bool equal_ = true;
2828

29-
int16_t n;
29+
int n;
3030
_OPENMP_PRAGMA("omp parralel shared(this_blocks, other_blocks, _equal)")
3131
_OPENMP_PRAGMA("omp for")
3232
for (n = 0; n < _height * _width; n++) {
@@ -58,7 +58,7 @@ bool Vector::operator==(Vector const& other) const {
5858

5959
bool equal_ = true;
6060

61-
int16_t i;
61+
int i;
6262
_OPENMP_PRAGMA("omp parralel shared(this_blocks, other_blocks, _equal)")
6363
_OPENMP_PRAGMA("omp for")
6464
for (i = 0; i < _height; i++) {
@@ -96,7 +96,7 @@ bool Matrix::operator==(const bool bit) const {
9696
auto *this_blocks = blocks;
9797
auto _size = height * width;
9898

99-
int16_t n;
99+
int n;
100100
_OPENMP_PRAGMA("omp parralel shared(this_blocks, _equal)")
101101
_OPENMP_PRAGMA("omp for")
102102
for (n = 0; n < _size; n++) {
@@ -123,7 +123,7 @@ bool Vector::operator==(const bool bit) const {
123123
auto *this_blocks = blocks;
124124
auto _height = height;
125125

126-
int16_t i;
126+
int i;
127127
_OPENMP_PRAGMA("omp parralel shared(this_blocks, _equal)")
128128
_OPENMP_PRAGMA("omp for")
129129
for (i = 0; i < _height; i++) {
@@ -156,7 +156,7 @@ int Matrix::difference(Matrix const& other) const {
156156

157157
int diff = 0;
158158

159-
int16_t n;
159+
int n;
160160
#if defined(_OPENMP) && defined(TARGET)
161161
if(_size > GPU_LIMIT) {
162162
#pragma omp target teams distribute parallel for reduction(+ : diff) map(tofrom:diff)
@@ -186,7 +186,7 @@ int Vector::difference(Vector const& other) const {
186186

187187
int diff = 0;
188188

189-
int16_t i;
189+
int i;
190190
#if defined(_OPENMP) && defined(TARGET)
191191
if(_height > GPU_LIMIT) {
192192
#pragma omp target teams distribute parallel for reduction(+ : diff) map(tofrom:diff)

src/initializers.inl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void Matrix::randomize() {
1919
#endif
2020
uint8_t *block_8 = (uint8_t *)blocks;
2121

22-
uint16_t _size = height * width * 8;
22+
int _size = height * width * 8;
2323

24-
int16_t i;
24+
int i;
2525
_OPENMP_PRAGMA("omp parallel for shared(block_8)")
2626
for (i = 0; i < _size; i++)
2727
block_8[i] = rand();
@@ -45,7 +45,7 @@ void Vector::randomize() {
4545
#endif
4646
INITIALIZER_VECTOR_HEADER;
4747

48-
int16_t i;
48+
int i;
4949
_OPENMP_PRAGMA("omp parallel for shared(this_blocks)")
5050
for (i = 0; i < _height; i++)
5151
this_blocks[i] = rand();
@@ -104,7 +104,7 @@ diagonal initializers
104104
void Matrix::diag() {
105105
INITIALIZER_SQUARE_MATRIX_HEADER;
106106

107-
int16_t i, j;
107+
int i, j;
108108
_OPENMP_PRAGMA("omp parallel for collapse(2) shared(this_blocks)")
109109
for (i = 0; i < _height; i++)
110110
for (j = 0; j < _width; j++)
@@ -122,15 +122,15 @@ void Matrix::diag() {
122122
void Matrix::diag(Vector const& diagonal) {
123123
INITIALIZER_SQUARE_MATRIX_HEADER;
124124

125-
int16_t i, j;
125+
int i, j;
126126
_OPENMP_PRAGMA("omp parallel for collapse(2) shared(this_blocks)")
127127
for (i = 0; i < _height; i++)
128128
for (j = 0; j < _width; j++)
129129
if(i == j) {
130130
uint8_t block = diagonal.blocks[i];
131131
uint64_t res = 0;
132132

133-
for (int16_t k = 7; k >= 0; k--)
133+
for (int k = 7; k >= 0; k--)
134134
res = (res << 9) | ((block >> k) & 0x01);
135135

136136
blocks[i + j*_height] = res;

src/member/read_write.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ read operators
4646
*/
4747

4848

49-
bool_from_word Matrix::operator()(uint16_t i, uint16_t j) const { //changed to acomodate the switch in block indices, check the readme
49+
bool_from_word Matrix::operator()(int i, int j) const { //changed to acomodate the switch in block indices, check the readme
5050
assert(i < height * 8); //check if indices are in range
5151
assert(j < width * 8);
5252

5353
uint64_t *block = &blocks[j/8 + (i/8)*width];
5454
return bool_from_word(i%8, j%8, block);
5555
}
5656

57-
bool_from_byte Vector::operator[](uint16_t i) const {
57+
bool_from_byte Vector::operator[](int i) const {
5858
assert(i < height * 8); //check if indices are in range
5959

6060
return bool_from_byte(i%8, &blocks[i/8]);

src/member/slice.inl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ slice cast operator
2020
matrix_slice::operator Matrix() const {
2121
Matrix res(length_i, length_j);
2222

23-
for (int16_t i = 0; i < length_i; i++)
23+
for (int i = 0; i < length_i; i++)
2424
memcpy(&res.blocks[i*length_j], &mat->blocks[start_j + (i + start_i)*mat->width], length_j * sizeof(uint64_t)); //copy blocks
2525

2626
#if defined(_OPENMP) && defined(TARGET)
@@ -52,7 +52,7 @@ matrix_slice& matrix_slice::operator=(Matrix const& other) {
5252
assert(length_i == other.height);
5353
assert(length_j == other.width);
5454

55-
for (int16_t i = 0; i < length_i; i++) {
55+
for (int i = 0; i < length_i; i++) {
5656
memcpy(&mat->blocks[start_j + (i + start_i)*mat->width], &other.blocks[i*length_j], length_j * sizeof(uint64_t)); //copy blocks
5757

5858
#if defined(_OPENMP) && defined(TARGET)
@@ -79,7 +79,7 @@ matrix_slice& matrix_slice::operator=(matrix_slice const& other) {
7979
assert(length_i == other.length_i);
8080
assert(length_j == other.length_j);
8181

82-
for (int16_t i = 0; i < length_i; i++) {
82+
for (int i = 0; i < length_i; i++) {
8383
memcpy(&mat->blocks[start_j + (i + start_i)*mat->width], &other.mat->blocks[other.start_j + (i + other.start_i)*other.mat->width], length_j * sizeof(uint64_t)); //copy blocks
8484

8585
#if defined(_OPENMP) && defined(TARGET)

src/openmp.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//gpu operations
22
#if defined(_OPENMP) && defined(TARGET)
33
void Matrix::to() {
4-
uint16_t _size = height * width;
4+
int _size = height * width;
55
uint64_t *this_blocks = blocks;
66
#pragma omp target update to(this_blocks[:_size])
77
}
88

99
void Vector::to() {
10-
uint16_t _height = height;
10+
int _height = height;
1111
uint8_t *this_blocks = blocks;
1212
#pragma omp target update to(this_blocks[:_height])
1313
}
@@ -23,13 +23,13 @@
2323
}
2424

2525
void Matrix::from() {
26-
uint16_t _size = height * width;
26+
int _size = height * width;
2727
uint64_t *this_blocks = blocks;
2828
#pragma omp target update from(this_blocks[:_size])
2929
}
3030

3131
void Vector::from() {
32-
uint16_t _height = height;
32+
int _height = height;
3333
uint8_t *this_blocks = blocks;
3434
#pragma omp target update from(this_blocks[:_height])
3535
}

0 commit comments

Comments
 (0)