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 / src / runtime / rx_cm_math.h

38 lines · 1529 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#ifndef RX_CM_MATH_H
3#define RX_CM_MATH_H
4#include "cudapp_native.h"
5#include <math.h>
6#include <stdint.h>
7#include <string.h>
8#ifndef CUDAPP_MIGRATION_PENDING_C_CM_MATH
9#define CUDAPP_MIGRATION_PENDING_C_CM_MATH 0
10#endif
11#if !CUDAPP_MIGRATION_PENDING_C_CM_MATH
12/* Binary64 transport only. Numerical computation and exceptional-value policy
13 * are in the first-party Omega unit, not a host libm call. */
14static inline double rx_host_math(unsigned mode, double x) {
15 uint64_t input, output;
16 memcpy(&input, &x, sizeof input);
17 if (omega_cm_math(&output, mode, input) != OMEGA_OK) return NAN;
18 memcpy(&x, &output, sizeof x);
19 return x;
20}
21static inline double rx_host_log(double x) { return rx_host_math(0, x); }
22static inline double rx_host_log2(double x) { return rx_host_math(1, x); }
23static inline double rx_host_ceil(double x) { return rx_host_math(2, x); }
24static inline double rx_host_exp(double x) { return rx_host_math(3, x); }
25static inline double rx_host_exp2(double x) { return rx_host_math(4, x); }
26static inline double rx_host_sqrt(double x) { return rx_host_math(5, x); }
27static inline double rx_host_erfc(double x) { return rx_host_math(6, x); }
28static inline double rx_host_fabs(double x) { return rx_host_math(7, x); }
29#define log rx_host_log
30#define log2 rx_host_log2
31#define ceil rx_host_ceil
32#define exp rx_host_exp
33#define exp2 rx_host_exp2
34#define sqrt rx_host_sqrt
35#define erfc rx_host_erfc
36#define fabs rx_host_fabs
37#endif
38#endif