|
NEP 4.3.0
NetCDF Expansion Pack
|
Benchmark NC_FLOAT vs NC_BFLOAT16 write and read time on data already in bfloat16, with no conversion. More...
#include <netcdf.h>#include <nep.h>#include "nxcdf/nxcdf.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <sys/stat.h>#include "bfloat16_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 "bfloat16_io_perf_tmp.nc" |
| #define | ERRCODE 2 |
| #define | ERR(e) |
Functions | |
| static double | get_time (void) |
| Return current wall-clock time in seconds. | |
| static int | run_config (const char *field, const void *data, int is_bf16, int deflate, row_t *row, void *rbuf) |
| 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_BFLOAT16 write and read time on data already in bfloat16, with no conversion.
Unlike bfloat16_perf.c, which times the float32 to bfloat16 conversion as part of the write and read, this benchmark measures pure I/O: it writes and reads the four GDAS surface fields (tmp2m, prate_ave, soilw1, land) in four configurations: (float, contiguous), (bfloat16, contiguous), (float, deflate level 1 with shuffle) and (bfloat16, deflate level 1 with shuffle). The bfloat16 data come from test/data/NXCDF/gdas_sfc_sample_bfloat16.nc, a bfloat16 copy of the GDAS sample made by make_bfloat16_sample.c, so the timed regions contain no conversion at all. 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 program first checks that the bfloat16 sample's stored bits are exactly float_to_bfloat16() of the float sample's values, fill points included, and fails if they are not.
Write time runs from nc_create() 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(). Both times cover the whole file (all NCOPIES steps). Timing uses clock_gettime(CLOCK_MONOTONIC). Every read is checked bit-for-bit against the data written.
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. write_MBps and read_MBps are MB/s of float32 data (NCOPIES x 4718592 bytes) for every row, so the speeds compare the same user data. ratio_vs_float is the (float, same storage) file_bytes divided by this row's; write_speedup and read_speedup are the (float, same storage) times divided by this row's. They are 1.000 for the float rows. Each row is also printed to stdout.
Typical workflow:
Learning Objectives:
Key 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 "bfloat16_io_perf_tmp.nc" |
Temporary NetCDF file created for each measurement.
|
static |
Return current wall-clock time in seconds.
| int main | ( | int | argc, |
| char ** | argv ) |
Main entry point.
For each of the four GDAS fields, reads the float32 data from the float sample and the bfloat16 bits from the bfloat16 sample, verifies the bits are float_to_bfloat16() of the floats, runs the four configurations (float/bfloat16 x contiguous/deflate1) and appends one CSV row per configuration to the output file, printing each to stdout.
| argc | Argument count; must be 4. |
| argv | argv[1] is gdas_sfc_sample.nc, argv[2] gdas_sfc_sample_bfloat16.nc, argv[3] 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 with no fill value (nc_def_var_fill NC_NOFILL for both types, so the float and bfloat16 files match), optionally chunked 1x768x1536 with shuffle and deflate level 1, writes the data once per time step with nc_put_vara_float() or nc_put_vara_bfloat16(), closes and fsyncs the file (timed), stats it, drops it from the page cache (untimed), reopens it, reads the data back and checks the bits with memcmp(). There is no conversion in either timed region. The minimum write and read times and the last repetition's file size are returned in row.
| field | Field name (used as the variable name). |
| data | Input data (NVALS floats or uint16_t bfloat16 bits). |
| is_bf16 | Non-zero for an NC_BFLOAT16 variable. |
| deflate | Non-zero for shuffle+deflate level 1. |
| row | Result row to fill in. |
| rbuf | Scratch buffer of at least NCOPIES*NVALS*4 bytes. |
|
static |
Field names in the GDAS sample.