-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH, SIMD: Dispatch for unsigned floor division #18075
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50752aa
ENH, SIMD: Added integer dispatch
ganesh-k13 6b2fb9e
ENH, SIMD: Use integer dispatch
ganesh-k13 f2cb33b
ENH, SIMD: Add dispatch to build process
ganesh-k13 453043c
MAINT, SIMD: Add loops_arithmetic.dispatch.c.src
ganesh-k13 71e84dc
MAINT: Fixed dispatch in generate_umath
ganesh-k13 bbb1436
SIMD, MAINT: Refined kernel and inner ufunc functions
ganesh-k13 c78d9a0
TST: Division tests for unsigned ints
ganesh-k13 a2c5af9
BENCH: Benchmarks for unsigned ints (#18075)
ganesh-k13 4d2e484
SIMD: Use scalar division for Armv7, Aarch64, and IBM/Power
ganesh-k13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
ENH, SIMD: Added integer dispatch
- Loading branch information
commit 50752aa920be32b74c1a7d0e4242e84b15ffa73c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/*@targets | ||
** $maxopt baseline | ||
** sse2 sse41 avx2 avx512_skx | ||
** vsx2 | ||
** neon | ||
**/ | ||
#define _UMATHMODULE | ||
#define _MULTIARRAYMODULE | ||
#define NPY_NO_DEPRECATED_API NPY_API_VERSION | ||
|
||
#include "simd/simd.h" | ||
#include "loops_utils.h" | ||
#include "loops.h" | ||
#include "lowlevel_strided_loops.h" | ||
#include<signal.h> | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Provides the various *_LOOP macros | ||
#include "fast_loop_macros.h" | ||
|
||
//############################################################################### | ||
//## Unsigned Integers | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//############################################################################### | ||
/******************************************************************************** | ||
** Defining the SIMD kernels | ||
********************************************************************************/ | ||
#ifdef NPY_SIMD | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/**begin repeat | ||
* #sfx = u8, u16, u32, u64# | ||
*/ | ||
|
||
static void simd_divide_by_scalar_contig_contig_@sfx@ | ||
(npyv_lanetype_@sfx@ *src, const npyv_lanetype_@sfx@ scalar, npyv_lanetype_@sfx@ *dst, | ||
int len) | ||
{ | ||
const int vstep = npyv_nlanes_@sfx@; | ||
const npyv_@sfx@x3 divisor = npyv_divisor_@sfx@(scalar); | ||
|
||
for (; len >= vstep; len -= vstep, src += vstep, dst += vstep) { | ||
npyv_@sfx@ a = npyv_load_@sfx@(src); | ||
npyv_@sfx@ c = npyv_divc_@sfx@(a, divisor); | ||
npyv_store_@sfx@(dst, c); | ||
} | ||
for (; len > 0; --len, ++src, ++dst) { | ||
const npyv_lanetype_@sfx@ a = *src; | ||
*dst = a / scalar; | ||
} | ||
npyv_cleanup(); | ||
} | ||
|
||
/**end repeat**/ | ||
#endif | ||
|
||
|
||
|
||
// XXX Need to see what can be done for 64 bits | ||
/**begin repeat | ||
* Unsigned types | ||
* #type = npy_ubyte, npy_ushort, npy_uint, npy_ulong, npy_ulonglong# | ||
* #TYPE = UBYTE, USHORT, UINT, ULONG, ULONGLONG# | ||
* #SIGNED_TYPE = BYTE, SHORT, INT, LONG, LONGLONG# | ||
*/ | ||
#if NPY_BITSOF_@SIGNED_TYPE@ <= 8 | ||
#define simd_divide_by_scalar_@type@ simd_divide_by_scalar_contig_contig_u8 | ||
#elif NPY_BITSOF_@SIGNED_TYPE@ <= 16 | ||
#define simd_divide_by_scalar_@type@ simd_divide_by_scalar_contig_contig_u16 | ||
#elif NPY_BITSOF_@SIGNED_TYPE@ <= 32 | ||
#define simd_divide_by_scalar_@type@ simd_divide_by_scalar_contig_contig_u32 | ||
#else | ||
#define simd_divide_by_scalar_@type@ simd_divide_by_scalar_contig_contig_u64 | ||
#endif | ||
static NPY_INLINE int | ||
run_binary_simd_divide_@TYPE@(char **args, npy_intp const *dimensions, npy_intp const *steps) | ||
seiko2plus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
BINARY_DEFS | ||
|
||
if (n == 0) { | ||
return 1; | ||
} | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const @type@ in2 = *(@type@ *)ip2; | ||
if (in2 == 0) { | ||
npy_set_floatstatus_divbyzero(); | ||
BINARY_LOOP_SLIDING { | ||
*((@type@ *)op1) = 0; | ||
} | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 1; | ||
} | ||
#if defined NPY_SIMD | ||
#ifdef NPY_HAVE_AVX512F | ||
const npy_intp vector_size_bytes = 64; | ||
#elif defined NPY_HAVE_AVX2 | ||
const npy_intp vector_size_bytes = 32; | ||
#else | ||
const npy_intp vector_size_bytes = 16; | ||
#endif | ||
// XXX Implement other loops | ||
if (IS_BLOCKABLE_BINARY_SCALAR2(sizeof(@type@), (npy_uintp)vector_size_bytes)) { | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
simd_divide_by_scalar_@type@(ip1, in2, op1, n); | ||
return 1; | ||
} | ||
#endif | ||
return 0; | ||
} | ||
/**end repeat**/ | ||
|
||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/**begin repeat | ||
* Unsigned types | ||
* #type = npy_ubyte, npy_ushort, npy_uint, npy_ulong, npy_ulonglong# | ||
* #TYPE = UBYTE, USHORT, UINT, ULONG, ULONGLONG# | ||
*/ | ||
NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_divide) | ||
(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func)) | ||
{ | ||
if (IS_BINARY_REDUCE) { | ||
BINARY_REDUCE_LOOP(@type@) { | ||
io1 /= *(@type@ *)ip2; | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
*((@type@ *)iop1) = io1; | ||
} | ||
else if (!run_binary_simd_divide_@TYPE@(args, dimensions, steps)) { | ||
BINARY_LOOP { | ||
const @type@ in1 = *(@type@ *)ip1; | ||
const @type@ in2 = *(@type@ *)ip2; | ||
if (in2 == 0) { | ||
npy_set_floatstatus_divbyzero(); | ||
*((@type@ *)op1) = 0; | ||
} | ||
*((@type@ *)op1) = in1 / in2; | ||
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
/**end repeat**/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.