Skip to content

Add support for lowering mhlo.fft to Linalg. - #5450

Merged
hanhanW merged 10 commits into
iree-org:mainfrom
hanhanW:dft
Apr 20, 2021
Merged

hanhanW merged 10 commits into
iree-org:mainfrom
hanhanW:dft

Conversation

@hanhanW

@hanhanW hanhanW commented Apr 15, 2021

Copy link
Copy Markdown
Contributor

Only RFFT type is supported, which means the inputs are all real
numbers. Since we do not handle complex numbers in IREE and mhlo.fft
returns a complex number, we have to use mhlo.complex op to pack real
part and imaginary part together. And rely on canonicalization patterns
to fold it away. They will be folded away because we ran
PopulateComplexLoweringPatterns in HLOToHLOPreprocessing pass, if
there are complex number computation, mhlo.real/imag will be created.

The implementation is not FFT algorithm. It follows DFT definition to
support naive solution. See definition
https://en.wikipedia.org/wiki/Discrete_Fourier_transform

Fixes #5299

@hanhanW
hanhanW requested a review from asaadaldien April 15, 2021 16:40
@google-cla google-cla Bot added the cla: yes label Apr 15, 2021
@hanhanW

hanhanW commented Apr 15, 2021

Copy link
Copy Markdown
Contributor Author

I'd like to add end-to-end testing later. It only works on Linalg on tensors, but current iree/test/e2e/*/BUILD is a bit messy.

@hanhanW

hanhanW commented Apr 15, 2021

Copy link
Copy Markdown
Contributor Author

I'd like to add end-to-end testing later. It only works on Linalg on tensors, but current iree/test/e2e/*/BUILD is a bit messy.

I think I was wrong, I probably can add the e2e test.

@hanhanW

hanhanW commented Apr 16, 2021

Copy link
Copy Markdown
Contributor Author

This is really weird, I can't fix the tests.

I hacked into printf representation, and got something weird.

https://github.com/google/iree/blob/abab8572e3bf3f81dca6fcd9de18e7660a0c2345/iree/hal/string_util.cc#L394-L396

265: Expected equality of these values. Contents does not match.
265:   lhs:
265:     17xf32=666.84601 -0.00001 -590.16931 -0.00000 593.44849 -0.00009 -579.52881 -0.00041 629.95404 0.00061 -567.11255 -0.00021 591
.75140 0.00042 -583.18927 -0.00062 630.84601
265:   rhs:
265:     17xf32=666.84601 -0.00001 -590.16931 -0.00000 593.44849 -0.00009 -579.52881 -0.00041 629.95404 0.00061 -567.11255 -0.00021 591
.75140 0.00042 -583.18927 -0.00062 630.84601

They look identical to me. I even just copy-paste the result, and can still get some similar failures.

@hanhanW

hanhanW commented Apr 16, 2021

Copy link
Copy Markdown
Contributor Author

oh, I'm so stupid >~<
It should be expect_almost_eq_const, not expect_eq_const

@hanhanW
hanhanW requested a review from asaadaldien April 19, 2021 11:35
hanhanW added 8 commits April 19, 2021 09:41
Only RFFT type is supported, which means the inputs are all real
numbers. Since we do not handle complex numbers in IREE and mhlo.fft
returns a complex number, we have to use mhlo.complex op to pack real
part and imaginary part together. And rely on canonicalization patterns
to fold it away. They will be folded away because we ran
`PopulateComplexLoweringPatterns` in HLOToHLOPreprocessing pass, if
there are complex number computation, mhlo.real/imag will be created.

The implementation is not FFT algorithm. It follows DFT definition to
support naive solution. See definition
https://en.wikipedia.org/wiki/Discrete_Fourier_transform
Comment thread iree/test/e2e/xla_ops/BUILD Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for lowering mhlo.fft in codegen

2 participants