Skip to content

Commit 6272ab9

Browse files
committed
Convert
1 parent a1805a8 commit 6272ab9

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tools/clang/unittests/HLSLExec/LinAlgTests.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class DxilConf_SM610_LinAlg {
348348
// Query Accumulator Layout
349349
TEST_METHOD(QueryAccumLayout);
350350

351+
// Convert
352+
TEST_METHOD(Convert);
353+
351354
private:
352355
CComPtr<ID3D12Device> D3DDevice;
353356
dxc::SpecificDllLoader DxcSupport;
@@ -1672,4 +1675,51 @@ void DxilConf_SM610_LinAlg::AccumulateMemory_Wave_16x16_F16() {
16721675
runAccumulateMemory(D3DDevice, DxcSupport, Params, VerboseLogging, /*FillValue=*/7.0f);
16731676
}
16741677

1678+
static const char ConvertShader[] = R"(
1679+
#define CT_F16 8
1680+
#define CT_F32 9
1681+
1682+
RWByteAddressBuffer Output : register(u0);
1683+
1684+
[numthreads(1, 1, 1)]
1685+
void main() {
1686+
vector<half, 4> InVec = {1.0, 2.0, 3.0, 4.0};
1687+
vector<float, 4> OutVec;
1688+
__builtin_LinAlg_Convert(OutVec, InVec, CT_F16, CT_F32);
1689+
Output.Store<float>(0, OutVec.x);
1690+
Output.Store<float>(4, OutVec.y);
1691+
Output.Store<float>(8, OutVec.z);
1692+
Output.Store<float>(12, OutVec.w);
1693+
}
1694+
)";
1695+
1696+
static void runConvert(ID3D12Device *Device,
1697+
dxc::SpecificDllLoader &DxcSupport,
1698+
bool Verbose) {
1699+
std::string Args = "-HV 202x";
1700+
MatrixDim NumElements = 4;
1701+
size_t BufferSize = elementSize(ComponentType::F32) * NumElements;
1702+
1703+
compileShader(DxcSupport, ConvertShader, "cs_6_10", Args, Verbose);
1704+
1705+
auto Expected = makeExpectedVec(ComponentType::F32, NumElements, 1.0);
1706+
1707+
auto Op = createComputeOp(ConvertShader, "cs_6_10", "UAV(u0)",
1708+
Args.c_str());
1709+
addUAVBuffer(Op.get(), "Output", BufferSize, true);
1710+
addRootUAV(Op.get(), 0, "Output");
1711+
1712+
auto Result = runShaderOp(Device, DxcSupport, std::move(Op));
1713+
1714+
MappedData OutData;
1715+
Result->Test->GetReadBackData("Output", &OutData);
1716+
1717+
VERIFY_IS_TRUE(verifyComponentBuffer(ComponentType::F32, OutData.data(),
1718+
Expected, NumElements, Verbose));
1719+
}
1720+
1721+
void DxilConf_SM610_LinAlg::Convert() {
1722+
runConvert(D3DDevice, DxcSupport, VerboseLogging);
1723+
}
1724+
16751725
} // namespace LinAlg

0 commit comments

Comments
 (0)