interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / gpu_dnn_activations_ref.h

25 lines · 1165 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#ifndef GPU_DNN_ACTIVATIONS_REF_H
3#define GPU_DNN_ACTIVATIONS_REF_H
4#include <math.h>
5#include <stdint.h>
6#include <string.h>
7/* Oracle only: double libm; no polynomial or emitted-kernel helper reused. */
8static double da_input(const void *p,size_t i,unsigned dtype) {
9 if (!dtype) return ((const float *)p)[i];
10 uint16_t u=((const uint16_t *)p)[i];
11 if (dtype==1) { uint32_t v=(uint32_t)u<<16;float f;memcpy(&f,&v,4);return f; }
12 int exponent=(u>>10)&31; unsigned mantissa=u&1023;
13 double value=exponent ? ldexp(1.0+(double)mantissa/1024.0,exponent-15) : ldexp((double)mantissa,-24);
14 return u&32768 ? -value : value;
15}
16static double da_reference(double x,unsigned op) {
17 if (op==0) return x<0.0 ? 0.0 : x;
18 if (op==1) return x*0.5*erfc(-x/sqrt(2.0)); /* erfc avoids negative-tail cancellation. */
19 if (op==2) return x*0.5*(1.0+tanh(sqrt(2.0/acos(-1.0))*(x+0.044715*x*x*x)));
20 return x>=0.0 ? x/(1.0+exp(-x)) : x*exp(x)/(1.0+exp(x));
21}
22static int da_equal(float got,double want) {
23 return isfinite(got) && fabs((double)got-want)<=0.000003+0.000003*fabs(want);
24}
25#endif