Skip to content

Commit b62ee90

Browse files
vano105vadyushkins
authored andcommitted
Fix issue for pull request
2 parents b5e41f6 + ca6a89b commit b62ee90

File tree

5 files changed

+95
-126
lines changed

5 files changed

+95
-126
lines changed

tests/opencl/j_stat/statistic.ipynb

+49-120
Large diffs are not rendered by default.

tests/opencl/kernel1/main.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sys/resource.h>
99
#include <time.h>
1010
#include <unistd.h>
11+
#include <math.h>
1112

1213
#include "common.h"
1314

@@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
6263
return 0;
6364
}
6465

66+
static bool float_compare(float f1, float f2)
67+
{
68+
static constexpr auto epsilon = 1.0e-06f;
69+
70+
if (abs(f1 - f2) <= epsilon)
71+
return true;
72+
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
73+
}
74+
6575
static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
6676
int K) {
6777
for (int m = 0; m < M; ++m) {
@@ -265,7 +275,7 @@ int main(int argc, char **argv) {
265275
int errors = 0;
266276

267277
for (size_t i = 0; i < size_t(M * N); i++)
268-
if (C_cpu[i] != C[i])
278+
if (!float_compare(C_cpu[i], C[i]))
269279
errors++;
270280
if (errors != 0)
271281
printf("FAILED! - %d errors\n", errors);

tests/opencl/kernel2/main.cc

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sys/resource.h>
99
#include <time.h>
1010
#include <unistd.h>
11+
#include <math.h>
1112

1213
#include "common.h"
1314

@@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
6263
return 0;
6364
}
6465

66+
static bool float_compare(float f1, float f2)
67+
{
68+
static constexpr auto epsilon = 1.0e-06f;
69+
70+
if (abs(f1 - f2) <= epsilon)
71+
return true;
72+
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
73+
}
74+
6575
static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
6676
int K) {
6777
for (int m = 0; m < M; ++m) {
@@ -172,9 +182,9 @@ int main(int argc, char **argv) {
172182
}
173183
srand(time(NULL));
174184
for (int i = 0; i < M * K; i++)
175-
A[i] = (int)((float)rand() / (float)RAND_MAX);
185+
A[i] = ((float)rand() / (float)RAND_MAX);
176186
for (int i = 0; i < N * K; i++)
177-
B[i] = (int)((float)rand() / (float)RAND_MAX);
187+
B[i] = ((float)rand() / (float)RAND_MAX);
178188

179189
// create buffers
180190
a_memobj =
@@ -265,7 +275,7 @@ int main(int argc, char **argv) {
265275
int errors = 0;
266276

267277
for (size_t i = 0; i < size_t(M * N); i++)
268-
if (C_cpu[i] != C[i])
278+
if (!float_compare(C_cpu[i], C[i]))
269279
errors++;
270280
if (errors != 0)
271281
printf("FAILED! - %d errors\n", errors);

tests/opencl/kernel3/main.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sys/resource.h>
99
#include <time.h>
1010
#include <unistd.h>
11+
#include <math.h>
1112

1213
#include "common.h"
1314

@@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
6263
return 0;
6364
}
6465

66+
static bool float_compare(float f1, float f2)
67+
{
68+
static constexpr auto epsilon = 1.0e-06f;
69+
70+
if (abs(f1 - f2) <= epsilon)
71+
return true;
72+
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
73+
}
74+
6575
static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
6676
int K) {
6777
for (int m = 0; m < M; ++m) {
@@ -265,7 +275,7 @@ int main(int argc, char **argv) {
265275
int errors = 0;
266276

267277
for (size_t i = 0; i < size_t(M * N); i++)
268-
if (C_cpu[i] != C[i])
278+
if (!float_compare(C_cpu[i], C[i]))
269279
errors++;
270280
if (errors != 0)
271281
printf("FAILED! - %d errors\n", errors);

tests/opencl/kernel4/main.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sys/resource.h>
99
#include <time.h>
1010
#include <unistd.h>
11+
#include <math.h>
1112

1213
#include "common.h"
1314

@@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
6263
return 0;
6364
}
6465

66+
static bool float_compare(float f1, float f2)
67+
{
68+
static constexpr auto epsilon = 1.0e-06f;
69+
70+
if (abs(f1 - f2) <= epsilon)
71+
return true;
72+
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
73+
}
74+
6575
static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
6676
int K) {
6777
for (int m = 0; m < M; ++m) {
@@ -265,7 +275,7 @@ int main(int argc, char **argv) {
265275
int errors = 0;
266276

267277
for (size_t i = 0; i < size_t(M * N); i++)
268-
if (C_cpu[i] != C[i])
278+
if (!float_compare(C_cpu[i], C[i]))
269279
errors++;
270280
if (errors != 0)
271281
printf("FAILED! - %d errors\n", errors);

0 commit comments

Comments
 (0)