Skip to content

Commit

Permalink
Merge pull request #38 from texadactyl/master
Browse files Browse the repository at this point in the history
FBH5 - satisfy enhancement request in issue #19
  • Loading branch information
david-macmahon authored Dec 16, 2021
2 parents 62c3140 + 67c1e56 commit 5accb91
Show file tree
Hide file tree
Showing 11 changed files with 951 additions and 86 deletions.
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ INCDIR = $(PREFIX)/include
LIBDIR = $(PREFIX)/lib
DATADIR = $(PREFIX)/share

# Begin HDF5 definitions
INCDIR_H5= /usr/include/hdf5/serial/
#LIBDIR_h5= /usr/lib/x86_64-linux-gnu/hdf5/serial/
LIBDIR_h5= /usr/local/lib
LIBHDF5= :libhdf5.so
LIBHDF5_HL= :libhdf5_hl.so
LINKH5:= -L$(LIBDIR) -l $(LIBHDF5) -l $(LIBHDF5_HL)
# End HDF5 definitions

CUDA_DIR ?= $(CUDA_ROOT)
CUDA_PATH ?= $(CUDA_DIR)

Expand All @@ -13,7 +22,7 @@ CXX ?= g++
HOST_COMPILER ?= $(CXX)
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)

CFLAGS = -ggdb -fPIC -I$(CUDA_PATH)/include
CFLAGS = -ggdb -fPIC -I$(CUDA_PATH)/include -I$(INCDIR_H5)
ifdef DEBUG_CALLBACKS
CFLAGS += -DDEBUG_CALLBACKS=$(DEBUG_CALLBACKS)
endif
Expand Down Expand Up @@ -66,14 +75,21 @@ rawspec_socket.o: rawspec_socket.h rawspec.h \
rawspectest.o: rawspec.h
rawspec_rawutils.o: rawspec_rawutils.h hget.h

# Begin fbh5 objects
fbh5_open.o: fbh5_defs.h rawspec_callback.h rawspec_fbutils.h
fbh5_close.o: fbh5_defs.h rawspec_callback.h rawspec_fbutils.h
fbh5_write.o: fbh5_defs.h rawspec_callback.h rawspec_fbutils.h
fbh5_util.o: fbh5_defs.h rawspec_callback.h rawspec_fbutils.h
# End fbh5 objects

%.o: %.cu
$(VERBOSE) $(NVCC) $(NVCC_FLAGS) -dc $(GENCODE_FLAGS) -o $@ -c $<

librawspec.so: rawspec_gpu.o rawspec_fbutils.o rawspec_rawutils.o
$(VERBOSE) $(NVCC) -shared $(NVCC_FLAGS) $(GENCODE_FLAGS) -o $@ $^ $(CUDA_STATIC_LIBS)
librawspec.so: rawspec_gpu.o rawspec_fbutils.o rawspec_rawutils.o fbh5_open.o fbh5_close.o fbh5_write.o fbh5_util.o
$(VERBOSE) $(NVCC) -shared $(NVCC_FLAGS) $(GENCODE_FLAGS) -o $@ $^ $(CUDA_STATIC_LIBS) $(LINKH5)

rawspec: librawspec.so
rawspec: rawspec.o rawspec_file.o rawspec_socket.o
rawspec: rawspec.o rawspec_file.o rawspec_socket.o
$(VERBOSE) $(NVCC) $(NVCC_FLAGS) $(GENCODE_FLAGS) -o $@ $^ -L. -lrawspec

rawspectest: librawspec.so
Expand Down
69 changes: 69 additions & 0 deletions fbh5_close.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* fbh5_close.c *
* ---------- *
* Close an FBH5 writing session: . *
* Dataspace, Dataset, and File (in that order). *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


#include "fbh5_defs.h"
#define MILLION 1000000.0


