Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime checks for use of SIMD implementations and stubs functions if not available. #1

Merged
merged 6 commits into from
Jul 3, 2024
23 changes: 21 additions & 2 deletions blosc/bitshuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "bitshuffle-altivec.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure ALTIVEC is available for the compilation target and compiler. */
#if defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8)
Expand All @@ -33,7 +34,6 @@
#include <altivec.h>

#include <stdint.h>
#include <stdlib.h>

/* The next is useful for debugging purposes */
#if 0
Expand Down Expand Up @@ -592,4 +592,23 @@ int64_t bshuf_untrans_bit_elem_altivec(const void* in, void* out, const size_t s
return count;
}

#endif /* defined(__ALTIVEC__) */

const bool is_bshuf_altivec = true;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used naming consistent with the functions.
The naming (like the SIMD suffix) could be made consistent between bitshuffle and shuffle functions


#else /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */

const bool is_bshuf_altivec = false;

int64_t
bshuf_trans_bit_elem_altivec(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_altivec(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* ALTIVEC-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_altivec;

BLOSC_NO_EXPORT int64_t
bshuf_trans_byte_elem_altivec(const void* in, void* out, const size_t size,
Expand Down
19 changes: 19 additions & 0 deletions blosc/bitshuffle-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "bitshuffle-avx2.h"
#include "bitshuffle-sse2.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure AVX2 is available for the compilation target and compiler. */
#if defined(__AVX2__)
Expand Down Expand Up @@ -262,4 +263,22 @@ int64_t bshuf_untrans_bit_elem_AVX(const void* in, void* out, const size_t size,
return count;
}

const bool is_bshuf_AVX = true;

#else /* defined(__AVX2__) */

const bool is_bshuf_AVX = false;

int64_t
bshuf_trans_bit_elem_AVX(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_AVX(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__AVX2__) */
7 changes: 7 additions & 0 deletions blosc/bitshuffle-avx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* AVX2-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_AVX;


/**
* AVX2-accelerated bitshuffle routine.
Expand Down
28 changes: 24 additions & 4 deletions blosc/bitshuffle-avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
rights to use.
**********************************************************************/

/* Make sure AVX512 is available for the compilation target and compiler. */
#if defined(__AVX512F__) && defined (__AVX512BW__)
#include <immintrin.h>
#include "bitshuffle-avx512.h"
#include "bitshuffle-avx2.h"
#include "bitshuffle-sse2.h"
#include "bitshuffle-generic.h"
Comment on lines 23 to 26
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved those includes outside of #if defined... to be consistent with other SIMD implementations

#include <stdlib.h>

/* Make sure AVX512 is available for the compilation target and compiler. */
#if defined(__AVX512F__) && defined (__AVX512BW__)
#include <immintrin.h>


/* Transpose bits within bytes. */
Expand Down Expand Up @@ -158,4 +160,22 @@ int64_t bshuf_untrans_bit_elem_AVX512(const void* in, void* out, const size_t si
return count;
}

#endif
const bool is_bshuf_AVX512 = true;

#else /* defined(__AVX512F__) && defined (__AVX512BW__) */

const bool is_bshuf_AVX512 = false;

int64_t
bshuf_trans_bit_elem_AVX512(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_AVX512(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__AVX512F__) && defined (__AVX512BW__) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-avx512.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* AVX512-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_AVX512;

BLOSC_NO_EXPORT int64_t
bshuf_trans_bit_elem_AVX512(const void* in, void* out, const size_t size,
Expand Down
18 changes: 17 additions & 1 deletion blosc/bitshuffle-neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

#include "bitshuffle-neon.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move stdlib.h include outside of #if defined, it is also needed for abort


/* Make sure NEON is available for the compilation target and compiler. */
#if defined(__ARM_NEON)

#include <arm_neon.h>

#include <stdlib.h>

/* The next is useful for debugging purposes */
#if 0
Expand Down Expand Up @@ -491,4 +491,20 @@ int64_t bshuf_untrans_bit_elem_NEON(const void* in, void* out, const size_t size
return count;
}

const bool is_bshuf_NEON = true;

#else /* defined(__ARM_NEON) */

const bool is_bshuf_NEON = false;

int64_t bshuf_trans_bit_elem_NEON(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t bshuf_untrans_bit_elem_NEON(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__ARM_NEON) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* NEON-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_NEON;

/**
NEON-accelerated bitshuffle routine.
Expand Down
18 changes: 18 additions & 0 deletions blosc/bitshuffle-sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "bitshuffle-sse2.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure SSE2 is available for the compilation target and compiler. */
#if defined(__SSE2__)
Expand Down Expand Up @@ -481,5 +482,22 @@ int64_t bshuf_untrans_bit_elem_SSE(const void* in, void* out, const size_t size,
return count;
}

const bool is_bshuf_SSE = true;

#else /* defined(__SSE2__) */

const bool is_bshuf_SSE = false;

int64_t
bshuf_trans_bit_elem_SSE(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_SSE(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__SSE2__) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-sse2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* SSE2-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_SSE;

BLOSC_NO_EXPORT int64_t
bshuf_trans_byte_elem_SSE(const void* in, void* out, const size_t size,
Expand Down
19 changes: 18 additions & 1 deletion blosc/shuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "shuffle-altivec.h"
#include "shuffle-generic.h"
#include <stdlib.h>

/* Make sure ALTIVEC is available for the compilation target and compiler. */
#if defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8)
Expand Down Expand Up @@ -423,4 +424,20 @@ unshuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
}
}

#endif /* defined(__ALTIVEC__) */
const bool is_shuffle_altivec = true;

#else /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */

const bool is_shuffle_altivec = false;

void shuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

void unshuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

#endif /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */
6 changes: 6 additions & 0 deletions blosc/shuffle-altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include "blosc2/blosc2-common.h"

#include <stdint.h>
#include <stdbool.h>

/**
* ALTIVEC-accelerated (un)shuffle routines availability.
*/
extern const bool is_shuffle_altivec;

/**
ALTIVEC-accelerated shuffle routine.
Expand Down
18 changes: 17 additions & 1 deletion blosc/shuffle-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include "shuffle-avx2.h"
#include "shuffle-generic.h"
#include <stdlib.h>

/* Make sure AVX2 is available for the compilation target and compiler. */
#if defined(__AVX2__)

#include <immintrin.h>

#include <stdlib.h>
#include <stdint.h>

/* The next is useful for debugging purposes */
Expand Down Expand Up @@ -746,4 +746,20 @@ unshuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
}
}

const bool is_shuffle_avx2 = true;

#else

const bool is_shuffle_avx2 = false;

void shuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

void unshuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

#endif /* defined(__AVX2__) */
6 changes: 6 additions & 0 deletions blosc/shuffle-avx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include "blosc2/blosc2-common.h"

#include <stdint.h>
#include <stdbool.h>

/**
* AVX2-accelerated (un)shuffle routines availability.
*/
extern const bool is_shuffle_avx2;

/**
AVX2-accelerated shuffle routine.
Expand Down
17 changes: 17 additions & 0 deletions blosc/shuffle-neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "shuffle-neon.h"
#include "shuffle-generic.h"
#include <stdlib.h>

/* Make sure NEON is available for the compilation target and compiler. */
#if defined(__ARM_NEON)
Expand Down Expand Up @@ -414,4 +415,20 @@ unshuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
}
}

const bool is_shuffle_neon = true;

#else /* defined(__ARM_NEON) */

const bool is_shuffle_neon = false;

void shuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t* const _src, uint8_t* const _dest) {
abort();
}

void unshuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

#endif /* defined(__ARM_NEON) */
6 changes: 6 additions & 0 deletions blosc/shuffle-neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "blosc2/blosc2-common.h"

#include <stdint.h>
#include <stdbool.h>

/**
* NEON-accelerated (un)shuffle routines availability.
*/
extern const bool is_shuffle_neon;

/**
NEON-accelerated shuffle routine.
Expand Down
Loading