Skip to content

Commit

Permalink
Merge pull request #421 from SlideRuleEarth/cleanbuild
Browse files Browse the repository at this point in the history
code cleanup for building with latest tools
  • Loading branch information
jpswinski committed Jul 22, 2024
2 parents 20592b1 + 1694afd commit c2ffed6
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 97 deletions.
6 changes: 3 additions & 3 deletions packages/h5/H5Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ bool H5Array<T>::join(int timeout, bool throw_exception)
/*
* There is no way to do this in a portable "safe" way. The code
* below works because our target architectures are x86_64 and aarch64.
* The data pointed to by info.data is new'ed and therefore guaranteed
* to be aligned to a 16 byte boundary. The calling code is responsible
* for knowing what the data being read out of the h5 file is and
* The data pointed to by info.data is new'ed with H5CORO_DATA_ALIGNMENT alignment.
* The calling code is responsible for knowing
* what the data being read out of the h5 file is and
* providing the correct type to the template.
*/
data = reinterpret_cast<T*>(h5f->info.data);
Expand Down
60 changes: 30 additions & 30 deletions packages/h5/H5Coro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ H5Coro::Future::Future (void)
info.datasize = 0;
info.data = NULL;
info.datatype = RecordObject::INVALID_FIELD;

for(int d = 0; d < MAX_NDIMS; d++)
{
info.shape[d] = 0;
Expand All @@ -99,7 +99,7 @@ H5Coro::Future::Future (void)
H5Coro::Future::~Future (void)
{
wait(IO_PEND);
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
}

/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -147,7 +147,7 @@ H5Coro::Future::rc_t H5Coro::Future::wait (int timeout)
* Constructor
* - assumes that asset is in scope for the duration this object is in scope
*----------------------------------------------------------------------------*/
H5Coro::Context::Context (Asset* asset, const char* resource):
H5Coro::Context::Context (const Asset* asset, const char* resource):
name (NULL),
ioDriver (NULL),
l1 (IO_CACHE_L1_ENTRIES, hashL1),
Expand All @@ -167,7 +167,7 @@ H5Coro::Context::Context (Asset* asset, const char* resource):
delete [] name;
mlog(e.level(), "Failed to create H5 context: %s", e.what());
throw;
}
}
}

