Adding some datatype stuff
This commit was SVN r170.
Этот коммит содержится в:
родитель
77ace57c5a
Коммит
c7361d0a1f
26
src/mpi/datatype/Makefile.am
Обычный файл
26
src/mpi/datatype/Makefile.am
Обычный файл
@ -0,0 +1,26 @@
|
||||
# -*- makefile -*-
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
noinst_LTLIBRARIES = libdatatype.la
|
||||
|
||||
# Source code files
|
||||
|
||||
headers = \
|
||||
datatype.h
|
||||
|
||||
liblfc_la_SOURCES = \
|
||||
$(headers) \
|
||||
datatype.c
|
||||
|
||||
# Conditionally install the header files
|
||||
|
||||
if WANT_INSTALL_HEADERS
|
||||
lamdir = $(includedir)/lam/lam/datatype
|
||||
lam_HEADERS = $(headers)
|
||||
else
|
||||
lamdir = $(includedir)
|
||||
endif
|
161
src/mpi/datatype/datatype.c
Обычный файл
161
src/mpi/datatype/datatype.c
Обычный файл
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#include "mpi/p2p/base/cdi.h"
|
||||
|
||||
lam_class_info_t lam_datatype_cls = {
|
||||
"lam_datatype_t",
|
||||
&lam_dbl_item_cls,
|
||||
(class_init_t) lam_p2p_cdi_init,
|
||||
(class_destroy_t) lam_p2p_cdi_destroy
|
||||
};
|
||||
|
||||
static int lam_datatype_init = 0;
|
||||
lam_dbl_list_t lam_p2p_cdis;
|
||||
|
||||
|
||||
void lam_datatype_t(lam_p2p_cdi_t* cdi)
|
||||
{
|
||||
if(fetchNset(&lam_p2p_cdis_init,1) == 0) {
|
||||
lam_dbl_init(&lam_p2p_cdis);
|
||||
}
|
||||
lam_dbl_item_init(&cdi->cdi_base);
|
||||
cdi->cdi_name = 0;
|
||||
cdi->cdi_id = lam_dbl_get_size(&lam_p2p_cdis) + 1;
|
||||
cdi->cdi_frag_first_size = 0;
|
||||
cdi->cdi_frag_min_size = 0;
|
||||
cdi->cdi_frag_max_size = 0;
|
||||
cdi->cdi_endpoint_latency = 0;
|
||||
cdi->cdi_endpoint_bandwidth = 0;
|
||||
cdi->cdi_endpoint_count = 0;
|
||||
lam_dbl_init(&cdi->cdi_incomplete_sends);
|
||||
lam_dbl_append(&lam_p2p_cdis, &cdi->cdi_base);
|
||||
}
|
||||
|
||||
|
||||
void lam_p2p_cdi_destroy(lam_p2p_cdi_t* cdi)
|
||||
{
|
||||
lam_dbl_remove(&lam_p2p_cdis, &cdi->cdi_base);
|
||||
lam_dbl_destroy(&cdi->cdi_incomplete_sends);
|
||||
lam_dbl_item_destroy(&cdi->cdi_base);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This random stuff checked in while I think about things ...
|
||||
*/
|
||||
|
||||
/*!
|
||||
* type_pack -- Incrementally copy data type arrays to/from a packed buffer
|
||||
*
|
||||
* @param pack direction of copy: PACK or UNPACK
|
||||
* @param buf buffer to pack into/unpack from
|
||||
* @param bufsize size of buffer
|
||||
* @param offset pointer to current byte offset into the buffer
|
||||
* @param typebuf array of types
|
||||
* @param ntype size of type array
|
||||
* @param type type descriptor
|
||||
* @param type_index pointer to index of current type
|
||||
* @param map_index pointer to index of current type map
|
||||
* @param map_offset pointer to byte offset into current type map
|
||||
* @return 0 if pack/unpack is complete, non-zero otherwise
|
||||
*
|
||||
* Incrementally copy data type arrays to/from a packed buffer. by
|
||||
* iterating over the type and type_map until we finish or run out of
|
||||
* room.
|
||||
*
|
||||
* The contents of type_index, map_index and map_offset should be
|
||||
* initialized to 0 before the first call.
|
||||
*/
|
||||
|
||||
enum {
|
||||
TYPE_PACK_PACK = 0,
|
||||
TYPE_PACK_UNPACK,
|
||||
TYPE_PACK_COMPLETE = 0,
|
||||
TYPE_PACK_INCOMPLETE_VECTOR,
|
||||
TYPE_PACK_INCOMPLETE_TYPE,
|
||||
TYPE_PACK_INCOMPLETE_TYPE_MAP
|
||||
};
|
||||
|
||||
enum lam_packer_direction_t {
|
||||
LAM_PACKER_PACK = 0,
|
||||
LAM_PACKER_UNPACK,
|
||||
};
|
||||
|
||||
enum lam_packer_status_t {
|
||||
TYPE_PACK_COMPLETE = 0,
|
||||
TYPE_PACK_INCOMPLETE_VECTOR,
|
||||
TYPE_PACK_INCOMPLETE_TYPE,
|
||||
TYPE_PACK_INCOMPLETE_TYPE_MAP
|
||||
};
|
||||
|
||||
struct lam_packer_state_t {
|
||||
int do_checksum;
|
||||
int do_crc;
|
||||
size_t current_datatype;
|
||||
size_t current_repeat;
|
||||
size_t current_element;
|
||||
size_t *current_offset;
|
||||
lam_checksum_t checksum;
|
||||
lam_crc_t crc;
|
||||
};
|
||||
|
||||
/*!
|
||||
* lam_datatype_copy - Copy (the contents of) an array of data types
|
||||
*
|
||||
* @param dest output data type array
|
||||
* @param src input data type array
|
||||
* @param count size of array
|
||||
* @param type type descriptor
|
||||
*/
|
||||
lam_packer_status_t lam_packer(lam_packer_direction_t direction,
|
||||
void *buf,
|
||||
size_t bufsize,
|
||||
size_t *offset,
|
||||
void *typebuf,
|
||||
size_t ntype,
|
||||
lam_datatype_t *datatype,
|
||||
lam_pack_state_t *pack_state,
|
||||
lam_checksum_t *checksum)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* lam_datatype_copy - Copy (the contents of) an array of data types
|
||||
*
|
||||
* @param dest output data type array
|
||||
* @param src input data type array
|
||||
* @param count size of array
|
||||
* @param type type descriptor
|
||||
*/
|
||||
void lam_datatype_copy(void *dest,
|
||||
const void *src,
|
||||
size_t count,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum)
|
||||
{
|
||||
if (datatype == NULL) {
|
||||
memmove(dest, src, count);
|
||||
} else if (datatype->layout == CONTIGUOUS) {
|
||||
memmove(dest, src, count * datatype->extent);
|
||||
} else {
|
||||
unsigned char *p = ((unsigned char *) dest);
|
||||
unsigned char *q = ((unsigned char *) src);
|
||||
int map;
|
||||
|
||||
while (count--) {
|
||||
for (map = 0; map < datatype->num_pairs; map++) {
|
||||
memmove(p + datatype->type_map[map].offset,
|
||||
q + datatype->type_map[map].offset,
|
||||
datatype->type_map[map].size);
|
||||
}
|
||||
p += datatype->extent;
|
||||
q += datatype->extent;
|
||||
}
|
||||
}
|
||||
}
|
339
src/mpi/datatype/datatype.h
Обычный файл
339
src/mpi/datatype/datatype.h
Обычный файл
@ -0,0 +1,339 @@
|
||||
/*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
/** @file */
|
||||
|
||||
/*
|
||||
* LAM internal data type representation
|
||||
*/
|
||||
|
||||
#ifndef LAM_DATATYPE_H_INCLUDED
|
||||
#define LAM_DATATYPE_H_INCLUDED 1
|
||||
|
||||
/* typedefs ***********************************************************/
|
||||
|
||||
typedef enum lam_checksum_kind_t lam_checksum_kind_t;
|
||||
typedef enum lam_checksum_kind_t lam_checksum_kind_t;
|
||||
typedef enum lam_datatype_creator_t lam_dtype_creator_t;
|
||||
typedef enum lam_datatype_state_t lam_datatype_state_t;
|
||||
typedef struct lam_checksum_t lam_checksum_t;
|
||||
typedef struct lam_datatype_t lam_datatype_t;
|
||||
typedef struct lam_datatype_t lam_datatype_t;
|
||||
typedef struct lam_datavec_element_t lam_datavec_element_t;
|
||||
typedef struct lam_datavec_t lam_datavec_t;
|
||||
typedef struct lam_dataxdr_t lam_dataxdr_t;
|
||||
|
||||
|
||||
/* enums **************************************************************/
|
||||
|
||||
/**
|
||||
* Datatype state flags
|
||||
*/
|
||||
enum lam_datatype_state_t {
|
||||
LAM_DATATYPE_STATE_COMMITTED = 1 << 0,
|
||||
LAM_DATATYPE_STATE_FORTRAN = 1 << 1,
|
||||
LAM_DATATYPE_STATE_OPTIMIZED = 1 << 2,
|
||||
LAM_DATATYPE_STATE_DONT_OPTIMIZE = 1 << 3,
|
||||
LAM_DATATYPE_STATE_XDR = 1 << 4,
|
||||
/* etc. */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Enumeration of datatype creation functions
|
||||
*/
|
||||
enum lam_datatype_kind_t {
|
||||
|
||||
LAM_DATATYPE_KIND_BASIC = 0,
|
||||
|
||||
LAM_DATATYPE_KIND_CONTIG,
|
||||
LAM_DATATYPE_KIND_DUP,
|
||||
LAM_DATATYPE_KIND_HINDEXED,
|
||||
LAM_DATATYPE_KIND_HVECTOR,
|
||||
LAM_DATATYPE_KIND_INDEXED,
|
||||
LAM_DATATYPE_KIND_LB,
|
||||
LAM_DATATYPE_KIND_PACKED,
|
||||
LAM_DATATYPE_KIND_STRUCT,
|
||||
LAM_DATATYPE_KIND_UB,
|
||||
LAM_DATATYPE_KIND_VECTOR,
|
||||
|
||||
LAM_DATATYPE_KIND_CONTIG_FORTRAN,
|
||||
LAM_DATATYPE_KIND_HINDEXED_FORTRAN,
|
||||
LAM_DATATYPE_KIND_HVECTOR_FORTRAN,
|
||||
LAM_DATATYPE_KIND_INDEXED_FORTRAN,
|
||||
LAM_DATATYPE_KIND_STRUCT_FORTRAN,
|
||||
LAM_DATATYPE_KIND_VECTOR_FORTRAN
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* lam_checksum_kind_t - checksum types
|
||||
*/
|
||||
enum lam_checksum_kind_t {
|
||||
LAM_CHECKSUM_KIND_NONE = 0,
|
||||
LAM_CHECKSUM_KIND_CRC32,
|
||||
LAM_CHECKSUM_KIND_SUM32,
|
||||
LAM_CHECKSUM_KIND_SUM64
|
||||
};
|
||||
|
||||
|
||||
/* structs ************************************************************/
|
||||
|
||||
/**
|
||||
* Abstraction of checksum for data
|
||||
*/
|
||||
struct lam_checksum_t {
|
||||
lam_checksum_kind_t kind;
|
||||
union {
|
||||
uint64_t sum64;
|
||||
uint32_t sum32;
|
||||
uint32_t crc32;
|
||||
} sum;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Internal representation of MPI datatype
|
||||
*/
|
||||
struct lam_datatype_t {
|
||||
|
||||
lam_object_t super; /**< object super class */
|
||||
char name[MPI_MAX_OBJECT_NAME]; /**< object name */
|
||||
int flags; /**< bit flags */
|
||||
|
||||
/* cached information */
|
||||
|
||||
ssize_t lower_bound;
|
||||
size_t extent;
|
||||
size_t packed_size; /**< size in bytes, ignoring gaps */
|
||||
int nbasic; /**< number of basic elements */
|
||||
|
||||
/* optimized representation */
|
||||
|
||||
size_t datavec_size; /**< size of optimized representation */
|
||||
lam_datavec_t *datavec; /**< optimized representation (may be null) */
|
||||
|
||||
/* XDR representation */
|
||||
|
||||
size_t dataxdr_size; /**< size of XDR representation */
|
||||
lam_dataxdr_t *dataxdr; /**< XDR representation (may be null) */
|
||||
|
||||
/* full representation (c.f. MPI_Type_create_struct) */
|
||||
|
||||
struct {
|
||||
lam_datatype_kind_t kind; /**< creation function */
|
||||
int count; /**< number of blocks */
|
||||
int *blocklengths; /**< number of elements in each block */
|
||||
MPI_Aint *offset; /**< stride/displacement as appropriate */
|
||||
lam_datatype_t **types; /**< array of types (array) */
|
||||
} creator;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* An optimized representation of noncontiguous data used by packing
|
||||
* routines
|
||||
*/
|
||||
struct lam_datavec_t {
|
||||
size_t nrepeat;
|
||||
ssize_t repeat_offset;
|
||||
size_t nelement;
|
||||
lam_datavec_element_t *element;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* An element of a data type in optimized form
|
||||
*/
|
||||
struct lam_datavec_element_t {
|
||||
size_t size; /**< size in bytes of element */
|
||||
ssize_t offset; /**< offset from start of data type */
|
||||
ssize_t seq_offset; /**< offset from start of packed data type */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* XDR representation of a datatype
|
||||
*/
|
||||
struct lam_dataxdr_element_t {
|
||||
/* to be done */
|
||||
void *xdrs; /**< XDR stream */
|
||||
};
|
||||
|
||||
|
||||
/* interface **********************************************************/
|
||||
|
||||
/**
|
||||
* Checksum (the contents of) an array of data types
|
||||
*
|
||||
* @param addr Data type array
|
||||
* @param count Size of array
|
||||
* @param datatype Datatype descriptor
|
||||
* @param checksum Checksum
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int lam_datatype_checksum(const void *addr,
|
||||
size_t count,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum);
|
||||
|
||||
/**
|
||||
* Copy (the contents of) an array of data types
|
||||
*
|
||||
* @param dest Output data type array
|
||||
* @param src Input data type array
|
||||
* @param count Size of array
|
||||
* @param datatype Datatype descriptor
|
||||
* @param checksum Checksum
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int lam_datatype_copy(void *dest,
|
||||
const void *src,
|
||||
size_t count,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum);
|
||||
|
||||
/**
|
||||
* Pack state
|
||||
*
|
||||
* Structure to store the state of an incremental pack/unpack of a
|
||||
* datatype.
|
||||
*/
|
||||
struct lam_pack_state_t {
|
||||
size_t current_offset; /**< current offset into packed buffer */
|
||||
size_t current_type; /**< current index of datatype */
|
||||
size_t current_repeat; /**< current index of datavec repeat */
|
||||
size_t current_element; /**< current index of datavec element */
|
||||
size_t current_offset; /**< current offset into datavec element */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Incrementally pack an array of datatypes into a buffer
|
||||
*
|
||||
* @param state current state of the incremental pack/unpack
|
||||
* @param buf buffer to pack into/unpack from
|
||||
* @param bufsize size of buffer
|
||||
* @param typebuf array of types
|
||||
* @param ntype size of type array
|
||||
* @param datatype type descriptor
|
||||
* @param checksum checksum descriptor
|
||||
* @return 0 if complete, non-zero otherwise
|
||||
*
|
||||
* Incrementally copy data type arrays to/from a packed buffer by
|
||||
* iterating over the type and type_map until we finish or run out of
|
||||
* room.
|
||||
*
|
||||
* The state (all members) should be initialized to 0 before the first
|
||||
* call.
|
||||
*/
|
||||
int lam_datatype_pack(lam_pack_state_t *state,
|
||||
void *buf,
|
||||
size_t bufsize,
|
||||
const void *typebuf,
|
||||
size_t ntype,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum);
|
||||
|
||||
|
||||
/**
|
||||
* Incrementally unpack a buffer to an array of datatypes
|
||||
*
|
||||
* @param state current state of the incremental pack/unpack
|
||||
* @param typebuf array of types
|
||||
* @param ntype size of type array
|
||||
* @param buf buffer to pack into/unpack from
|
||||
* @param bufsize size of buffer
|
||||
* @param datatype type descriptor
|
||||
* @param checksum checksum descriptor
|
||||
* @return 0 complete, non-zero otherwise
|
||||
*
|
||||
* Incrementally copy data type arrays to/from a packed buffer by
|
||||
* iterating over the type and type_map until we finish or run out of
|
||||
* room.
|
||||
*
|
||||
* The state (all members) should be initialized to 0 before the first
|
||||
* call.
|
||||
*/
|
||||
int lam_datatype_unpack(lam_pack_state_t *state,
|
||||
void *typebuf,
|
||||
size_t ntype,
|
||||
const void *buf,
|
||||
size_t bufsize,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum);
|
||||
|
||||
|
||||
/**
|
||||
* Incrementally generate an iovec for gathering from an array of
|
||||
* datatypes
|
||||
*
|
||||
* @param state current state of the incremental pack/unpack
|
||||
* @param base_addr base address for iovec offsets
|
||||
* @param vec iovec buffer
|
||||
* @param vec_count maximum length of iovec buffer
|
||||
* @param max_bytes maximum bytes addressed by iovec
|
||||
* @param buf buffer to pack into/unpack from
|
||||
* @param bufsize size of buffer
|
||||
* @param typebuf array of types
|
||||
* @param ntype size of type array
|
||||
* @param type type descriptor
|
||||
* @return 0 if complete, non-zero otherwise
|
||||
*
|
||||
* Incrementally traverse an array of datatypes and generate an iovec
|
||||
* of at most length vec_count and addressing at most max_bytes. This
|
||||
* can be used to do a (partial) RDMA gather of the datatype array.
|
||||
*
|
||||
* The state (all members) should be initialized to 0 before the first
|
||||
* call.
|
||||
*/
|
||||
int lam_datatype_gather_iovec(lam_pack_state_t *state,
|
||||
void *base_addr,
|
||||
struct iovec *vec,
|
||||
size_t vec_count,
|
||||
size_t max_bytes,
|
||||
const void *typebuf,
|
||||
size_t ntype,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum);
|
||||
|
||||
/**
|
||||
* Incrementally generate an iovec for scattering from a packed array
|
||||
* of datatypes
|
||||
*
|
||||
* @param state current state of the incremental pack/unpack
|
||||
* @param base_addr base address for iovec offsets
|
||||
* @param vec iovec buffer
|
||||
* @param vec_count maximum length of iovec buffer
|
||||
* @param max_bytes maximum bytes addressed by iovec
|
||||
* @param buf packed buffer
|
||||
* @param bufsize size of buffer
|
||||
* @param typebuf array of types
|
||||
* @param ntype size of type array
|
||||
* @param type type descriptor
|
||||
* @return 0 if complete, non-zero otherwise
|
||||
*
|
||||
* Incrementally copy data type arrays to/from a packed buffer. by
|
||||
* iterating over the type and type_map until we finish or run out of
|
||||
* room.
|
||||
*
|
||||
* Incrementally traverse a packed array of datatypes and generate an
|
||||
* iovec of at most length vec_count and addressing at most max_bytes.
|
||||
* This can be used to do a (partial) RDMA scatter of the datatype
|
||||
* array.
|
||||
*
|
||||
* The state (all members) should be initialized to 0 before the first
|
||||
* call.
|
||||
*/
|
||||
int lam_datatype_scatter_iovec(lam_pack_state_t *state,
|
||||
void *base_addr,
|
||||
struct iovec *vec,
|
||||
size_t vec_count,
|
||||
size_t max_bytes,
|
||||
const void *buf,
|
||||
size_t bufsize,
|
||||
lam_datatype_t *datatype,
|
||||
lam_checksum_t *checksum);
|
||||
|
||||
#endif /* LAM_DATATYPE_H_INCLUDED */
|
Загрузка…
x
Ссылка в новой задаче
Block a user