-
Notifications
You must be signed in to change notification settings - Fork 409
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
Add test for EmitReducePrecisionIR #16775
base: main
Are you sure you want to change the base?
Conversation
5cd9df3
to
a63e028
Compare
a63e028
to
f94a79d
Compare
Maybe such tests should be in xla/tests/reduce_precision_test.cc. That way it will be tested on backends which don't use element_ir_emitter. |
The function To test the functions declared in
In contrast, Given this, I believe that |
So we have different kind of tests:
For the tests you are adding here, I think filecheck based tests that use the hlo-opt tool would be the best fit. Can you please rewrite the tests based on that? You can take a look at .hlo files in xla/service/gpu/tests to see how to use it. |
Thank you, Adrian and Reed, for your feedback. I’d like to provide some additional context on why I’m using the GTest framework for this test and the associated code. The
The function generates a sequence of LLVM IR operations that convert an input number in f16 format to an output in a reduced-precision f16-like format, with fewer bits for the exponent and mantissa. The result is returned as an When working on f8E4M3 type support, it wasn’t immediately clear what LLVM IR or output I would get when reducing f16 to a 4-bit exponent and 3-bit mantissa. To explore this, I created a test that generates the LLVM IR and uses specific f16 constants as inputs. Since the input is a constant, the entire LLVM IR can be evaluated and simplified to a final result. By calling Note that the GPU compiler has its own separate The
It’s a unit test for a specific C++ function (EmitReducePrecisionIR), which uses the LLVM API internally to emit LLVM IR for the CPU compiler. Given this, I believe the test should use GTest along with the LLVM API to properly validate the result of |
f94a79d
to
7407fbb
Compare
Thanks for the explanation. If it is for the CPU backend, then I think @ezhulenev might be a better reviewer. |
Hi Eugene, Could you please review this PR? I've included details above explaining the necessity of the test and the reasoning behind using GTest with the LLVM API. |
7407fbb
to
57dd070
Compare
I noticed that the
EmitReducePrecisionIR
function fromxla/service/elemental_ir_emitter.h
is not covered by unit tests.Given its non-trivial logic, I believe it should be thoroughly tested, particularly for corner cases.
Changes in this PR:
EmitReducePrecisionIR
function inxla/service/elemental_ir_emitter.h
EmitReducePrecisionIR_F16ToF8e5m2
testEmitReducePrecisionIR_F16ToF8e4m3fn
testRelated PR: