Skip to content

Commit

Permalink
Combine compact I/O read/write struct into single I/O struct
Browse files Browse the repository at this point in the history
Rename CTL memory copy flag and H5Fquery routine to get file driver
structure
  • Loading branch information
jhendersonHDF committed Sep 29, 2021
1 parent ea6174c commit 1b2fc54
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 114 deletions.
157 changes: 54 additions & 103 deletions src/H5Dcompact.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,19 @@
/* Local Typedefs */
/******************/

/* Callback info for readvv operation when file driver
* uses special memory management functions
/* Callback info for I/O operation when file driver
* wishes to do its own memory management
*/
typedef struct H5D_compact_readvv_special_mem_ud_t {
H5F_shared_t *f_sh; /* Shared file for dataset */
void * rbuf; /* Pointer to buffer to be read from */
void * dstbuf; /* Pointer to buffer to be read into */
} H5D_compact_readvv_special_mem_ud_t;

/* Callback info for writevv operation when file driver
* uses special memory management functions
*/
typedef struct H5D_compact_writevv_special_mem_ud_t {
H5F_shared_t *f_sh; /* Shared file for dataset */
const void * wbuf; /* Pointer to buffer to be written from */
void * dstbuf; /* Pointer to buffer to be written into */
} H5D_compact_writevv_special_mem_ud_t;
typedef struct H5D_compact_iovv_memmanage_ud_t {
H5D_io_op_type_t op_type; /* I/O op type (read/write) */
H5F_shared_t * f_sh; /* Shared file for dataset */
void * dstbuf; /* Pointer to buffer to be read into/written into */
union {
/* Pointer to buffer to be read from/written from */
void * srcbuf;
const void *const_srcbuf;
} u;
} H5D_compact_iovv_memmanage_ud_t;

/********************/
/* Local Prototypes */
Expand All @@ -75,11 +71,10 @@ static hbool_t H5D__compact_is_space_alloc(const H5O_storage_t *storage);
static herr_t H5D__compact_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_info,
hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space,
H5D_chunk_map_t *cm);
static herr_t H5D__compact_readvv_special_mem_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata);
static herr_t H5D__compact_iovv_memmanage_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata);
static ssize_t H5D__compact_readvv(const H5D_io_info_t *io_info, size_t dset_max_nseq, size_t *dset_curr_seq,
size_t dset_size_arr[], hsize_t dset_offset_arr[], size_t mem_max_nseq,
size_t *mem_curr_seq, size_t mem_size_arr[], hsize_t mem_offset_arr[]);
static herr_t H5D__compact_writevv_special_mem_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata);
static ssize_t H5D__compact_writevv(const H5D_io_info_t *io_info, size_t dset_max_nseq, size_t *dset_curr_seq,
size_t dset_size_arr[], hsize_t dset_offset_arr[], size_t mem_max_nseq,
size_t *mem_curr_seq, size_t mem_size_arr[], hsize_t mem_offset_arr[]);
Expand Down Expand Up @@ -260,48 +255,46 @@ H5D__compact_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t H5_ATTR
} /* end H5D__compact_io_init() */

/*-------------------------------------------------------------------------
* Function: H5D__compact_readvv_special_mem_cb
* Function: H5D__compact_iovv_memmanage_cb
*
* Purpose: Callback operator for H5D__compact_readvv() to send a
* memory copy request to the underlying file driver.
* Purpose: Callback operator for H5D__compact_readvv()/_writevv() to
* send a memory copy request to the underlying file driver.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5D__compact_readvv_special_mem_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata)
H5D__compact_iovv_memmanage_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata)
{
H5D_compact_readvv_special_mem_ud_t *udata = (H5D_compact_readvv_special_mem_ud_t *)_udata;
H5FD_ctl_memcpy_args_t op_args;
uint64_t op_flags;
H5FD_t *file_handle = NULL;
herr_t ret_value = SUCCEED;
H5D_compact_iovv_memmanage_ud_t *udata = (H5D_compact_iovv_memmanage_ud_t *)_udata;
H5FD_ctl_memcpy_args_t op_args;
uint64_t op_flags;
H5FD_t * file_handle = NULL;
herr_t ret_value = SUCCEED;

FUNC_ENTER_STATIC

/* Retrieve lower-level file handle for I/O */
if (H5F_shared_get_file_handle(udata->f_sh, &file_handle) < 0)
/* Retrieve pointer to file driver structure for ctl call */
if (H5F_shared_get_file_driver(udata->f_sh, &file_handle) < 0)
HGOTO_ERROR(H5E_IO, H5E_CANTGET, FAIL, "can't get file handle")

