8000 [SYCL][FE][Driver] Implement floating point accuracy control by zahiraam · Pull Request #8280 · intel/llvm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[SYCL][FE][Driver] Implement floating point accuracy control #8280

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

Merged
merged 55 commits into from
Jun 14, 2023

Conversation

zahiraam
Copy link
Contributor
@zahiraam zahiraam commented Feb 9, 2023

This patch implements the accuracy controls for floating-point math functions in DPC++. Using the -ffp-accuracy command line option, the user can request an accuracy level for all math functions or for specific ones. Calls to fpbuiltin intrinsics llvm.fpbuilin.* are then generated.

Syntax:

Linux: -ffp-accuracy=[default|value][:funclist]
Windows: /Qfp-accuracy:[default|value][:funclist]

funclist is an optional comma separated list of math library functions.

-ffp-accuracy=[default|value]
default: Use the implementation defined accuracy for all math library functions.
This is equivalent to not using this option.
value: Use the defined standard accuracy for what each accuracy value
means for all math library functions.

-ffp-accuracy=[default|value][:funclist]

default: Use the implementation defined accuracy for the math library functions in funclist.
This is equivalent to not using this option.
value: Use the defined standard accuracy for what each accuracy value
means for the math library functions in funclist.

value is one of the following values denoting the library function accuracy.

high This is equivalent to max-error = 1.0.
medium This is equivalent to max-error = 4.
low This is equivalent to accuracy-bits = 11 for single-precision functions.
accuracy-bits = 26 for double-precision functions.
sycl Determined by the OpenCL specification for math function accuracy: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#relative-error-as-ulps
cuda Determined by standard https://docs.nvidia.com/cuda/cuda-c-programming-guide/#mathematical-functions-appendix

This is a draft patch mostly to check that the use of TargetLibraryInfo
can be used from the FE.
Andy let me know if that's what you were thingking about?
// on the function (IntrinsicID) and the command line accuracy (FPAccuracyIntrinsicID)
// FPAccuracyVal = TLI.getFPAccuracy(F->getName(), FPAccuracyIntrinsicID)
// auto *AccuracyMDS = MDString::get(CGF.Builder.getContext(), FPAccuracyVal);
return CGF.Builder.CreateCall(F, {Src0, AccuracyMD});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the mock-up I shared used a metadata argument with a string like you have hear, but I ended up switching that to represent the accuracy as a numeric value using a callsite attribute. See PR #8134.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I knew that was temporary. I was shooting for this IR:

call float @llvm.experimental.fpaccuracy.cos.f32(float %0, "float ulp-value")

but we need to have a way to calculate the ulp error. From you message in Team and comments below, it looks like the FE needs to compute this ulp error without going through the TargetLibraryInfoImp? So, it would be a new function depending on the library function name and the fp-accuracy option given in the command line (or FPA_default if no option is used)?

Do you mean fpbuiltin-max-error? This attribute still needs the ulp error value.

So, this is the IR you are expecting?
call float @llvm.experimental.fpaccuracy.cos.f32(float %0) #10
attributes #0 = { "fpbuiltin-max-error"="2.5" }

If yes, the FE needs to generate a new attribute to mark the function and calculate the ulp error value (the way I describe above).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the mapping still needs to come from the backend because we'll want other languages (like Fortran) to be able to use the same functionality. I'll think about this and try to come up with a proposal. If you want to put a placeholder function in the front end for now, that's fine.

