[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, clementval wrote: I switch to use the `-x cuda` option which has a similar meaning. https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/clementval deleted https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/84944 >From e42e8fe7f1dfe503a6735ef76e9d6483f5c9b5ec Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 12 Mar 2024 09:33:17 -0700 Subject: [PATCH 1/2] [flang][cuda] Add -fcuda option --- clang/include/clang/Driver/Options.td | 3 +++ clang/lib/Driver/ToolChains/Flang.cpp | 1 + flang/lib/Frontend/CompilerInvocation.cpp | 6 ++ flang/lib/Frontend/FrontendAction.cpp | 11 --- flang/test/Driver/cuda-option.f90 | 13 + flang/test/Driver/driver-help-hidden.f90 | 1 + flang/test/Driver/driver-help.f90 | 2 ++ 7 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 flang/test/Driver/cuda-option.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index aca8c9b0d5487a..bd28ec90bf7283 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, + HelpText<"Enable CUDA">; } // let Visibility = [FC1Option, FlangOption] def J : JoinedOrSeparate<["-"], "J">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 6168b42dc78292..9b47ab0e7fcbf3 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -41,6 +41,7 @@ void Flang::addFortranDialectOptions(const ArgList , options::OPT_fopenmp, options::OPT_fopenmp_version_EQ, options::OPT_fopenacc, +options::OPT_fcuda, options::OPT_finput_charset_EQ, options::OPT_fimplicit_none, options::OPT_fno_implicit_none, diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 4707de0e976ca7..435f1df152c40d 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -877,6 +877,12 @@ static bool parseDialectArgs(CompilerInvocation , llvm::opt::ArgList , if (args.hasArg(clang::driver::options::OPT_flarge_sizes)) res.getDefaultKinds().set_sizeIntegerKind(8); + // -fcuda + if (args.hasArg(clang::driver::options::OPT_fcuda)) { +res.getFrontendOpts().features.Enable( +Fortran::common::LanguageFeature::CUDA); + } + // -fopenmp and -fopenacc if (args.hasArg(clang::driver::options::OPT_fopenacc)) { res.getFrontendOpts().features.Enable( diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp index 599b4e11f0cfbd..bb1c239540d9f5 100644 --- a/flang/lib/Frontend/FrontendAction.cpp +++ b/flang/lib/Frontend/FrontendAction.cpp @@ -86,9 +86,14 @@ bool FrontendAction::beginSourceFile(CompilerInstance , invoc.collectMacroDefinitions(); } - // Enable CUDA Fortran if source file is *.cuf/*.CUF. - invoc.getFortranOpts().features.Enable(Fortran::common::LanguageFeature::CUDA, - getCurrentInput().getIsCUDAFortran()); + if (!invoc.getFortranOpts().features.IsEnabled( + Fortran::common::LanguageFeature::CUDA)) { +// Enable CUDA Fortran if source file is *.cuf/*.CUF and not already +// enabled. +invoc.getFortranOpts().features.Enable( +Fortran::common::LanguageFeature::CUDA, +getCurrentInput().getIsCUDAFortran()); + } // Decide between fixed and free form (if the user didn't express any // preference, use the file extension to decide) diff --git a/flang/test/Driver/cuda-option.f90 b/flang/test/Driver/cuda-option.f90 new file mode 100644 index 00..7bd1b3ddbffc3c --- /dev/null +++ b/flang/test/Driver/cuda-option.f90 @@ -0,0 +1,13 @@ +! Test -fcuda option +! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s + +program main +#if _CUDA + integer :: var = _CUDA +#endif + integer, device :: dvar +end program + +! CHECK-LABEL: PROGRAM main +! CHECK: INTEGER :: var = 1 +! CHECK: INTEGER, DEVICE :: dvar diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index 44dbac44772b29..7b2e28263a825a 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -32,6 +32,7 @@ ! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics ! CHECK-NEXT: -fconvert= Set endian conversion of data for unformatted files +! CHECK-NEXT: -fcuda Enable CUDA ! CHECK-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, clementval wrote: The alternative is to use the same as `clang` with `-x `. I will need to check if we can filter the language so only the ones meaningful to flang can be passed. https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/clementval edited https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
@@ -0,0 +1,13 @@ +! Test -fcuda option +! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s clementval wrote: Without it, it would just fail during parsing. Do you want a test that check the failure? https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
@@ -0,0 +1,13 @@ +! Test -fcuda option +! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s banach-space wrote: Could you add a RUN line without enabling CUDA? Otherwise it's hard to see what's being tested and what the impact of enabling CUDA is. https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, banach-space wrote: I don't quite understand what actually `-fcuda` enables. Could the flag be more descriptive and the help text expanded? Also, what's the equivalent in Clang? We ought to keep both drivers in sync. In particular, if this is something specific to Flang then I would avoid generic names like `-fcuda`. https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/jeanPerier approved this pull request. https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, vzakhari wrote: I wonder if we also want to wire it to clang's `-x cuda` option. It might be good to use the same flags for clang/flang in makefiles/cmake. Though, I am not sure if the meaning of the two options is exactly the same. Maybe someone else knows. https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/vzakhari edited https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/vzakhari approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/84944 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-flang-driver Author: Valentin Clement (バレンタイン クレメン) (clementval) Changes Flang driver was already able to enable the CUDA language feature base on the file extension but there was no command line option. This PR adds one. --- Full diff: https://github.com/llvm/llvm-project/pull/84944.diff 7 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+3) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+6) - (modified) flang/lib/Frontend/FrontendAction.cpp (+8-3) - (added) flang/test/Driver/cuda-option.f90 (+13) - (modified) flang/test/Driver/driver-help-hidden.f90 (+1) - (modified) flang/test/Driver/driver-help.f90 (+2) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index aca8c9b0d5487a..bd28ec90bf7283 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, + HelpText<"Enable CUDA">; } // let Visibility = [FC1Option, FlangOption] def J : JoinedOrSeparate<["-"], "J">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 6168b42dc78292..9b47ab0e7fcbf3 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -41,6 +41,7 @@ void Flang::addFortranDialectOptions(const ArgList , options::OPT_fopenmp, options::OPT_fopenmp_version_EQ, options::OPT_fopenacc, +options::OPT_fcuda, options::OPT_finput_charset_EQ, options::OPT_fimplicit_none, options::OPT_fno_implicit_none, diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 4707de0e976ca7..435f1df152c40d 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -877,6 +877,12 @@ static bool parseDialectArgs(CompilerInvocation , llvm::opt::ArgList , if (args.hasArg(clang::driver::options::OPT_flarge_sizes)) res.getDefaultKinds().set_sizeIntegerKind(8); + // -fcuda + if (args.hasArg(clang::driver::options::OPT_fcuda)) { +res.getFrontendOpts().features.Enable( +Fortran::common::LanguageFeature::CUDA); + } + // -fopenmp and -fopenacc if (args.hasArg(clang::driver::options::OPT_fopenacc)) { res.getFrontendOpts().features.Enable( diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp index 599b4e11f0cfbd..bb1c239540d9f5 100644 --- a/flang/lib/Frontend/FrontendAction.cpp +++ b/flang/lib/Frontend/FrontendAction.cpp @@ -86,9 +86,14 @@ bool FrontendAction::beginSourceFile(CompilerInstance , invoc.collectMacroDefinitions(); } - // Enable CUDA Fortran if source file is *.cuf/*.CUF. - invoc.getFortranOpts().features.Enable(Fortran::common::LanguageFeature::CUDA, - getCurrentInput().getIsCUDAFortran()); + if (!invoc.getFortranOpts().features.IsEnabled( + Fortran::common::LanguageFeature::CUDA)) { +// Enable CUDA Fortran if source file is *.cuf/*.CUF and not already +// enabled. +invoc.getFortranOpts().features.Enable( +Fortran::common::LanguageFeature::CUDA, +getCurrentInput().getIsCUDAFortran()); + } // Decide between fixed and free form (if the user didn't express any // preference, use the file extension to decide) diff --git a/flang/test/Driver/cuda-option.f90 b/flang/test/Driver/cuda-option.f90 new file mode 100644 index 00..7bd1b3ddbffc3c --- /dev/null +++ b/flang/test/Driver/cuda-option.f90 @@ -0,0 +1,13 @@ +! Test -fcuda option +! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s + +program main +#if _CUDA + integer :: var = _CUDA +#endif + integer, device :: dvar +end program + +! CHECK-LABEL: PROGRAM main +! CHECK: INTEGER :: var = 1 +! CHECK: INTEGER, DEVICE :: dvar diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index 44dbac44772b29..7b2e28263a825a 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -32,6 +32,7 @@ ! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics ! CHECK-NEXT: -fconvert= Set endian conversion of data for unformatted files +! CHECK-NEXT: -fcuda Enable CUDA ! CHECK-NEXT: -fdefault-double-8 Set the default double
[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/84944 Flang driver was already able to enable the CUDA language feature base on the file extension but there was no command line option. This PR adds one. >From e42e8fe7f1dfe503a6735ef76e9d6483f5c9b5ec Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 12 Mar 2024 09:33:17 -0700 Subject: [PATCH] [flang][cuda] Add -fcuda option --- clang/include/clang/Driver/Options.td | 3 +++ clang/lib/Driver/ToolChains/Flang.cpp | 1 + flang/lib/Frontend/CompilerInvocation.cpp | 6 ++ flang/lib/Frontend/FrontendAction.cpp | 11 --- flang/test/Driver/cuda-option.f90 | 13 + flang/test/Driver/driver-help-hidden.f90 | 1 + flang/test/Driver/driver-help.f90 | 2 ++ 7 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 flang/test/Driver/cuda-option.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index aca8c9b0d5487a..bd28ec90bf7283 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays", defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride", PosFlag, NegFlag>; + +def fcuda : Flag<["-"], "fcuda">, Group, + HelpText<"Enable CUDA">; } // let Visibility = [FC1Option, FlangOption] def J : JoinedOrSeparate<["-"], "J">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 6168b42dc78292..9b47ab0e7fcbf3 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -41,6 +41,7 @@ void Flang::addFortranDialectOptions(const ArgList , options::OPT_fopenmp, options::OPT_fopenmp_version_EQ, options::OPT_fopenacc, +options::OPT_fcuda, options::OPT_finput_charset_EQ, options::OPT_fimplicit_none, options::OPT_fno_implicit_none, diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 4707de0e976ca7..435f1df152c40d 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -877,6 +877,12 @@ static bool parseDialectArgs(CompilerInvocation , llvm::opt::ArgList , if (args.hasArg(clang::driver::options::OPT_flarge_sizes)) res.getDefaultKinds().set_sizeIntegerKind(8); + // -fcuda + if (args.hasArg(clang::driver::options::OPT_fcuda)) { +res.getFrontendOpts().features.Enable( +Fortran::common::LanguageFeature::CUDA); + } + // -fopenmp and -fopenacc if (args.hasArg(clang::driver::options::OPT_fopenacc)) { res.getFrontendOpts().features.Enable( diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp index 599b4e11f0cfbd..bb1c239540d9f5 100644 --- a/flang/lib/Frontend/FrontendAction.cpp +++ b/flang/lib/Frontend/FrontendAction.cpp @@ -86,9 +86,14 @@ bool FrontendAction::beginSourceFile(CompilerInstance , invoc.collectMacroDefinitions(); } - // Enable CUDA Fortran if source file is *.cuf/*.CUF. - invoc.getFortranOpts().features.Enable(Fortran::common::LanguageFeature::CUDA, - getCurrentInput().getIsCUDAFortran()); + if (!invoc.getFortranOpts().features.IsEnabled( + Fortran::common::LanguageFeature::CUDA)) { +// Enable CUDA Fortran if source file is *.cuf/*.CUF and not already +// enabled. +invoc.getFortranOpts().features.Enable( +Fortran::common::LanguageFeature::CUDA, +getCurrentInput().getIsCUDAFortran()); + } // Decide between fixed and free form (if the user didn't express any // preference, use the file extension to decide) diff --git a/flang/test/Driver/cuda-option.f90 b/flang/test/Driver/cuda-option.f90 new file mode 100644 index 00..7bd1b3ddbffc3c --- /dev/null +++ b/flang/test/Driver/cuda-option.f90 @@ -0,0 +1,13 @@ +! Test -fcuda option +! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s + +program main +#if _CUDA + integer :: var = _CUDA +#endif + integer, device :: dvar +end program + +! CHECK-LABEL: PROGRAM main +! CHECK: INTEGER :: var = 1 +! CHECK: INTEGER, DEVICE :: dvar diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index 44dbac44772b29..7b2e28263a825a 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -32,6 +32,7 @@ ! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics ! CHECK-NEXT: -fconvert= Set endian conversion of data for unformatted files +!