Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
opencl-math-accuracy.c File Reference
#include <CL/cl.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+ Include dependency graph for opencl-math-accuracy.c:

Go to the source code of this file.

Data Structures

struct  option_set_t
 

Macros

#define CL_TARGET_OPENCL_VERSION   300
 
#define NSAMPLES   200000
 
#define XMIN   (-8.0f)
 
#define XMAX   (8.0f)
 
#define FAIL_THRESHOLD   1e-4
 
#define BROKEN_THRESHOLD   1e-2
 
#define N_OPTION_SETS   ((int)(sizeof(OPTION_SETS) / sizeof(OPTION_SETS[0])))
 

Enumerations

enum  op_t {
  OP_ERF = 0 ,
  OP_GELU ,
  OP_EXP ,
  OP_LOG ,
  OP_TANH ,
  OP_POW ,
  OP_SQRT ,
  OP_DIV ,
  N_OPS
}
 

Functions

static double reference (const op_t op, const double x)
 
static void host_probe (const float *const in, float *const out, const int n, const op_t op)
 
static void canonical_name (const char *in, char *out, const size_t maxlen)
 
static double max_error (const float *const got, const float *const in, const int n, const op_t op)
 
static void print_header (void)
 
int main (void)
 

Variables

static const char * KERNEL_SRC
 
static const char * OP_NAME [N_OPS] = { "erf", "GELU", "exp", "log", "tanh", "pow", "sqrt", "divide" }
 
static const option_set_t OPTION_SETS []
 

Macro Definition Documentation

◆ BROKEN_THRESHOLD

#define BROKEN_THRESHOLD   1e-2

Definition at line 65 of file opencl-math-accuracy.c.

◆ CL_TARGET_OPENCL_VERSION

#define CL_TARGET_OPENCL_VERSION   300

Definition at line 43 of file opencl-math-accuracy.c.

◆ FAIL_THRESHOLD

#define FAIL_THRESHOLD   1e-4

Definition at line 62 of file opencl-math-accuracy.c.

◆ N_OPTION_SETS

#define N_OPTION_SETS   ((int)(sizeof(OPTION_SETS) / sizeof(OPTION_SETS[0])))

Definition at line 154 of file opencl-math-accuracy.c.

◆ NSAMPLES

#define NSAMPLES   200000

Definition at line 55 of file opencl-math-accuracy.c.

◆ XMAX

#define XMAX   (8.0f)

Definition at line 57 of file opencl-math-accuracy.c.

◆ XMIN

#define XMIN   (-8.0f)

Definition at line 56 of file opencl-math-accuracy.c.

Enumeration Type Documentation

◆ op_t

enum op_t
Enumerator
OP_ERF 
OP_GELU 
OP_EXP 
OP_LOG 
OP_TANH 
OP_POW 
OP_SQRT 
OP_DIV 
N_OPS 

Definition at line 88 of file opencl-math-accuracy.c.

Function Documentation

◆ canonical_name()

static void canonical_name ( const char *  in,
char *  out,
const size_t  maxlen 
)
static

Definition at line 158 of file opencl-math-accuracy.c.

References out.

Referenced by main().

◆ host_probe()

static void host_probe ( const float *const  in,
float *const  out,
const int  n,
const op_t  op 
)
static

Definition at line 112 of file opencl-math-accuracy.c.

References i, n, OP_DIV, OP_ERF, OP_EXP, OP_GELU, OP_LOG, OP_POW, OP_SQRT, OP_TANH, out, and x.

Referenced by main().

◆ main()

◆ max_error()

static double max_error ( const float *const  got,
const float *const  in,
const int  n,
const op_t  op 
)
static

Definition at line 178 of file opencl-math-accuracy.c.

References i, n, and reference().

Referenced by dt_iop_channelmixer_shared_roundtrip_error(), and main().

◆ print_header()

static void print_header ( void  )
static

Definition at line 200 of file opencl-math-accuracy.c.

References i, N_OPS, and OP_NAME.

Referenced by main().

◆ reference()

Variable Documentation

◆ KERNEL_SRC

const char* KERNEL_SRC
static
Initial value:
=
"__kernel void probe(__global const float *in, __global float *out, const int op)\n"
"{\n"
" const int i = get_global_id(0);\n"
" const float x = in[i];\n"
" float r;\n"
" switch(op)\n"
" {\n"
" case 0: r = erf(x); break;\n"
" case 1: r = 0.5f * x * (1.0f + erf(x * 0.70710678118654752f)); break;\n"
" case 2: r = exp(x); break;\n"
" case 3: r = log(fabs(x) + 1.0f); break;\n"
" case 4: r = tanh(x); break;\n"
" case 5: r = pow(fabs(x) + 1.0f, 2.4f); break;\n"
" case 6: r = sqrt(fabs(x)); break;\n"
" case 7: r = 1.0f / (fabs(x) + 1.0f); break;\n"
" default: r = x; break;\n"
" }\n"
" out[i] = r;\n"
"}\n"

Definition at line 67 of file opencl-math-accuracy.c.

Referenced by main().

◆ OP_NAME

const char* OP_NAME[N_OPS] = { "erf", "GELU", "exp", "log", "tanh", "pow", "sqrt", "divide" }
static

Definition at line 90 of file opencl-math-accuracy.c.

Referenced by print_header().

◆ OPTION_SETS

const option_set_t OPTION_SETS[]
static
Initial value:
= {
{ "", "(none)", 0 },
{ "-cl-mad-enable", "-cl-mad-enable", 0 },
{ "-cl-no-signed-zeros", "-cl-no-signed-zeros", 0 },
{ "-cl-denorms-are-zero", "-cl-denorms-are-zero", 0 },
{ "-cl-finite-math-only", "-cl-finite-math-only", 0 },
{ "-cl-unsafe-math-optimizations", "-cl-unsafe-math-optimizations", 0 },
{ "-cl-fast-relaxed-math", "-cl-fast-relaxed-math", 0 },
{ "-cl-mad-enable -cl-no-signed-zeros", "SAFE SET (mad-enable + no-signed-zeros)", 0 },
{ "-cl-fast-relaxed-math -cl-no-signed-zeros -cl-unsafe-math-optimizations",
"ANSEL LEGACY DEFAULT (fast-relaxed + unsafe)", 1 },
}

Definition at line 142 of file opencl-math-accuracy.c.

Referenced by main().