Skip to content
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

[SYCL] Add option -fsycl-use-integration-headers #14759

Open
wants to merge 18 commits into
base: sycl
Choose a base branch
from

Conversation

premanandrao
Copy link
Contributor

@premanandrao premanandrao commented Jul 25, 2024

Add option -fsycl-use-integration-headers to enable integration between device and host compilation phases using integration headers and footers. This is currently the default behavior.

The option is passed through to the cc1 phase along with a macro __INTEL_SYCL_USE_INTEGRATION_HEADERS.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

See comments; I don't understand why the option is considered related to code gen.

I still don't love the option name. The option controls two major behaviors:

  1. Disabling the generation of integration headers and associated options used in generated compiler actions.
  2. Setting the macro the SYCL run-time library will check to determine how to access kernel information.

Perhaps we shouldn't use a single option to influence both of these behaviors. How about this approach?

  1. Rename the option to -f[no-]sycl-integration-headers to enable/disable generation and use of SYCL integration headers in the generated compiler actions. This option won't be upstreamed.
  2. Have the SYCL run-time library check to see if the builtin functions are available (via has_builtin or has_feature or similar) and, if so, default to using the builtins unless the __INTEL_SYCL_USE_INTEGRATION_HEADERS macro is defined.
  3. Modify the dpcpp/icx drivers to predefine __INTEL_SYCL_USE_INTEGRATION_HEADERS until we are ready to change the default behavior for SYCL aware host compilers. Continue to predefine the macro for SYCL unaware third party host compilers indefinitely. For testing, we can undefine the macro on the command line.
  4. Allow the user to manually define the macro on the command line as a workaround for any backward compatibility issues that arise.

clang/include/clang/Basic/DiagnosticDriverKinds.td Outdated Show resolved Hide resolved
clang/include/clang/Driver/Options.td Outdated Show resolved Hide resolved
clang/include/clang/Basic/CodeGenOptions.def Outdated Show resolved Hide resolved
clang/lib/Driver/Driver.cpp Outdated Show resolved Hide resolved
@premanandrao premanandrao changed the title [SYCL] Add option -fsycl-use-builtins-for-integration [SYCL] Add option -fsycl-use-integration-headers Jul 31, 2024
clang/test/Driver/sycl-use-int-headers.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/Driver.cpp Outdated Show resolved Hide resolved
clang/include/clang/Driver/Options.td Outdated Show resolved Hide resolved
clang/test/Driver/sycl-use-int-headers.cpp Show resolved Hide resolved
clang/lib/Driver/Driver.cpp Outdated Show resolved Hide resolved
clang/include/clang/Driver/Options.td Outdated Show resolved Hide resolved
Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

I added some minor comments and suggestions. The new updates look good to me.

I might have more comments to add depending on whether we can figure out how to get the BoolFOption approach to work with the new option definition.

Comment on lines +320 to +326
LANGOPT(SYCLUseIntegrationHeaders, 1, 1, "Use integration headers for "
"communication between device and host compilation phases")
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 this is fine. Here is another suggestion; use which ever one you prefer.

Suggested change
LANGOPT(SYCLUseIntegrationHeaders, 1, 1, "Use integration headers for "
"communication between device and host compilation phases")
LANGOPT(SYCLUseIntegrationHeaders, 1, 1, "Use integration headers for "
"coordination of device and host compilation phases")

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 decided to leave the old wording in place.

clang/lib/Driver/Driver.cpp Outdated Show resolved Hide resolved
clang/test/Driver/sycl-use-int-headers.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/Driver.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

The changes to use BoolFOption for the option definition looks great. Requesting changes to deal with the default use-integration-header behavior being specified in multiple locations. I added a couple of other minor comments as well.

Comment on lines 6979 to 6980
" that integration headers be used for "
"communication between the host and the device compilations. SYCL Only">>;
Copy link
Contributor

Choose a reason for hiding this comment

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

For pedantic consistency, I suggest:

Suggested change
" that integration headers be used for "
"communication between the host and the device compilations. SYCL Only">>;
" that integration headers be used for"
" communication between the host and the device compilations. SYCL Only">>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 1129 to 1150
// -fno-sycl-use-integration-headers cannot be used with
// -fsycl-host-compiler.
if (SYCLHostCompiler && SYCLUIHArg->getOption().matches(
options::OPT_fno_sycl_use_integration_headers))
Diag(clang::diag::err_drv_option_conflict)
<< SYCLHostCompiler->getSpelling().split('=').first
<< "-fno-sycl-use-integration-headers";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of getLastArg() above is good since it ensures that the err_drv_sycl_opt_requires_opt diagnostic is only issued when one of the options is explicitly used. I think we can simplify the check for conflict with the host compiler option a bit though and, while we're add it, perhaps future proof the code a bit against a change of default behavior. I suggest colocating the following with the declarations of HasSYCL and HasValidSYCLRuntime:

bool UseSYCLIntegrationHeaders =
    Args.hasFlag(options::OPT_fsycl_use_integration_headers,
                  options::OPT_fno_sycl_use_integration_headers,
                  true);

Then, break this diagnostic out of the enclosing if statement:

