Skip to content

Commit 24ea162

Browse files
authored
[SYCL][ESIMD][NFC] Replace the uses of std::max in ESIMD with ternary op (#11847)
Even though std::max is completely legal/correct to use in SYCL/ESIMD especially in 'constexpr' context, it may cause problems on Windows in some non-trivial configurations with some odd order of includes of system and SYCL header files. Signed-off-by: Klochkov, Vyacheslav N <[email protected]>
1 parent 73d4d25 commit 24ea162

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

sycl/include/sycl/ext/intel/esimd/memory.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ block_load_impl(const T *p, simd_mask<1> pred, FlagsT flags) {
247247

248248
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
249249
constexpr int SmallIntFactor32Bit =
250-
(std::max)(static_cast<size_t>(1), sizeof(uint32_t) / sizeof(T));
250+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
251251
static_assert(NElts > 0 && NElts % SmallIntFactor32Bit == 0,
252252
"Number of elements is not supported by Transposed load");
253253

@@ -333,7 +333,7 @@ block_load_impl(const T *p, simd_mask<1> pred, simd<T, NElts> pass_thru,
333333

334334
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
335335
constexpr int SmallIntFactor32Bit =
336-
(std::max)(static_cast<size_t>(1), sizeof(uint32_t) / sizeof(T));
336+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
337337
static_assert(NElts > 0 && NElts % SmallIntFactor32Bit == 0,
338338
"Number of elements is not supported by Transposed load");
339339

@@ -430,7 +430,7 @@ __ESIMD_API
430430

431431
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
432432
constexpr int SmallIntFactor32Bit =
433-
(std::max)(static_cast<size_t>(1), sizeof(uint32_t) / sizeof(T));
433+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
434434
static_assert(NElts > 0 && NElts % SmallIntFactor32Bit == 0,
435435
"Number of elements is not supported by Transposed load");
436436

@@ -529,7 +529,7 @@ __ESIMD_API
529529

530530
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
531531
constexpr int SmallIntFactor32Bit =
532-
(std::max)(static_cast<size_t>(1), sizeof(uint32_t) / sizeof(T));
532+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
533533
static_assert(NElts > 0 && NElts % SmallIntFactor32Bit == 0,
534534
"Number of elements is not supported by Transposed load");
535535

@@ -586,9 +586,7 @@ block_store_impl(T *p, simd<T, NElts> vals, simd_mask<1> pred, FlagsT flags) {
586586

587587
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
588588
constexpr int SmallIntFactor32Bit =
589-
sizeof(uint32_t) / sizeof(T) > static_cast<size_t>(1)
590-
? sizeof(uint32_t) / sizeof(T)
591-
: static_cast<size_t>(1);
589+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
592590
static_assert(NElts > 0 && NElts % SmallIntFactor32Bit == 0,
593591
"Number of elements is not supported by Transposed store");
594592

@@ -2614,7 +2612,7 @@ slm_block_load(uint32_t byte_offset, simd_mask<1> pred,
26142612

26152613
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
26162614
constexpr int SmallIntFactor32Bit =
2617-
(std::max)(static_cast<size_t>(1), sizeof(uint32_t) / sizeof(T));
2615+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
26182616
static_assert(N > 0 && N % SmallIntFactor32Bit == 0,
26192617
"Number of elements is not supported by Transposed load");
26202618

@@ -2700,7 +2698,7 @@ slm_block_load(uint32_t offset, simd_mask<1> pred, simd<T, N> pass_thru,
27002698

27012699
constexpr int SmallIntFactor64Bit = sizeof(uint64_t) / sizeof(T);
27022700
constexpr int SmallIntFactor32Bit =
2703-
(std::max)(static_cast<size_t>(1), sizeof(uint32_t) / sizeof(T));
2701+
sizeof(uint32_t) / sizeof(T) > 1 ? sizeof(uint32_t) / sizeof(T) : 1;
27042702
static_assert(N > 0 && N % SmallIntFactor32Bit == 0,
27052703
"Number of elements is not supported by Transposed load");
27062704

sycl/include/sycl/ext/intel/esimd/xmx/dpas.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ constexpr int verify_parameters_and_deduce_exec_size() {
8989
"Cannot deduce element size of input arguments");
9090
verify_repeat_count<RepeatCount, AElemBitSize, BElemBitSize, IsDPASW>();
9191

92+
constexpr int MaxElemBitSize =
93+
AElemBitSize > BElemBitSize ? AElemBitSize : BElemBitSize;
94+
constexpr int MaxElemsInDword = 32 / MaxElemBitSize;
9295
constexpr int OpsPerChannel =
93-
(std::max)((std::min)(32 / (std::max)(AElemBitSize, BElemBitSize), 8), 1);
96+
MaxElemsInDword > 8 ? 8 : (MaxElemsInDword < 1 ? 1 : MaxElemsInDword);
9497

9598
// A(_Mx_K) * B(_Kx_N) + C(_Mx_N)
9699
// where:

0 commit comments

Comments
 (0)