/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -469,12 +469,12 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
if(valtype == RecordObject::INTEGER)
{
/* Allocate Buffer of Integers */
long* tbuf = new long [info.elements];
long* tbuf = new (std::align_val_t(H5CORO_DATA_ALIGNMENT)) long [info.elements];

/* Float to Long */
if(info.datatype == RecordObject::FLOAT)
{
float* dptr = reinterpret_cast<float*>(info.data);
const float* dptr = reinterpret_cast<float*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -483,7 +483,7 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Double to Long */
else if(info.datatype == RecordObject::DOUBLE)
{
double* dptr = reinterpret_cast<double*>(info.data);
const double* dptr = reinterpret_cast<double*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -492,15 +492,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Char to Long */
else if(info.datatype == RecordObject::INT8)
{
int8_t* cptr = reinterpret_cast<int8_t*>(info.data);
const int8_t* cptr = reinterpret_cast<int8_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(cptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT8)
{
uint8_t* cptr = reinterpret_cast<uint8_t*>(info.data);
const uint8_t* cptr = info.data;
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(cptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -527,15 +527,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Short to Long */
else if(info.datatype == RecordObject::INT16)
{
int16_t* dptr = reinterpret_cast<int16_t*>(info.data);
const int16_t* dptr = reinterpret_cast<int16_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT16)
{
uint16_t* dptr = reinterpret_cast<uint16_t*>(info.data);
const uint16_t* dptr = reinterpret_cast<uint16_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -544,15 +544,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Int to Long */
else if(info.datatype == RecordObject::INT32)
{
int32_t* dptr = reinterpret_cast<int32_t*>(info.data);
const int32_t* dptr = reinterpret_cast<int32_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = dptr[i]; // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT32)
{
uint32_t* dptr = reinterpret_cast<uint32_t*>(info.data);
const uint32_t* dptr = reinterpret_cast<uint32_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = dptr[i]; // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -561,15 +561,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Long to Long */
else if(info.datatype == RecordObject::INT64)
{
int64_t* dptr = reinterpret_cast<int64_t*>(info.data);
const int64_t* dptr = reinterpret_cast<int64_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT64)
{
uint64_t* dptr = reinterpret_cast<uint64_t*>(info.data);
const uint64_t* dptr = reinterpret_cast<uint64_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<long>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -582,20 +582,20 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
}

/* Switch Buffers */
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info.data = reinterpret_cast<uint8_t*>(tbuf);
info.datasize = sizeof(long) * info.elements;
}
/* Perform Integer Type Transaltion */
else if(valtype == RecordObject::REAL)
{
/* Allocate Buffer of Integers */
double* tbuf = new double [info.elements];
/* Allocate Buffer of doubles */
double* tbuf = new (std::align_val_t(H5CORO_DATA_ALIGNMENT)) double [info.elements];

/* Float to Double */
if(info.datatype == RecordObject::FLOAT)
{
float* dptr = reinterpret_cast<float*>(info.data);
const float* dptr = reinterpret_cast<float*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -604,7 +604,7 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Double to Double */
else if(info.datatype == RecordObject::DOUBLE)
{
double* dptr = reinterpret_cast<double*>(info.data);
const double* dptr = reinterpret_cast<double*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = dptr[i]; // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -613,15 +613,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Char to Double */
else if(info.datatype == RecordObject::INT8)
{
int8_t* dptr = reinterpret_cast<int8_t*>(info.data);
const int8_t* dptr = reinterpret_cast<int8_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT8)
{
uint8_t* dptr = reinterpret_cast<uint8_t*>(info.data);
const uint8_t* dptr = info.data;
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -630,15 +630,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Short to Double */
else if(info.datatype == RecordObject::INT16)
{
int16_t* dptr = reinterpret_cast<int16_t*>(info.data);
const int16_t* dptr = reinterpret_cast<int16_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT16)
{
uint16_t* dptr = reinterpret_cast<uint16_t*>(info.data);
const uint16_t* dptr = reinterpret_cast<uint16_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -647,15 +647,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Int to Double */
else if(info.datatype == RecordObject::INT32)
{
int32_t* dptr = reinterpret_cast<int32_t*>(info.data);
const int32_t* dptr = reinterpret_cast<int32_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT32)
{
uint32_t* dptr = reinterpret_cast<uint32_t*>(info.data);
const uint32_t* dptr = reinterpret_cast<uint32_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -664,15 +664,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
/* Long to Double */
else if(info.datatype == RecordObject::INT64)
{
int64_t* dptr = reinterpret_cast<int64_t*>(info.data);
const int64_t* dptr = reinterpret_cast<int64_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
}
}
else if(info.datatype == RecordObject::UINT64)
{
uint64_t* dptr = reinterpret_cast<uint64_t*>(info.data);
const uint64_t* dptr = reinterpret_cast<uint64_t*>(info.data);
for(uint32_t i = 0; i < info.elements; i++)
{
tbuf[i] = static_cast<double>(dptr[i]); // NOLINT(clang-analyzer-core.uninitialized.Assign)
Expand All @@ -685,15 +685,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
}

/* Switch Buffers */
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info.data = reinterpret_cast<uint8_t*>(tbuf);
info.datasize = sizeof(double) * info.elements;
}

/* Check Data Valid */
if(!data_valid)
{
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info.data = NULL;
info.datasize = 0;
throw RunTimeException(CRITICAL, RTE_ERROR, "data translation failed for %s: [%d] %d --> %d", datasetname, info.typesize, (int)info.datatype, (int)valtype);
Expand Down
10 changes: 7 additions & 3 deletions packages/h5/H5Coro.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
#define H5CORO_ENABLE_FILL false
#endif

#ifndef H5CORO_DATA_ALIGNMENT
#define H5CORO_DATA_ALIGNMENT 8
#endif

/******************************************************************************
* MACRO
******************************************************************************/
Expand All @@ -86,7 +90,7 @@ namespace H5Coro
* Constants
*--------------------------------------------------------------------*/

const int MAX_NDIMS = H5CORO_MAXIMUM_DIMENSIONS;
const int MAX_NDIMS = H5CORO_MAXIMUM_DIMENSIONS;
const long EOR = -1L; // end of range - read rest of the span of a dimension
const long ALL_ROWS = EOR;
const long ALL_COLS = EOR;
Expand All @@ -99,7 +103,7 @@ namespace H5Coro
uint32_t elements; // number of elements in dataset
uint32_t typesize; // number of bytes per element
uint64_t datasize; // total number of bytes in dataset
uint8_t* data; // point to allocated data buffer
uint8_t* data; // point to allocated data buffer - must be H5CORO_DATA_ALIGNMENT aligned
RecordObject::fieldType_t datatype; // data type of elements
int64_t shape[MAX_NDIMS]; // dimensions of the data
} info_t;
Expand Down Expand Up @@ -190,7 +194,7 @@ namespace H5Coro
/* Methods */
/***********/

Context (Asset* asset, const char* resource);
Context (const Asset* asset, const char* resource);
~Context (void);

void ioRequest (uint64_t* pos, int64_t size, uint8_t* buffer, int64_t hint, bool cache);
Expand Down
18 changes: 9 additions & 9 deletions packages/h5/H5Dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Mutex H5Dataset::metaMutex;
/*----------------------------------------------------------------------------
* Constructor
*----------------------------------------------------------------------------*/
H5Dataset::H5Dataset (info_t* info, Context* context,
H5Dataset::H5Dataset (info_t* info, Context* context,
const char* dataset, const range_t* slice, int slicendims,
bool _meta_only):
ioContext (context),
Expand Down Expand Up @@ -166,7 +166,7 @@ H5Dataset::H5Dataset (info_t* info, Context* context,
catch(const RunTimeException& e)
{
/* Clean Up Data Allocations */
delete [] info->data;
operator delete [] (info->data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info->data= NULL;
info->datasize = 0;

Expand Down Expand Up @@ -296,7 +296,7 @@ void H5Dataset::readDataset (info_t* info)
(hyperslice[d].r1 > metaData.dimensions[d]) ||
(hyperslice[d].r0 < 0) )
{
throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid hyperslice at dimension %d [%ld]: [%ld, %ld)", d, metaData.dimensions[d], hyperslice[d].r0, hyperslice[d].r1);
throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid hyperslice at dimension %d [%ld]: [%ld, %ld)", d, metaData.dimensions[d], hyperslice[d].r0, hyperslice[d].r1);
}
}

Expand All @@ -319,12 +319,12 @@ void H5Dataset::readDataset (info_t* info)
const int64_t extra_space_for_terminator = (metaData.type == STRING_TYPE);

/* Allocate */
buffer = new uint8_t [buffer_size + extra_space_for_terminator];
buffer = new (std::align_val_t(H5CORO_DATA_ALIGNMENT)) uint8_t [buffer_size + extra_space_for_terminator];

/* Gaurantee Termination of String */
if(metaData.type == STRING_TYPE)
{
buffer[buffer_size] = '\0';
buffer[buffer_size] = '\0';
}

/* Fill Buffer with Fill Value (if provided) */
Expand Down Expand Up @@ -484,7 +484,7 @@ void H5Dataset::readDataset (info_t* info)
for(int d = metaData.ndims - 1; d > 0; d--)
{
chunkStepSize[d - 1] = dimensionsInChunks[d] * chunkStepSize[d];
}
}

/* Calculate position of first and last element in hyperslice */
hypersliceChunkStart = 0;
Expand Down Expand Up @@ -1286,7 +1286,7 @@ int H5Dataset::readBTreeV1 (uint64_t pos, uint8_t* buffer, uint64_t buffer_size)
// decompress
inflateChunk(dataChunkFilterBuffer, curr_node.chunk_size, dataChunkBuffer, dataChunkBufferSize);
chunk_buffer = dataChunkBuffer; // sets chunk buffer to new output

// unshuffle
if(metaData.filter[SHUFFLE_FILTER])
{
Expand All @@ -1295,7 +1295,7 @@ int H5Dataset::readBTreeV1 (uint64_t pos, uint8_t* buffer, uint64_t buffer_size)
}
}

// get truncated slice to pull out of chunk
// get truncated slice to pull out of chunk
// (intersection of chunk_slice and hyperslice selection)
range_t chunk_slice_to_read[MAX_NDIMS];
for(int d = 0; d < metaData.ndims; d++)
Expand Down Expand Up @@ -3053,7 +3053,7 @@ bool H5Dataset::hypersliceIntersection(const range_t* node_slice, const uint8_t
/*----------------------------------------------------------------------------
* type2str
*----------------------------------------------------------------------------*/
void H5Dataset::readSlice (uint8_t* output_buffer, const int64_t* output_dimensions, const range_t* output_slice,
void H5Dataset::readSlice (uint8_t* output_buffer, const int64_t* output_dimensions, const range_t* output_slice,
const uint8_t* input_buffer, const int64_t* input_dimensions, const range_t* input_slice) const
{
assert(metaData.ndims > 1); // this code should never be called when ndims is 0 or 1
Expand Down
2 changes: 1 addition & 1 deletion packages/h5/H5DatasetDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool H5DatasetDevice::isConnected (int num_open)
void H5DatasetDevice::closeConnection (void)
{
connected = false;
delete [] dataBuffer;
operator delete[](dataBuffer, std::align_val_t(H5CORO_DATA_ALIGNMENT));
dataBuffer = NULL;
}

Expand Down
Loading

0 comments on commit c2ffed6

Please sign in to comment.