Skip to content

Commit 7955801

Browse files
authored
Execution Tests: Long vector - WaveActiveMin/Max and Prod (microsoft#7884)
Adds tests for WaveActiveMin, WaveActiveMax, and WaveActiveProd. This partially addresses microsoft#7472 Verified locally against a private build of WARP. WARP will need some fixes for these to be able to pass in automation so the priority of these tests remains set at 2 to prevent running in automation.
1 parent eede016 commit 7955801

File tree

4 files changed

+107
-5
lines changed

4 files changed

+107
-5
lines changed

tools/clang/unittests/HLSLExec/LongVectorOps.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ INPUT_SET(Positive)
1919
INPUT_SET(Bitwise)
2020
INPUT_SET(SelectCond)
2121
INPUT_SET(FloatSpecial)
22+
INPUT_SET(AllOnes)
2223

2324
#undef INPUT_SET
2425

@@ -194,5 +195,9 @@ OP_LOAD_AND_STORE_SB(LoadAndStore_RD_SB_SRV, "RootDescriptor_SRV")
194195
#undef OP_LOAD_AND_STORE_DEFINES
195196

196197
OP_DEFAULT(Wave, WaveActiveSum, 1, "WaveActiveSum", "")
198+
OP_DEFAULT_DEFINES(Wave, WaveActiveMin, 1, "TestWaveActiveMin", "", " -DFUNC_WAVE_ACTIVE_MIN=1")
199+
OP_DEFAULT_DEFINES(Wave, WaveActiveMax, 1, "TestWaveActiveMax", "", " -DFUNC_WAVE_ACTIVE_MAX=1")
200+
OP(Wave, WaveActiveProduct, 1, "TestWaveActiveProduct", "", " -DFUNC_WAVE_ACTIVE_PRODUCT=1", "LongVectorOp",
201+
AllOnes, Default2, Default3)
197202

198203
#undef OP

tools/clang/unittests/HLSLExec/LongVectorTestData.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ INPUT_SET(InputSet::Bitwise, std::numeric_limits<int16_t>::min(), -1, 0, 1, 3,
289289
6, 9, 0x5555, static_cast<int16_t>(0xAAAA),
290290
std::numeric_limits<int16_t>::max());
291291
INPUT_SET(InputSet::SelectCond, 0, 1);
292+
INPUT_SET(InputSet::AllOnes, 1);
292293
END_INPUT_SETS()
293294

294295
BEGIN_INPUT_SETS(int32_t)
@@ -302,6 +303,7 @@ INPUT_SET(InputSet::Bitwise, std::numeric_limits<int32_t>::min(), -1, 0, 1, 3,
302303
6, 9, 0x55555555, static_cast<int32_t>(0xAAAAAAAA),
303304
std::numeric_limits<int32_t>::max());
304305
INPUT_SET(InputSet::SelectCond, 0, 1);
306+
INPUT_SET(InputSet::AllOnes, 1);
305307
END_INPUT_SETS()
306308

307309
BEGIN_INPUT_SETS(int64_t)
@@ -315,6 +317,7 @@ INPUT_SET(InputSet::Bitwise, std::numeric_limits<int64_t>::min(), -1, 0, 1, 3,
315317
6, 9, 0x5555555555555555LL, 0xAAAAAAAAAAAAAAAALL,
316318
std::numeric_limits<int64_t>::max());
317319
INPUT_SET(InputSet::SelectCond, 0, 1);
320+
INPUT_SET(InputSet::AllOnes, 1);
318321
END_INPUT_SETS()
319322

320323
BEGIN_INPUT_SETS(uint16_t)
@@ -325,6 +328,7 @@ INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 12, 13, 14, 15);
325328
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555, 0xAAAA, 0x8000, 127,
326329
std::numeric_limits<uint16_t>::max());
327330
INPUT_SET(InputSet::SelectCond, 0, 1);
331+
INPUT_SET(InputSet::AllOnes, 1);
328332
END_INPUT_SETS()
329333

330334
BEGIN_INPUT_SETS(uint32_t)
@@ -335,6 +339,7 @@ INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 30, 31, 32);
335339
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x55555555, 0xAAAAAAAA, 0x80000000,
336340
127, std::numeric_limits<uint32_t>::max());
337341
INPUT_SET(InputSet::SelectCond, 0, 1);
342+
INPUT_SET(InputSet::AllOnes, 1);
338343
END_INPUT_SETS()
339344

340345
BEGIN_INPUT_SETS(uint64_t)
@@ -346,6 +351,7 @@ INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555555555555555,
346351
0xAAAAAAAAAAAAAAAA, 0x8000000000000000, 127,
347352
std::numeric_limits<uint64_t>::max());
348353
INPUT_SET(InputSet::SelectCond, 0, 1);
354+
INPUT_SET(InputSet::AllOnes, 1);
349355
END_INPUT_SETS()
350356

