-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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 8 commits
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
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
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
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
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
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
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
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,108 @@ | ||
/*@targets | ||
** $maxopt baseline | ||
** sse2 sse41 avx2 avx512f 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" | ||
// Provides the various *_LOOP macros | ||
#include "fast_loop_macros.h" | ||
|
||
//############################################################################### | ||
//## Division | ||
//############################################################################### | ||
/******************************************************************************** | ||
** Defining the SIMD kernels | ||
********************************************************************************/ | ||
#if NPY_SIMD | ||
/**begin repeat | ||
* #sfx = u8, u16, u32, u64# | ||
*/ | ||
static NPY_INLINE void | ||
simd_divide_by_scalar_contig_@sfx@(char **args, npy_intp len) | ||
{ | ||
npyv_lanetype_@sfx@ *src = (npyv_lanetype_@sfx@ *) args[0]; | ||
npyv_lanetype_@sfx@ scalar = *(npyv_lanetype_@sfx@ *) args[1]; | ||
npyv_lanetype_@sfx@ *dst = (npyv_lanetype_@sfx@ *) args[2]; | ||
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 | ||
|
||
/******************************************************************************** | ||
** Defining ufunc inner functions | ||
********************************************************************************/ | ||
|
||
/**begin repeat | ||
* Unsigned types | ||
* #type = npy_ubyte, npy_ushort, npy_uint, npy_ulong, npy_ulonglong# | ||
* #TYPE = UBYTE, USHORT, UINT, ULONG, ULONGLONG# | ||
* #STYPE = BYTE, SHORT, INT, LONG, LONGLONG# | ||
*/ | ||
#undef TO_SIMD_SFX | ||
#if 0 | ||
/**begin repeat1 | ||
* #len = 8, 16, 32, 64# | ||
*/ | ||
#elif NPY_BITSOF_@STYPE@ == @len@ | ||
#define TO_SIMD_SFX(X) X##_u@len@ | ||
/**end repeat1**/ | ||
#endif | ||
|
||
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@) { | ||
const @type@ d = *(@type@ *)ip2; | ||
if (NPY_UNLIKELY(d == 0)) { | ||
npy_set_floatstatus_divbyzero(); | ||
io1 = 0; | ||
} else { | ||
io1 /= d; | ||
} | ||
} | ||
*((@type@ *)iop1) = io1; | ||
} | ||
#if NPY_SIMD && defined(TO_SIMD_SFX) | ||
// for contiguous block of memory, divisor is a scalar and not 0 | ||
else if (IS_BLOCKABLE_BINARY_SCALAR2(sizeof(@type@), NPY_SIMD_WIDTH) && | ||
(*(@type@ *)args[1]) != 0) { | ||
TO_SIMD_SFX(simd_divide_by_scalar_contig)(args, dimensions[0]); | ||
} | ||
#endif | ||
else { | ||
BINARY_LOOP { | ||
const @type@ in1 = *(@type@ *)ip1; | ||
const @type@ in2 = *(@type@ *)ip2; | ||
if (NPY_UNLIKELY(in2 == 0)) { | ||
npy_set_floatstatus_divbyzero(); | ||
*((@type@ *)op1) = 0; | ||
} else{ | ||
*((@type@ *)op1) = in1 / in2; | ||
} | ||
} | ||
} | ||
} | ||
/**end repeat**/ |
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
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.