-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathhelper.h
35 lines (30 loc) · 787 Bytes
/
helper.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
#pragma once
bool all_close(float *A, float *B, int m, int n) {
for (int i = 0; i < m * n; i++) {
if (fabs(A[i] - B[i]) > 1e-5) {
printf("A[%d] = %f, B[%d] = %f\n", i, A[i], i, B[i]);
return false;
}
}
return true;
}
// print matrix
void print_host_matrix(float *matrix, int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
printf("%f, ", matrix[i * n + j]);
}
printf("\n");
}
}
void print_device_matrix(float *dev_ptr, int m, int n) {
float *host_ptr = new float[m * n];
cudaMemcpy(host_ptr, dev_ptr, sizeof(float) * m * n, cudaMemcpyDeviceToHost);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
printf("%f, ", host_ptr[i * n + j]);
}
printf("\n");
}
free(host_ptr);
}