Suggested change
// -fno-sycl-use-integration-headers cannot be used with
// -fsycl-host-compiler.
if (SYCLHostCompiler && SYCLUIHArg->getOption().matches(
options::OPT_fno_sycl_use_integration_headers))
Diag(clang::diag::err_drv_option_conflict)
<< SYCLHostCompiler->getSpelling().split('=').first
<< "-fno-sycl-use-integration-headers";
}
}
// -fno-sycl-use-integration-headers cannot be used with
// -fsycl-host-compiler.
if (SYCLHostCompiler && !UseSYCLIntegrationHeaders) {
Diag(clang::diag::err_drv_option_conflict)
<< SYCLHostCompiler->getSpelling().split('=').first
<< "-fno-sycl-use-integration-headers";
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +4962 to +4987
if (!Args.hasFlag(options::OPT_fsycl_use_integration_headers,
options::OPT_fno_sycl_use_integration_headers,
true))
Copy link
Contributor

Choose a reason for hiding this comment

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

The default value of true is passed in multiple places (here, in Driver::BuildActions(), in Clang::ConstructHostCompilerJob(), in Clang::ConstructJob(), and in the suggested change I offered in a previous comment). Perhaps we should define the default in one place somewhere. There are a few different approaches. I don't have a strong opinion on any of these, but I think we should do something.

  • We could introduce a constant that is passed in each of the calls to hasFlag().
  • We could introduce a function to be called at each of these locations to ascertain whether integration headers are being used; that function would query the options and supply the default.
  • We could check the options in one place and store that result.

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 went with option 2. Thanks @tahonermann

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! It looks like this particular location didn't get updated to use it though.

Add option -fsycl-use-builtins-for-integration to enable integration
between device and host compilation phases without using integration
headers and footers.

The option is passed through to the cc1 phase along with a macro
__INTEL_SYCL_USE_BUILTINS_FOR_INTEGRATION.
@premanandrao
Copy link
Contributor Author

And apologies; there were merge conflicts and I had to do a force push after resolving them.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

This is looking good. I think I spotted a couple of minor issues.

Comment on lines +7000 to +7006
defm sycl_use_integration_headers : BoolFOption<"sycl-use-integration-headers",
LangOpts<"SYCLUseIntegrationHeaders">, DefaultTrue,
PosFlag<SetTrue, [], [ClangOption, CLOption], "Specify">,
NegFlag<SetFalse, [], [ClangOption, CLOption], "Do not specify">,
BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option],
" that integration headers be used for communication"
" between the host and the device compilations. SYCL Only">>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent indentation with respect to surrounding code.

Suggested change
defm sycl_use_integration_headers : BoolFOption<"sycl-use-integration-headers",
LangOpts<"SYCLUseIntegrationHeaders">, DefaultTrue,
PosFlag<SetTrue, [], [ClangOption, CLOption], "Specify">,
NegFlag<SetFalse, [], [ClangOption, CLOption], "Do not specify">,
BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option],
" that integration headers be used for communication"
" between the host and the device compilations. SYCL Only">>;
defm sycl_use_integration_headers : BoolFOption<"sycl-use-integration-headers",
LangOpts<"SYCLUseIntegrationHeaders">, DefaultTrue,
PosFlag<SetTrue, [], [ClangOption, CLOption], "Specify">,
NegFlag<SetFalse, [], [ClangOption, CLOption], "Do not specify">,
BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option],
" that integration headers be used for communication"
" between the host and the device compilations. SYCL Only">>;

if (SYCLUIHArg) {
// -f[no-]sycl-use-integration-headers cannot be used without
// -fsycl. (-fintelfpga implies -fsycl).
if (!HasSYCL && !SYCLfpga)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason not to include the test of SYCLfpga in the initialization of HasSYCL above? As is, it looks like HasValidSYCLRuntime will be initialized to false if -fintelfpga is passed (but -fsycl is not).

Comment on lines +4962 to +4987
if (!Args.hasFlag(options::OPT_fsycl_use_integration_headers,
options::OPT_fno_sycl_use_integration_headers,
true))
Copy link
Contributor

Choose a reason for hiding this comment

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

Great! It looks like this particular location didn't get updated to use it though.

Comment on lines +7305 to +7309
// If -fno-sycl-use-integration-headers is speficified, don't generate
// integration headers and footers.
if (!Args.hasFlag(options::OPT_fsycl_use_integration_headers,
options::OPT_fno_sycl_use_integration_headers, true))
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If -fno-sycl-use-integration-headers is speficified, don't generate
// integration headers and footers.
if (!Args.hasFlag(options::OPT_fsycl_use_integration_headers,
options::OPT_fno_sycl_use_integration_headers, true))
continue;
// If -fno-sycl-use-integration-headers is speficified, don't generate
// integration headers and footers.
if (!getSYCLUseIntegrationHeaders(Args))
continue;

@premanandrao
Copy link
Contributor Author

@tahonermann, when you have time, could you please review this again?

@tahonermann
Copy link
Contributor

@tahonermann, when you have time, could you please review this again?

@premanandrao, it looks like the latest changes are still what I reviewed 5 days ago :)

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.

3 participants