/***
Main entry point.
***/
void fbh5_close(fbh5_context_t * p_fbh5_ctx, int debug_callback) {
herr_t status; // Status from HDF5 function call
hsize_t sz_store; // Storage size
double MiBstore; // sz_store converted to MiB
double MiBlogical; // sz_store converted to MiB

sz_store = H5Dget_storage_size(p_fbh5_ctx->dataset_id);
MiBlogical = (double) p_fbh5_ctx->tint_size * (double) p_fbh5_ctx->offset_dims[0] / MILLION;

/*
* Attach "dimension scale" labels.
*/
fbh5_set_ds_label(p_fbh5_ctx, "time", 0, debug_callback);
fbh5_set_ds_label(p_fbh5_ctx, "feed_id", 1, debug_callback);
fbh5_set_ds_label(p_fbh5_ctx, "frequency", 2, debug_callback);

/*
* Close dataspace.
*/
status = H5Sclose(p_fbh5_ctx->dataspace_id);
if(status != 0)
fbh5_oops(__FILE__, __LINE__, "fbh5_close H5Sclose dataspace FAILED\n");

/*
* Close dataset.
*/
status = H5Dclose(p_fbh5_ctx->dataset_id);
if(status != 0)
fbh5_oops(__FILE__, __LINE__, "fbh5_close H5Dclose dataset 'data' FAILED\n");

/*
* Close file.
*/
status = H5Fclose(p_fbh5_ctx->file_id);
if(status != 0)
fbh5_oops(__FILE__, __LINE__, "fbh5_close H5Fclose FAILED\n");
p_fbh5_ctx->active = 0;

/*
* Closing statistics.
*/
if(debug_callback) {
printf("fbh5_close: Context closed.\n");
printf("fbh5_close: %ld dumps processed.\n", p_fbh5_ctx->dump_count);
printf("fbh5_close: %lld time integrations processed.\n", p_fbh5_ctx->offset_dims[0]);
MiBstore = (double) sz_store / MILLION;
printf("fbh5_close: Compressed %.2f MiB --> %.2f MiB\n", MiBlogical, MiBstore);
}

/*
* Bye-bye.
*/
}

60 changes: 60 additions & 0 deletions fbh5_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* fbh5_defs.h *
* ----------- *
* Global Definitions . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef FBH5_DEFS_H
#define FBH5_DEFS_H

#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <sys/types.h>
#include <string.h>
#include <time.h>

/*
* HDF5 library definitions
*/
#include <hdf5/serial/hdf5.h>
#include <hdf5/serial/H5pubconf.h>
#include <hdf5/serial/H5DSpublic.h>
#ifndef H5_HAVE_THREADSAFE
#error The installed HDF5 run-time is not thread-safe!
#endif

/*
* Rawspec callback definitions
*/
#include "rawspec_callback.h"

/*
* Global definitions
*/
#define DATASETNAME "data" // FBH5 dataset name to hold the data matrix
#define NDIMS 3 // # of data matrix dimensions (rank)
#define FILTERBANK_CLASS "FILTERBANK" // File-level attribute "CLASS"
#define FILTERBANK_VERSION "2.0" // File-level attribute "VERSION"
#define ENABLER_FD_FOR_FBH5 42 // Fake fd value to enable dump_file_thread_func()

/*
* fbh5 API functions
*/
void fbh5_open(fbh5_context_t * p_fbh5_ctx, fb_hdr_t * p_fb_hdr, char * output_path, int debug_callback);
void fbh5_write(fbh5_context_t * p_fbh5_ctx, fb_hdr_t * p_fb_hdr, void * buffer, size_t bufsize, int debug_callback);
void fbh5_close(fbh5_context_t * p_fbh5_ctx, int debug_callback);

/*
* fbh5_util.c functions
*/
void fbh5_oops(char * srcfile, int linenum, char * msg);
void fbh5_set_str_attr(hid_t file_or_dataset_id, char * tag, char * value, int debug_callback);
void fbh5_set_dataset_double_attr(hid_t dataset_id, char * tag, double * p_value, int debug_callback);
void fbh5_set_dataset_int_attr(hid_t dataset_id, char * tag, int * p_value, int debug_callback);
void fbh5_write_metadata(hid_t dataset_id, fb_hdr_t * p_metadata, int debug_callback);
void fbh5_set_ds_label(fbh5_context_t * p_fbh5_ctx, char * label, int dims_index, int debug_callback);
void fbh5_show_context(char * caller, fbh5_context_t * p_fbh5_ctx);

#endif

Loading

0 comments on commit 5accb91

Please sign in to comment.