From e743ddd49045284b706cc2cbbb615acc6fe3d882 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 9 Nov 2022 09:15:15 -0500 Subject: f32tof16 and f16tof32 support for CPU targets (#2500) * #include an absolute path didn't work - because paths were taken to always be relative. * Float16 support for C++/CPU based targets with f16tof32 and f32tof16. * Small correction around INF/NAN handling for f32tof16 * Small improvement to f16tof32 * Disable CUDA test for now. --- tests/hlsl-intrinsic/f16tof32.slang | 18 ++++++++++++ tests/hlsl-intrinsic/f16tof32.slang.expected.txt | 8 +++++ tests/hlsl-intrinsic/f32tof16.slang | 37 ++++++++++++++++++++++++ tests/hlsl-intrinsic/f32tof16.slang.expected.txt | 8 +++++ 4 files changed, 71 insertions(+) create mode 100644 tests/hlsl-intrinsic/f16tof32.slang create mode 100644 tests/hlsl-intrinsic/f16tof32.slang.expected.txt create mode 100644 tests/hlsl-intrinsic/f32tof16.slang create mode 100644 tests/hlsl-intrinsic/f32tof16.slang.expected.txt (limited to 'tests') diff --git a/tests/hlsl-intrinsic/f16tof32.slang b/tests/hlsl-intrinsic/f16tof32.slang new file mode 100644 index 000000000..b73ade4cf --- /dev/null +++ b/tests/hlsl-intrinsic/f16tof32.slang @@ -0,0 +1,18 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(8, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int idx = int(dispatchThreadID.x); + + uint values[] = { 0, 0xC600, 0x4A00, 0xCE00, 0x2555, 0xA155, 0x1D55, 0x9955 }; + + outputBuffer[idx] = f16tof32(values[idx]); +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/f16tof32.slang.expected.txt b/tests/hlsl-intrinsic/f16tof32.slang.expected.txt new file mode 100644 index 000000000..833998d8e --- /dev/null +++ b/tests/hlsl-intrinsic/f16tof32.slang.expected.txt @@ -0,0 +1,8 @@ +0 +C0C00000 +41400000 +C1C00000 +3CAAA000 +BC2AA000 +3BAAA000 +BB2AA000 diff --git a/tests/hlsl-intrinsic/f32tof16.slang b/tests/hlsl-intrinsic/f32tof16.slang new file mode 100644 index 000000000..465b2840a --- /dev/null +++ b/tests/hlsl-intrinsic/f32tof16.slang @@ -0,0 +1,37 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(8, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int idx = int(dispatchThreadID.x); + + // We want to test 0 + float value = 0.0f; + // Produces some somewhat interesting numbers + if (idx != 0) + { + value = (3 << idx); + + if ((idx & 1) != 0) + { + value = -value; + } + + // Do the recip + if ((idx & 4) != 0) + { + value = 1.0f / value; + } + } + + uint r = f32tof16(value); + + outputBuffer[idx] = r; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/f32tof16.slang.expected.txt b/tests/hlsl-intrinsic/f32tof16.slang.expected.txt new file mode 100644 index 000000000..2a2175a43 --- /dev/null +++ b/tests/hlsl-intrinsic/f32tof16.slang.expected.txt @@ -0,0 +1,8 @@ +0 +C600 +4A00 +CE00 +2555 +A155 +1D55 +9955 -- cgit v1.2.3