|
NEP 4.3.0
NetCDF Expansion Pack
|
#include "config.h"#include "nep.h"#include "nxcdf/nxcdf.h"#include <stdlib.h>#include <string.h>Functions | |
| static uint16_t | f32_to_bf16 (float f, int *range) |
| static uint16_t | f64_to_bf16 (double d, int *range) |
| static float | bf16_to_f32 (uint16_t b) |
| static int | bf16_io (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, void *buf, int put) |
| int | nc_get_vars_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, nc_bfloat16_t *ip) |
| Read a strided hyperslab of a variable as bfloat16. | |
| int | nc_put_vars_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const nc_bfloat16_t *op) |
| Write a strided hyperslab of a variable from bfloat16 values. | |
| int | nc_get_vara_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, nc_bfloat16_t *ip) |
| Read a hyperslab of a variable as bfloat16. | |
| int | nc_put_vara_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, const nc_bfloat16_t *op) |
| Write a hyperslab of a variable from bfloat16 values. | |
| int | nc_get_var1_bfloat16 (int ncid, int varid, const size_t *indexp, nc_bfloat16_t *ip) |
| Read one value from a variable as bfloat16. | |
| int | nc_put_var1_bfloat16 (int ncid, int varid, const size_t *indexp, const nc_bfloat16_t *op) |
| Write one value to a variable as bfloat16. | |
| int | nc_get_var_bfloat16 (int ncid, int varid, nc_bfloat16_t *ip) |
| Read a whole variable as bfloat16. | |
| int | nc_put_var_bfloat16 (int ncid, int varid, const nc_bfloat16_t *op) |
| Write a whole variable from bfloat16 values. | |
This is the code file for the NEP bfloat16 I/O functions.
The nc_*_bfloat16 functions exchange bfloat16 values in memory with NC_BFLOAT16, NC_FLOAT and NC_DOUBLE variables. They are written on top of the public netCDF API, so they work with any file netCDF can open. Buffers are always accessed as bytes through memcpy, never as nc_bfloat16_t values, so the code is the same whether nc_bfloat16_t is the compiler's __bf16 or uint16_t.
|
static |
Common worker for the eight nc_*_bfloat16 functions. NC_BFLOAT16 variables are read or written as raw bits with nc_get_vars() or nc_put_vars(). NC_FLOAT and NC_DOUBLE variables go through a temporary float or double buffer and the typed nc_get_vars_* or nc_put_vars_* call, with the conversion done here.
| ncid | NetCDF file ID. |
| varid | Variable ID. |
| startp | Start index in each dimension. |
| countp | Edge count in each dimension. |
| stridep | Stride in each dimension, or NULL for a stride of 1. |
| buf | The bfloat16 buffer (read into for a get, read from for a put). |
| put | Non-zero to write, zero to read. |
|
static |
Convert a bfloat16 bit pattern to float. The conversion is exact.
| b | The bfloat16 bit pattern. |
|
static |
Convert a float to a bfloat16 bit pattern, rounding to nearest with ties to even. NaN stays a quiet NaN, as in bfloat16_conv.h.
| f | The float to convert. |
| range | Set to 1 when a finite input becomes +-inf; otherwise left unchanged. |
|
static |
Convert a double to a bfloat16 bit pattern with a single rounding (to nearest, ties to even). The double is first rounded to float with round-to-odd (an inexact result gets an odd last bit), then converted with f32_to_bf16(). float has 16 more significand bits than bfloat16, so this equals rounding the double directly.
| d | The double to convert. |
| range | Set to 1 when a finite input becomes +-inf; otherwise left unchanged. |
| int nc_get_var1_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const size_t * | indexp, | ||
| nc_bfloat16_t * | ip ) |
Read one value from a variable as bfloat16.
Read one value from a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.
| int nc_get_var_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| nc_bfloat16_t * | ip ) |
Read a whole variable as bfloat16.
Read a whole variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.
| int nc_get_vara_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const size_t * | startp, | ||
| const size_t * | countp, | ||
| nc_bfloat16_t * | ip ) |
Read a hyperslab of a variable as bfloat16.
Read a hyperslab of a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.
| int nc_get_vars_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const size_t * | startp, | ||
| const size_t * | countp, | ||
| const ptrdiff_t * | stridep, | ||
| nc_bfloat16_t * | ip ) |
Read a strided hyperslab of a variable as bfloat16.
Read a strided hyperslab of a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.
| int nc_put_var1_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const size_t * | indexp, | ||
| const nc_bfloat16_t * | op ) |
Write one value to a variable as bfloat16.
Write one value to a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.
| int nc_put_var_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const nc_bfloat16_t * | op ) |
Write a whole variable from bfloat16 values.
Write a whole variable from bfloat16 values. See nep.h for the variable types accepted and the conversion rules.
| int nc_put_vara_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const size_t * | startp, | ||
| const size_t * | countp, | ||
| const nc_bfloat16_t * | op ) |
Write a hyperslab of a variable from bfloat16 values.
Write a hyperslab of a variable from bfloat16 values. See nep.h for the variable types accepted and the conversion rules.
| int nc_put_vars_bfloat16 | ( | int | ncid, |
| int | varid, | ||
| const size_t * | startp, | ||
| const size_t * | countp, | ||
| const ptrdiff_t * | stridep, | ||
| const nc_bfloat16_t * | op ) |
Write a strided hyperslab of a variable from bfloat16 values.
Write a strided hyperslab of a variable from bfloat16 values. See nep.h for the variable types accepted and the conversion rules.