351357
BEGIN_INPUT_SETS(HLSLHalf_t)
@@ -376,6 +382,7 @@ INPUT_SET(InputSet::FloatSpecial, std::numeric_limits<float>::infinity(),
376382
-std::numeric_limits<float>::max(),
377383
std::numeric_limits<float>::denorm_min(),
378384
std::numeric_limits<float>::denorm_min() * 10.0, 1.0 / 3.0);
385+
INPUT_SET(InputSet::AllOnes, 1.0);
379386
END_INPUT_SETS()
380387

381388
BEGIN_INPUT_SETS(float)
@@ -403,6 +410,7 @@ INPUT_SET(InputSet::FloatSpecial, std::numeric_limits<float>::infinity(),
403410
-std::numeric_limits<float>::max(),
404411
std::numeric_limits<float>::denorm_min(),
405412
std::numeric_limits<float>::denorm_min() * 10.0f, 1.0f / 3.0f);
413+
INPUT_SET(InputSet::AllOnes, 1.0f);
406414
END_INPUT_SETS()
407415

408416
BEGIN_INPUT_SETS(double)
@@ -421,6 +429,7 @@ INPUT_SET(InputSet::SplitDouble, 0.0, -1.0, 1.0, -1.0, 12345678.87654321, -1.0,
421429
INPUT_SET(InputSet::Positive, 1.0, 1.0, 65535.0, 0.01, 5531.0, 0.01, 1.0, 0.01,
422430
331.2330, 3250.01);
423431
INPUT_SET(InputSet::SelectCond, 0.0, 1.0);
432+
INPUT_SET(InputSet::AllOnes, 1.0);
424433
END_INPUT_SETS()
425434

426435
#undef BEGIN_INPUT_SETS

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,10 +1266,44 @@ FLOAT_SPECIAL_OP(OpType::IsNan, (std::isnan(A)));
12661266

12671267
#define WAVE_ACTIVE_OP(OP, IMPL) \
12681268
template <typename T> struct Op<OP, T, 1> : DefaultValidation<T> { \
1269-
T operator()(T A, T WaveSize) { return IMPL; } \
1269+
T operator()(T A, UINT WaveSize) { return IMPL; } \
12701270
};
12711271

1272-
WAVE_ACTIVE_OP(OpType::WaveActiveSum, (A * WaveSize));
1272+
template <typename T> T waveActiveSum(T A, UINT WaveSize) {
1273+
T WaveSizeT = static_cast<T>(WaveSize);
1274+
return A * WaveSizeT;
1275+
}
1276+
1277+
WAVE_ACTIVE_OP(OpType::WaveActiveSum, (waveActiveSum(A, WaveSize)));
1278+
1279+
template <typename T> T waveActiveMin(T A, UINT WaveSize) {
1280+
std::vector<T> Values;
1281+
// Add the 'WaveLaneID' to A.
1282+
for (UINT I = 0; I < WaveSize; ++I)
1283+
Values.push_back(A + static_cast<T>(I));
1284+
return *std::min_element(Values.begin(), Values.end());
1285+
}
1286+
1287+
WAVE_ACTIVE_OP(OpType::WaveActiveMin, (waveActiveMin(A, WaveSize)));
1288+
1289+
template <typename T> T waveActiveMax(T A, UINT WaveSize) {
1290+
std::vector<T> Values;
1291+
// Add the 'WaveLaneID' to A.
1292+
for (UINT I = 0; I < WaveSize; ++I)
1293+
Values.push_back(A + static_cast<T>(I));
1294+
return *std::max_element(Values.begin(), Values.end());
1295+
}
1296+
1297+
WAVE_ACTIVE_OP(OpType::WaveActiveMax, (waveActiveMax(A, WaveSize)));
1298+
1299+
template <typename T> T waveActiveProduct(T A, UINT WaveSize) {
1300+
// We want to avoid overflow of a large product. So, the WaveActiveProdFn has
1301+
// an input set of all 1's and we modify the value of the largest lane to be
1302+
// equal to the lane index in the shader.
1303+
return A * static_cast<T>(WaveSize - 1);
1304+
}
1305+
1306+
WAVE_ACTIVE_OP(OpType::WaveActiveProduct, (waveActiveProduct(A, WaveSize)));
12731307

12741308
#undef WAVE_ACTIVE_OP
12751309

@@ -1321,13 +1355,12 @@ template <OpType OP, typename T> struct WaveOpExpectedBuilder {
13211355
static auto buildExpected(Op<OP, T, 1> Op, const InputSets<T> &Inputs,
13221356
UINT WaveSize) {
13231357
DXASSERT_NOMSG(Inputs.size() == 1);
1324-
const T WaveSizeT = static_cast<T>(WaveSize);
13251358

1326-
std::vector<decltype(Op(T(), WaveSizeT))> Expected;
1359+
std::vector<decltype(Op(T(), WaveSize))> Expected;
13271360
Expected.reserve(Inputs[0].size());
13281361

13291362
for (size_t I = 0; I < Inputs[0].size(); ++I)
1330-
Expected.push_back(Op(Inputs[0][I], WaveSizeT));
1363+
Expected.push_back(Op(Inputs[0][I], WaveSize));
13311364

13321365
return Expected;
13331366
}
@@ -2173,16 +2206,43 @@ class DxilConf_SM69_Vectorized {
21732206
HLK_TEST(LoadAndStore_RD_SB_UAV, double);
21742207

21752208
HLK_WAVEOP_TEST(WaveActiveSum, int16_t);
2209+
HLK_WAVEOP_TEST(WaveActiveMin, int16_t);
2210+
HLK_WAVEOP_TEST(WaveActiveMax, int16_t);
2211+
HLK_WAVEOP_TEST(WaveActiveProduct, int16_t);
21762212
HLK_WAVEOP_TEST(WaveActiveSum, int32_t);
2213+
HLK_WAVEOP_TEST(WaveActiveMin, int32_t);
2214+
HLK_WAVEOP_TEST(WaveActiveMax, int32_t);
2215+
HLK_WAVEOP_TEST(WaveActiveProduct, int32_t);
21772216
HLK_WAVEOP_TEST(WaveActiveSum, int64_t);
2217+
HLK_WAVEOP_TEST(WaveActiveMin, int64_t);
2218+
HLK_WAVEOP_TEST(WaveActiveMax, int64_t);
2219+
HLK_WAVEOP_TEST(WaveActiveProduct, int64_t);
21782220

21792221
HLK_WAVEOP_TEST(WaveActiveSum, uint16_t);
2222+
HLK_WAVEOP_TEST(WaveActiveMin, uint16_t);
2223+
HLK_WAVEOP_TEST(WaveActiveMax, uint16_t);
2224+
HLK_WAVEOP_TEST(WaveActiveProduct, uint16_t);
21802225
HLK_WAVEOP_TEST(WaveActiveSum, uint32_t);
2226+
HLK_WAVEOP_TEST(WaveActiveMin, uint32_t);
2227+
HLK_WAVEOP_TEST(WaveActiveMax, uint32_t);
2228+
HLK_WAVEOP_TEST(WaveActiveProduct, uint32_t);
21812229
HLK_WAVEOP_TEST(WaveActiveSum, uint64_t);
2230+
HLK_WAVEOP_TEST(WaveActiveMin, uint64_t);
2231+
HLK_WAVEOP_TEST(WaveActiveMax, uint64_t);
2232+
HLK_WAVEOP_TEST(WaveActiveProduct, uint64_t);
21822233

21832234
HLK_WAVEOP_TEST(WaveActiveSum, HLSLHalf_t);
2235+
HLK_WAVEOP_TEST(WaveActiveMin, HLSLHalf_t);
2236+
HLK_WAVEOP_TEST(WaveActiveMax, HLSLHalf_t);
2237+
HLK_WAVEOP_TEST(WaveActiveProduct, HLSLHalf_t);
21842238
HLK_WAVEOP_TEST(WaveActiveSum, float);
2239+
HLK_WAVEOP_TEST(WaveActiveMin, float);
2240+
HLK_WAVEOP_TEST(WaveActiveMax, float);
2241+
HLK_WAVEOP_TEST(WaveActiveProduct, float);
21852242
HLK_WAVEOP_TEST(WaveActiveSum, double);
2243+
HLK_WAVEOP_TEST(WaveActiveMin, double);
2244+
HLK_WAVEOP_TEST(WaveActiveMax, double);
2245+
HLK_WAVEOP_TEST(WaveActiveProduct, double);
21862246

21872247
private:
21882248
bool Initialized = false;

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,6 +4083,34 @@ void MSMain(uint GID : SV_GroupIndex,
40834083
}
40844084
#endif
40854085
4086+
#ifdef FUNC_WAVE_ACTIVE_MIN
4087+
vector<OUT_TYPE, NUM> TestWaveActiveMin(vector<TYPE, NUM> Vector)
4088+
{
4089+
Vector += WaveGetLaneIndex();
4090+
return WaveActiveMin(Vector);
4091+
}
4092+
#endif
4093+
4094+
#ifdef FUNC_WAVE_ACTIVE_MAX
4095+
vector<OUT_TYPE, NUM> TestWaveActiveMax(vector<TYPE, NUM> Vector)
4096+
{
4097+
Vector += WaveGetLaneIndex();
4098+
return WaveActiveMax(Vector);
4099+
}
4100+
#endif
4101+
4102+
#ifdef FUNC_WAVE_ACTIVE_PRODUCT
4103+
vector<OUT_TYPE, NUM> TestWaveActiveProduct(vector<TYPE, NUM> Vector)
4104+
{
4105+
uint LaneIndex = WaveGetLaneIndex();
4106+
if(LaneIndex == (WaveGetLaneCount() - 1))
4107+
{
4108+
Vector = LaneIndex;
4109+
}
4110+
return WaveActiveProduct(Vector);
4111+
}
4112+
#endif
4113+
40864114
#ifdef FUNC_TEST_SELECT
40874115
vector<OUT_TYPE, NUM> TestSelect(vector<TYPE, NUM> Vector1,
40884116
vector<TYPE, NUM> Vector2,

0 commit comments

Comments
 (0)