/* Setup operation flags and arguments */
op_flags = H5FD_CTL__ROUTE_TO_TERMINAL_VFD_FLAG |
H5FD_CTL__FAIL_IF_UNKNOWN_FLAG;
op_flags = H5FD_CTL__ROUTE_TO_TERMINAL_VFD_FLAG | H5FD_CTL__FAIL_IF_UNKNOWN_FLAG;

op_args.dstbuf = udata->dstbuf;
op_args.dst_off = dst_off;
op_args.srcbuf = udata->rbuf;
op_args.srcbuf = (udata->op_type == H5D_IO_OP_READ) ? udata->u.srcbuf : udata->u.const_srcbuf;
op_args.src_off = src_off;
op_args.len = len;

/* Make request to file driver */
if (H5FD_ctl(file_handle, H5FD_CTL__MEM_COPY, op_flags,
&op_args, NULL) < 0)
if (H5FD_ctl(file_handle, H5FD_CTL__MEM_COPY, op_flags, &op_args, NULL) < 0)
HGOTO_ERROR(H5E_IO, H5E_FCNTL, FAIL, "VFD memcpy request failed")

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__compact_readvv_special_mem_cb() */
} /* end H5D__compact_iovv_memmanage_cb() */

/*-------------------------------------------------------------------------
* Function: H5D__compact_readvv
Expand Down Expand Up @@ -332,77 +325,34 @@ H5D__compact_readvv(const H5D_io_info_t *io_info, size_t dset_max_nseq, size_t *

HDassert(io_info);

/* Check if file driver uses special memory management routines */
if (H5F_SHARED_HAS_FEATURE(io_info->f_sh, H5FD_FEAT_SPECIAL_MEMMANAGE)) {
H5D_compact_readvv_special_mem_ud_t udata;
/* Check if file driver wishes to do its own memory management */
if (H5F_SHARED_HAS_FEATURE(io_info->f_sh, H5FD_FEAT_MEMMANAGE)) {
H5D_compact_iovv_memmanage_ud_t udata;

/* Set up udata for memory copy operation */
udata.f_sh = io_info->f_sh;
udata.rbuf = io_info->store->compact.buf;
udata.dstbuf = io_info->u.rbuf;
udata.op_type = io_info->op_type;
udata.f_sh = io_info->f_sh;
udata.dstbuf = io_info->u.rbuf;
udata.u.srcbuf = io_info->store->compact.buf;

/* Request that file driver does the memory copy */
if ((ret_value = H5VM_opvv(mem_max_nseq, mem_curr_seq, mem_size_arr, mem_offset_arr,
dset_max_nseq, dset_curr_seq, dset_size_arr, dset_offset_arr, H5D__compact_readvv_special_mem_cb,
&udata)) < 0)
if ((ret_value = H5VM_opvv(mem_max_nseq, mem_curr_seq, mem_size_arr, mem_offset_arr, dset_max_nseq,
dset_curr_seq, dset_size_arr, dset_offset_arr,
H5D__compact_iovv_memmanage_cb, &udata)) < 0)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "vectorized memcpy failed")
}
else {
/* Use the vectorized memory copy routine to do actual work */
if ((ret_value = H5VM_memcpyvv(io_info->u.rbuf, mem_max_nseq, mem_curr_seq, mem_size_arr, mem_offset_arr,
io_info->store->compact.buf, dset_max_nseq, dset_curr_seq, dset_size_arr,
dset_offset_arr)) < 0)
if ((ret_value = H5VM_memcpyvv(io_info->u.rbuf, mem_max_nseq, mem_curr_seq, mem_size_arr,
mem_offset_arr, io_info->store->compact.buf, dset_max_nseq,
dset_curr_seq, dset_size_arr, dset_offset_arr)) < 0)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "vectorized memcpy failed")
}

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__compact_readvv() */

/*-------------------------------------------------------------------------
* Function: H5D__compact_writevv_special_mem_cb
*
* Purpose: Callback operator for H5D__compact_writevv() to send a
* memory copy request to the underlying file driver.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5D__compact_writevv_special_mem_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata)
{
H5D_compact_writevv_special_mem_ud_t *udata = (H5D_compact_writevv_special_mem_ud_t *)_udata;
H5FD_ctl_memcpy_args_t op_args;
uint64_t op_flags;
H5FD_t *file_handle = NULL;
herr_t ret_value = SUCCEED;

FUNC_ENTER_STATIC

/* Retrieve lower-level file handle for I/O */
if (H5F_shared_get_file_handle(udata->f_sh, &file_handle) < 0)
HGOTO_ERROR(H5E_IO, H5E_CANTGET, FAIL, "can't get file handle")

/* Setup operation flags and arguments */
op_flags = H5FD_CTL__ROUTE_TO_TERMINAL_VFD_FLAG |
H5FD_CTL__FAIL_IF_UNKNOWN_FLAG;

op_args.dstbuf = udata->dstbuf;
op_args.dst_off = dst_off;
op_args.srcbuf = udata->wbuf;
op_args.src_off = src_off;
op_args.len = len;

/* Make request to file driver */
if (H5FD_ctl(file_handle, H5FD_CTL__MEM_COPY, op_flags,
&op_args, NULL) < 0)
HGOTO_ERROR(H5E_IO, H5E_FCNTL, FAIL, "VFD memcpy request failed")

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__compact_writevv_special_mem_cb() */

/*-------------------------------------------------------------------------
* Function: H5D__compact_writevv
*
Expand Down Expand Up @@ -435,26 +385,27 @@ H5D__compact_writevv(const H5D_io_info_t *io_info, size_t dset_max_nseq, size_t

HDassert(io_info);

/* Check if file driver uses special memory management routines */
if (H5F_SHARED_HAS_FEATURE(io_info->f_sh, H5FD_FEAT_SPECIAL_MEMMANAGE)) {
H5D_compact_writevv_special_mem_ud_t udata;
/* Check if file driver wishes to do its own memory management */
if (H5F_SHARED_HAS_FEATURE(io_info->f_sh, H5FD_FEAT_MEMMANAGE)) {
H5D_compact_iovv_memmanage_ud_t udata;

/* Set up udata for memory copy operation */
udata.f_sh = io_info->f_sh;
udata.wbuf = io_info->u.wbuf;
udata.dstbuf = io_info->store->compact.buf;
udata.op_type = io_info->op_type;
udata.f_sh = io_info->f_sh;
udata.dstbuf = io_info->store->compact.buf;
udata.u.const_srcbuf = io_info->u.wbuf;

/* Request that file driver does the memory copy */
if ((ret_value = H5VM_opvv(dset_max_nseq, dset_curr_seq, dset_size_arr, dset_offset_arr,
mem_max_nseq, mem_curr_seq, mem_size_arr, mem_offset_arr, H5D__compact_writevv_special_mem_cb,
&udata)) < 0)
if ((ret_value = H5VM_opvv(dset_max_nseq, dset_curr_seq, dset_size_arr, dset_offset_arr, mem_max_nseq,
mem_curr_seq, mem_size_arr, mem_offset_arr, H5D__compact_iovv_memmanage_cb,
&udata)) < 0)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "vectorized memcpy failed")
}
else {
/* Use the vectorized memory copy routine to do actual work */
if ((ret_value = H5VM_memcpyvv(io_info->store->compact.buf, dset_max_nseq, dset_curr_seq, dset_size_arr,
dset_offset_arr, io_info->u.wbuf, mem_max_nseq, mem_curr_seq, mem_size_arr,
mem_offset_arr)) < 0)
if ((ret_value = H5VM_memcpyvv(io_info->store->compact.buf, dset_max_nseq, dset_curr_seq,
dset_size_arr, dset_offset_arr, io_info->u.wbuf, mem_max_nseq,
mem_curr_seq, mem_size_arr, mem_offset_arr)) < 0)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "vectorized memcpy failed")
}

