|
NEP 4.3.0
NetCDF Expansion Pack
|
Benchmark NC_FLOAT vs NC_FLOAT16 file size and I/O throughput on four GDAS surface fields. More...
#include <netcdf.h>#include <nep.h>#include "nxcdf/nxcdf.h"#include "nep_meta.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <sys/stat.h>#include "float16_conv.h"#include "perf_disk.h"Data Structures | |
| struct | row_t |
| One benchmark row for one field/type/storage configuration. More... | |
Macros | |
| #define | NFIELDS 4 |
| #define | NY 768 |
| #define | NX 1536 |
| #define | NVALS ((size_t)NY * NX) |
| #define | NREPS 10 |
| #define | NCOPIES 10 |
| #define | TMP_FILE "float16_perf_tmp.nc" |
| #define | ERRCODE 2 |
| #define | ERR(e) |
Enumerations | |
| enum | cfg_type_t { CFG_FLOAT , CFG_F16_USER , CFG_F16_TYPED } |
Functions | |
| static double | get_time (void) |
| Return current wall-clock time in seconds. | |
| static int | run_config (const char *field, const float *fdata, cfg_type_t type, int deflate, row_t *row, uint16_t *hdata, uint16_t *rdata, float *back) |
| Write and read one field in one configuration NREPS times. | |
| int | main (int argc, char **argv) |
| Main entry point. | |
Variables | |
| static const char * | FIELDS [NFIELDS] = {"tmp2m", "prate_ave", "soilw1", "land"} |
Benchmark NC_FLOAT vs NC_FLOAT16 file size and I/O throughput on four GDAS surface fields.
Reads tmp2m, prate_ave, soilw1 and land from the GDAS sample file test/data/netCDF-4/gdas_sfc_sample.nc and, for each field, writes and reads a nxCDF file in six configurations: (float, contiguous), (float16, contiguous), (float16_typed, contiguous), (float, deflate level 1 with shuffle), (float16, deflate level 1 with shuffle) and (float16_typed, deflate level 1 with shuffle). Each file holds NCOPIES (10) copies of the field as time steps, written and read one step at a time, so the fixed cost of creating, opening and closing a file is spread over more data. Each configuration is repeated 10 times and the minimum times are kept.
The float16 rows convert float32 to binary16 in user code and exchange raw uint16_t bits through nc_put_vara_float16() and nc_get_vara_float16(). The float16_typed rows define the same NC_FLOAT16 variable but write the float data with nc_put_vara_float() and read with nc_get_vara_float(), so the internal conversion engine does the conversion; wconv_s and rconv_s are 0. Both paths use NEP round-to-nearest-even, so they produce identical stored bits - unlike the historical bfloat16 HDF5 rows, there is no differing-rounding report. The typed path's read is the engine's convert-out path, which (issue #386) currently takes an extra full-buffer pass over the converted data.
Write time runs from just before the float32 to binary16 conversion (float16 only) through nc_close() and an fsync() of the file (nep_perf_sync_file()), so the data has reached the storage device. Before each read the file is dropped from the page cache (nep_perf_drop_cache(), untimed), so every read comes from the device. Read time runs from nc_open() through nc_close() plus the conversion back to float for float16. Both times cover the whole file (all NCOPIES steps). Timing uses clock_gettime(CLOCK_MONOTONIC). Throughput is reported in MB/s of float32 data (NCOPIES x 4718592 bytes) for every row so the speeds compare the same user data.
Output: CSV written to the path given on the command line, with columns:
copies is NCOPIES; uncompressed_bytes, file_bytes, write_s and read_s cover all copies. wconv_s is the minimum float32-to-binary16 conversion time (part of write_s) and rconv_s the minimum binary16-to-float32 conversion time (part of read_s); both are 0 for float and float16_typed rows. Each row is also printed to stdout.
Typical workflow:
Learning Objectives:
prate_ave valuesKey Concepts:
Related Examples:
| #define ERR | ( | e | ) |
| #define ERRCODE 2 |
| #define NCOPIES 10 |
Copies of the field written to (and read from) each file, as time steps, so the fixed cost of opening and closing a file is spread over more data.
| #define NFIELDS 4 |
Number of GDAS fields benchmarked.
| #define NREPS 10 |
Repetitions per configuration; the minimum time is kept.
| #define NX 1536 |
Length of the grid_xt dimension of the GDAS sample.
| #define NY 768 |
Length of the grid_yt dimension of the GDAS sample.
| #define TMP_FILE "float16_perf_tmp.nc" |
Temporary NetCDF file created for each measurement.
| enum cfg_type_t |
|
static |
Return current wall-clock time in seconds.
| int main | ( | int | argc, |
| char ** | argv ) |
Main entry point.
For each of the four GDAS fields, runs the six configurations (float/float16/float16_typed x contiguous/deflate1), appends one CSV row per configuration to the output file and prints it to stdout.
| argc | Argument count; must be 3. |
| argv | argv[1] is the input gdas_sfc_sample.nc path, argv[2] the output CSV path. |
|
static |
Write and read one field in one configuration NREPS times.
For each repetition: creates TMP_FILE with nc_create(NC_NXCDF | NC_CLOBBER), defines fixed dims time = NCOPIES, grid_yt = NY, grid_xt = NX and one variable of the field name, optionally chunked 1x768x1536 with shuffle and deflate level 1, writes the field once per time step (converting it again for each step in the CFG_F16_USER case), closes and fsyncs the file (timed), stats it, drops it from the page cache (untimed), reopens it, reads every time step back and checks it. CFG_FLOAT and CFG_F16_USER use nc_put_vara_float()/nc_put_vara_float16() and check the raw bits; CFG_F16_TYPED uses the typed float calls and checks the read floats and the stored raw bits on the last repetition. The minimum write and read times and the last repetition's file size and error metrics are returned in row.
| field | Field name (used as the variable name). |
| fdata | Input float data (NVALS elements). |
| type | Conversion path (CFG_FLOAT, CFG_F16_USER or CFG_F16_TYPED). |
| deflate | Non-zero for shuffle+deflate level 1, 0 for contiguous. |
| row | Result row to fill in. |
| hdata | Scratch buffer of NVALS uint16_t. |
| rdata | Scratch buffer of at least NCOPIES*NVALS*4 bytes. |
| back | Scratch buffer of NCOPIES*NVALS floats for the binary16 to float32 conversion. |
|
static |
Field names in the GDAS sample.