Skip to content

Commit

Permalink
Fix issue for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
vano105 committed Jul 31, 2024
2 parents b5e41f6 + ca6a89b commit d5a9e5c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 126 deletions.
169 changes: 49 additions & 120 deletions tests/opencl/j_stat/statistic.ipynb

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion tests/opencl/kernel1/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#include "common.h"

Expand Down Expand Up @@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
return 0;
}

static bool float_compare(float f1, float f2)
{
static constexpr auto epsilon = 1.0e-06f;

if (abs(f1 - f2) <= epsilon)
return true;
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
}

static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
int K) {
for (int m = 0; m < M; ++m) {
Expand Down Expand Up @@ -265,7 +275,7 @@ int main(int argc, char **argv) {
int errors = 0;

for (size_t i = 0; i < size_t(M * N); i++)
if (C_cpu[i] != C[i])
if (!float_compare(C_cpu[i], C[i]))
errors++;
if (errors != 0)
printf("FAILED! - %d errors\n", errors);
Expand Down
16 changes: 13 additions & 3 deletions tests/opencl/kernel2/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#include "common.h"

Expand Down Expand Up @@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
return 0;
}

static bool float_compare(float f1, float f2)
{
static constexpr auto epsilon = 1.0e-06f;

if (abs(f1 - f2) <= epsilon)
return true;
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
}

static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
int K) {
for (int m = 0; m < M; ++m) {
Expand Down Expand Up @@ -172,9 +182,9 @@ int main(int argc, char **argv) {
}
srand(time(NULL));
for (int i = 0; i < M * K; i++)
A[i] = (int)((float)rand() / (float)RAND_MAX);
A[i] = ((float)rand() / (float)RAND_MAX);
for (int i = 0; i < N * K; i++)
B[i] = (int)((float)rand() / (float)RAND_MAX);
B[i] = ((float)rand() / (float)RAND_MAX);

// create buffers
a_memobj =
Expand Down Expand Up @@ -265,7 +275,7 @@ int main(int argc, char **argv) {
int errors = 0;

for (size_t i = 0; i < size_t(M * N); i++)
if (C_cpu[i] != C[i])
if (!float_compare(C_cpu[i], C[i]))
errors++;
if (errors != 0)
printf("FAILED! - %d errors\n", errors);
Expand Down
12 changes: 11 additions & 1 deletion tests/opencl/kernel3/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#include "common.h"

Expand Down Expand Up @@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
return 0;
}

static bool float_compare(float f1, float f2)
{
static constexpr auto epsilon = 1.0e-06f;

if (abs(f1 - f2) <= epsilon)
return true;
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
}

static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
int K) {
for (int m = 0; m < M; ++m) {
Expand Down Expand Up @@ -265,7 +275,7 @@ int main(int argc, char **argv) {
int errors = 0;

for (size_t i = 0; i < size_t(M * N); i++)
if (C_cpu[i] != C[i])
if (!float_compare(C_cpu[i], C[i]))
errors++;
if (errors != 0)
printf("FAILED! - %d errors\n", errors);
Expand Down
12 changes: 11 additions & 1 deletion tests/opencl/kernel4/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#include "common.h"

Expand Down Expand Up @@ -62,6 +63,15 @@ static int read_kernel_file(const char *filename, uint8_t **data,
return 0;
}

static bool float_compare(float f1, float f2)
{
static constexpr auto epsilon = 1.0e-06f;

if (abs(f1 - f2) <= epsilon)
return true;
return abs(f1 - f2) <= epsilon * fmax(abs(f1), abs(f2));
}

static void sgemm_cpu(float *C, const float *A, const float *B, int M, int N,
int K) {
for (int m = 0; m < M; ++m) {
Expand Down Expand Up @@ -265,7 +275,7 @@ int main(int argc, char **argv) {
int errors = 0;

for (size_t i = 0; i < size_t(M * N); i++)
if (C_cpu[i] != C[i])
if (!float_compare(C_cpu[i], C[i]))
errors++;
if (errors != 0)
printf("FAILED! - %d errors\n", errors);
Expand Down

0 comments on commit d5a9e5c

Please sign in to comment.