Expand Down
12 changes: 6 additions & 6 deletions src/H5FDpublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@
*/
#define H5FD_FEAT_DEFAULT_VFD_COMPATIBLE 0x00008000
/*
* Defining H5FD_FEAT_SPECIAL_MEMMANAGE for a VFL driver means
* that the driver uses special memory management routines.
* Therefore, HDF5 should request that the driver handle any
* memory management operations that would otherwise be performed
* with standard library routines.
* Defining H5FD_FEAT_MEMMANAGE for a VFL driver means that
* the driver uses special memory management routines or wishes
* to do memory management in a specific manner. Therefore, HDF5
* should request that the driver handle any memory management
* operations when appropriate.
*/
#define H5FD_FEAT_SPECIAL_MEMMANAGE 0x00010000
#define H5FD_FEAT_MEMMANAGE 0x00010000

/* ctl function definitions: */
#define H5FD_CTL_OPC_RESERVED 512 /* Opcodes below this value are reserved for library use */
Expand Down
2 changes: 1 addition & 1 deletion src/H5Fprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ H5_DLL hbool_t H5F_shared_has_feature(const H5F_shared_t *f, unsigned feature);
H5_DLL hbool_t H5F_has_feature(const H5F_t *f, unsigned feature);
H5_DLL haddr_t H5F_shared_get_eoa(const H5F_shared_t *f_sh, H5FD_mem_t type);
H5_DLL haddr_t H5F_get_eoa(const H5F_t *f, H5FD_mem_t type);
H5_DLL herr_t H5F_shared_get_file_handle(const H5F_shared_t *f_sh, H5FD_t **file_handle);
H5_DLL herr_t H5F_shared_get_file_driver(const H5F_shared_t *f_sh, H5FD_t **file_handle);
H5_DLL herr_t H5F_get_vfd_handle(const H5F_t *file, hid_t fapl, void **file_handle);

/* File mounting routines */
Expand Down
8 changes: 4 additions & 4 deletions src/H5Fquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,16 +950,16 @@ H5F_get_eoa(const H5F_t *f, H5FD_mem_t type)
} /* end H5F_get_eoa() */

/*-------------------------------------------------------------------------
* Function: H5F_shared_get_file_handle
* Function: H5F_shared_get_file_driver
*
* Purpose: Returns a pointer to the lower-level I/O file handle of the
* Purpose: Returns a pointer to the file driver structure of the
* file's 'shared' structure.
*
* Return: file handle on success/abort on failure (shouldn't fail)
*-------------------------------------------------------------------------
*/
herr_t
H5F_shared_get_file_handle(const H5F_shared_t *f_sh, H5FD_t **file_handle)
H5F_shared_get_file_driver(const H5F_shared_t *f_sh, H5FD_t **file_handle)
{
/* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOERR
Expand All @@ -970,7 +970,7 @@ H5F_shared_get_file_handle(const H5F_shared_t *f_sh, H5FD_t **file_handle)
*file_handle = f_sh->lf;

FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5F_shared_get_file_handle() */
} /* end H5F_shared_get_file_driver() */

/*-------------------------------------------------------------------------
* Function: H5F_get_vfd_handle
Expand Down

0 comments on commit 1b2fc54

Please sign in to comment.