Skip to content

Commit

Permalink
Support for new accelerated paths in b2nd_append
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed Apr 1, 2024
1 parent af6602e commit 3aa602a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
16 changes: 11 additions & 5 deletions blosc/b2nd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,16 +1451,22 @@ int b2nd_append(b2nd_array_t *array, const void *buffer, int64_t buffersize,

int32_t chunksize = array->sc->chunksize;
int64_t nchunks_append = buffersize / chunksize;
// Check whether chunkshape and blockshape are equals
bool equal_chunks_blocks = true;
for (int i = 0; i < array->ndim; ++i) {
// Check whether chunkshape and blockshape are compatible with accelerated path.
// Essentially, we are checking whether the buffer is a multiple of the chunksize
// and that the chunkshape and blockshape are the same, except for the first axis.
// Also, axis needs to be the first one.
bool compat_chunks_blocks = true;
for (int i = 1; i < array->ndim; ++i) {
if (array->chunkshape[i] != array->blockshape[i]) {
equal_chunks_blocks = false;
compat_chunks_blocks = false;
break;
}
}
if (axis > 0) {
compat_chunks_blocks = false;
}
// General case where a buffer has a different size than the chunksize
if (!equal_chunks_blocks || buffersize % chunksize != 0 || nchunks_append != 1) {
if (!compat_chunks_blocks || buffersize % chunksize != 0 || nchunks_append != 1) {
BLOSC_ERROR(b2nd_insert(array, buffer, buffersize, axis, array->shape[axis]));
return BLOSC2_ERROR_SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions blosc/schunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ int64_t blosc2_schunk_update_chunk(blosc2_schunk *schunk, int64_t nchunk, uint8_

if (schunk->chunksize != 0 && (chunk_nbytes > schunk->chunksize ||
(chunk_nbytes < schunk->chunksize && nchunk != schunk->nchunks - 1))) {
BLOSC_TRACE_ERROR("Updating chunks that have different lengths in the same schunk "
BLOSC_TRACE_ERROR("Updating chunks having different lengths in the same schunk "
"is not supported yet (unless it's the last one and smaller):"
" %d > %d.", chunk_nbytes, schunk->chunksize);
return BLOSC2_ERROR_CHUNK_UPDATE;
Expand Down Expand Up @@ -1038,7 +1038,7 @@ int64_t blosc2_schunk_delete_chunk(blosc2_schunk *schunk, int64_t nchunk) {


/* Append a data buffer to a super-chunk. */
int64_t blosc2_schunk_append_buffer(blosc2_schunk *schunk, void *src, int32_t nbytes) {
int64_t blosc2_schunk_append_buffer(blosc2_schunk *schunk, const void *src, int32_t nbytes) {
uint8_t* chunk = malloc(nbytes + BLOSC2_MAX_OVERHEAD);
schunk->current_nchunk = schunk->nchunks;
/* Compress the src buffer using super-chunk context */
Expand Down
2 changes: 1 addition & 1 deletion include/blosc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ BLOSC_EXPORT int64_t blosc2_schunk_delete_chunk(blosc2_schunk *schunk, int64_t n
* @return The number of chunks in super-chunk. If some problem is
* detected, this number will be negative.
*/
BLOSC_EXPORT int64_t blosc2_schunk_append_buffer(blosc2_schunk *schunk, void *src, int32_t nbytes);
BLOSC_EXPORT int64_t blosc2_schunk_append_buffer(blosc2_schunk *schunk, const void *src, int32_t nbytes);

/**
* @brief Decompress and return the @p nchunk chunk of a super-chunk.
Expand Down
7 changes: 6 additions & 1 deletion tests/b2nd/test_b2nd_append.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ CUTEST_TEST_SETUP(append) {
{2, {0, 6}, {6, 6}, {3, 3}, {6, 6}, 0},
// Accelerated path with chunkshape and blockshape equal to buffershape
{2, {0, 6}, {6, 6}, {6, 6}, {6, 6}, 0},

// Accelerated path with chunkshape and blockshape equals except in the first dimension
{2, {0, 6}, {6, 6}, {3, 6}, {6, 6}, 0},
{2, {0, 6}, {6, 6}, {4, 6}, {6, 6}, 0},
{2, {0, 6}, {6, 6}, {3, 6}, {13, 6}, 0},
// The one below is not supported yet
// {2, {0, 6}, {6, 6}, {4, 6}, {13, 6}, 0},
));
}

Expand Down

0 comments on commit 3aa602a

Please sign in to comment.