-
Notifications
You must be signed in to change notification settings - Fork 18
Add distance
tests
#270
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
base: main
Are you sure you want to change the base?
Add distance
tests
#270
Conversation
Should I add a test case for NaNs? Or other non-normal floats? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah adding tests for odd values like NaN and Inf would be good.
5cb1a01
to
913c363
Compare
float R3 = distance(X[0].xyzw, Y[0].xyzw); | ||
Result[3] = R3; | ||
|
||
// test denormal cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't denormal (aka. subnormal) cases, which would also be good to test. That would be very small positive or negative values, below the smallest normalized value in the given float representation.
Elsewhere we use the terminology "floating point specials" to refer to INF or NaN non-numeric values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/llvm/offload-test-suite/pull/268/files
you can look here for examples of 16 and 32 bit float values which should be denorm according to c++
be926bc
to
ae5988a
Compare
638892e
to
8b75db9
Compare
void main() { | ||
// test special cases | ||
// distance(inf, 1.0) = inf | ||
Result[0] = distance(X[0].x, Y[0].x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The degenerate scalar case is not that interesting for distance, since it just translates to fsub. Vector distance translates to fsub, fmul+fadd per component, sqrt.
So these scalar cases are really only testing the behavior of fsub.
... | ||
#--- end | ||
|
||
# UNSUPPORTED: Clang-Vulkan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Clang-Vulkan unsupported? Sorry if this has been explained before and I forgot or missed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# | Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-08742 ]
# | vkCreateShaderModule(): SPIR-V Extension SPV_KHR_float_controls2 was declared, but one of the following requirements is required (1.4.0 (0x00404000) or VK_KHR_shader_float_controls2).
is what I get when running it without that line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment about that in the tests?
15dded5
to
977c5fa
Compare
- Name: X | ||
Format: Float32 | ||
Stride: 16 | ||
Data: [ inf, NaN, -inf, 0 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would -0 also an interesting value to test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, looks like it didn't affect any of the expected results however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there needs to be an adjustment in approach due to the intended purpose of these tests.
- I don't think we need NaN/Inf/Denorm tests
- Values used should test full operation/expansion within reasonable ranges and precisions for confidence that the expansion used is correct, but not hyper-sensitive to precision
- Don't just test degenerate edge cases that could pass with an incomplete expansion
- ULP tolerance should be higher to allow for valid variances in operation expansions
- Need constant (literal) input cases to test constant folding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this particular test is necessary, since the purpose of this test suite is to make sure Clang produces the same key DXIL / SPIR-V code as DXC to implement the operation.
The important aspects to test would be the forms of HLSL that generate different operations/dimensions, and a variety of reasonable inputs to verify that the operations performed are the same.
I thought edge cases like these aren't what we care about for this test suite.
Additionally, the denorm tests (after which this file is apparently named) aren't even interesting, as their results would be identical if those denorms were replaced with 0's.
// distance({0.0, 0.0, 0.0}, {3.0, 4.0, 12.0}) = 13.0 | ||
float R2 = distance(X[0].xyz, Y[0].xyz); | ||
Result[2] = R2; | ||
// distance({0.0, 0.0, 0.0, 0.0}, {3.0, 4.0, 12.0, 84.0}) = 85.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always using 0's for the first argument is an edge case that doesn't even require the full operation expansion (initial subtraction could be omitted, making it the same as length
). It would be better to test some random values in reasonable ranges on both sides with a reasonable ULP tolerance for comparison of expected results. That should be sufficient to show that the correct operations are used for each compiler scenario.
Testing the exact precision of implementations isn't the point of this test either, so having a higher tolerance than necessary would probably not be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to think of it, one special case that SHOULD be tested is when inputs are constant. In that case, the compiler (likely) constant-folds operations, which is a separate code path.
Constant inputs should be tested for most/all math ops.
Results: | ||
- Result: CheckResult | ||
Rule: BufferFloatULP | ||
ULPT: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ULP of 1 seems pretty tight. Since the expansion could use dot or fma with varying ordering, and uses sqrt, it seems possible you could exceed the tolerance on a perfectly valid implementation.
- Name: X | ||
Format: Float32 | ||
Stride: 16 | ||
Data: [ 1.125, 2.5, 4.75, 6.625 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be interesting to test some negative values? (same for the half
test)
Result[5] = R2_constant; | ||
|
||
// distance({1.125, 2.5, 4.75, 6.625}, {2.375, 5.25, 8.375, 5.30}) = 4.90115 | ||
float R3 = distance(X[0].xyzw, Y[0].xyzw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: you don't need to do X[0].xyzw
and Y[0].xyzw
, you can just do distance(X[0], Y[0])
(same for the half
test)
Data: [ 0x3c80, 0x4100, 0x44c0, 0x46a0 ] | ||
- Name: Y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be useful to add comments under the Data
lines listing these values, even though you have them commented in main so you don't have to scroll up to look for/match them
Data: [ 0x3c80, 0x4100, 0x44c0, 0x46a0 ]
# 1.125, 2.5, 4.75, 6.625
@@ -0,0 +1,100 @@ | |||
#--- source.hlsl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember for ldexp
, @spall said to just name my files <intrinsic>.32.test
and <intrinsic>.16.test
to make it clear there isn't a missing int16.test
file. Probably want her input for this though
This PR adds tests for the
distance
function. Adds float16 and float32 test files.Fixes #175