if (FPAccuracyIntrinsicID != Intrinsic::not_intrinsic) {
LangOptions::FPAccuracyKind FPAccuracy = CGF.getLangOpts().getFPAccuracy();
// Enter this part of the condition only when TLI.isFPACCuracyAvailable is
// true, implying FPAccuary != LangOptions::FPA_Default.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this assumption is correct. It's possible that we'll have a back-end that supports multiple accuracy implementations but we want to use the default accuracy anyway. In fact, that's probably going to be the most common case.

@zahiraam zahiraam temporarily deployed to aws February 9, 2023 20:12 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws February 14, 2023 00:04 — with GitHub Actions Inactive
Added a map to LangOption that will map the function in
the function list of command line to its accuracy.
@zahiraam zahiraam temporarily deployed to aws March 2, 2023 03:44 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws April 18, 2023 14:12 — with GitHub Actions Inactive
def warn_function_fp_accuray_already_set : Warning <"FP accuracy value of '%0' has already "
"been assigned to 8000 function '%1'">;
def warn_all_fp_accuray_already_set : Warning <"FP accuracy value of '%0' has already "
"been assigned to all functions in the program">;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a way to disable these diagnostics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to disable them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an informative diagnostic, but typically warnings have a way to be disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can create the warning in a new group:
def FPAccuracyWrongValue : DiagGroup<"wrong-value-of-fp-accuracy">;
and then use the -Wno-wrong-value-of-fp-accuracy on the command line to disable the warning. Is that what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's what I mean. Maybe: "fp-accuracy-value" would be sufficient here for the name.

@zahiraam
Copy link
Contributor Author

@mdtoguchi Thanks for taking a look at it.

@zahiraam zahiraam temporarily deployed to aws April 18, 2023 17:25 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws April 18, 2023 20:58 — with GitHub Actions Inactive
@asudarsa asudarsa self-requested a review June 12, 2023 15:49
llvm::AttributeList AttrList;
// sincos() doesn't return a value, but it still has a type associated with
// it that corresponds to the operand type.
CGF.CGM.getFPAccuracyFuncAttributes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a AttrList here? Is there a scenario where more than one such attribute can be attached to a builtin call?

Thanks

Copy link
Contributor Author
@zahiraam zahiraam Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there is a call to getFPAccuracyFuncAttributes which in tun will call getDefaultFunctionFPAccuracyAttributes that can additional attributes to the function. So. I think a list is needed here.

Copy link
Contributor Author
@zahiraam zahiraam Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think you are right that the AttrList can be a single attribute instead of a list. Added a TODO comment as we discussed offline. Thanks.

@zahiraam zahiraam temporarily deployed to aws June 12, 2023 17:41 — with GitHub Actions Inactive
Copy link
Contributor
@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo. LGTM. Thanks for implementing this.

@zahiraam zahiraam temporarily deployed to aws June 12, 2023 19:34 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws June 12, 2023 20:22 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws June 13, 2023 12:05 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws June 13, 2023 21:52 — with GitHub Actions Inactive
@zahiraam zahiraam temporarily deployed to aws June 13, 2023 22:31 — with GitHub Actions Inactive
@zahiraam
Copy link
Contributor Author
zahiraam commented Jun 14, 2023

@intel/llvm-gatekeepers can you consider merging this please? Thanks.

@dm-vodopyanov
Copy link
Contributor
dm-vodopyanov commented Jun 14, 2023

@intel/llvm-gatekeepers can you consider merging this please? Thanks.

@zahiraam please update the caption of PR in accordance with https://github.com/intel/llvm/blob/sycl/sycl/doc/developer/ContributeToDPCPP.md#commit-message

@zahiraam zahiraam changed the title Floating point accuracy control. [SYCL] Floating point accuracy control. Jun 14, 2023
@zahiraam zahiraam changed the title [SYCL] Floating point accuracy control. [SYCL] Add support for floating point accuracy control. Jun 14, 2023
@dm-vodopyanov dm-vodopyanov changed the title [SYCL] Add support for floating point accuracy control. [SYCL][FE][Driver] Implement floating point accuracy control Jun 14, 2023
@dm-vodopyanov
Copy link
Contributor

Will be merged as soon as post-commit turns green.

@dm-vodopyanov dm-vodopyanov merged commit 405778a into intel:sycl Jun 14, 2023
@dm-vodopyanov
Copy link
Contributor
dm-vodopyanov commented Jun 14, 2023

Failures in post-commit:

Failed Tests (2):
  Clang :: CodeGen/fp-accuracy.c
  Clang :: Driver/fp-accuracy.c

https://github.com/intel/llvm/actions/runs/5267586087/jobs/9523035374

@zahiraam could you please address them?

fineg74 pushed a commit to fineg74/llvm that referenced this pull request Jun 15, 2023
)

This patch implements the accuracy controls for floating-point math
functions in DPC++. Using the -ffp-accuracy command line option, the
user can request an accuracy level for all math functions or for
specific ones. Calls to fpbuiltin intrinsics llvm.fpbuilin.* are then
generated.

Syntax: 

Linux:   -ffp-accuracy=[default|value][:funclist]
Windows: /Qfp-accuracy:[default|value][:funclist]

funclist is an optional comma separated list of math library functions.

-ffp-accuracy=[default|value]
default: Use the implementation defined accuracy for all math library
functions.
            This is equivalent to not using this option.         
value: Use the defined standard accuracy for what each accuracy value
            means for all math library functions.

-ffp-accuracy=[default|value][:funclist]

default: Use the implementation defined accuracy for the math library
functions in funclist.
            This is equivalent to not using this option.
value: Use the defined standard accuracy for what each accuracy value
            means for the math library functions in funclist.

value is one of the following values denoting the library function
accuracy.

high	This is equivalent to max-error = 1.0.
medium	This is equivalent to max-error = 4.
low This is equivalent to accuracy-bits = 11 for single-precision
functions.
accuracy-bits = 26 for double-precision functions.
sycl Determined by the OpenCL specification for math function accuracy:
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#relative-error-as-ulps
cuda Determined by standard
https://docs.nvidia.com/cuda/cuda-c-programming-guide/#mathematical-functions-appendix
@aelovikov-intel
Copy link
Contributor

@zahiraam could you please address them?

Any updates on this? If the fix isn't ready, can we just disable the tests to fix post-commit?

@zahiraam
Copy link
Contributor Author

@zahiraam could you please address them?

Any updates on this? If the fix isn't ready, can we just disable the tests to fix post-commit?

@aelovikov-intel I was able to reproduce the issue and working on it. Yes for now, we can diable the LIT tests and I will work on it. Thanks.

@zahiraam
Copy link
Contributor Author

Also it looks like it's failing only on a release self-build. With the debug self-build the 2 tests are passing.

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.

0