|
| 1 | +# Copyright (c) 2018-2024, MPI-M |
| 2 | +# |
| 3 | +# Author: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de> |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: BSD-3-Clause |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without |
| 8 | +# modification, are permitted provided that the following conditions are met: |
| 9 | +# |
| 10 | +# 1. Redistributions of source code must retain the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer. |
| 12 | +# 2. Redistributions in binary form must reproduce the above copyright |
| 13 | +# notice, this list of conditions and the following disclaimer in the |
| 14 | +# documentation and/or other materials provided with the distribution. |
| 15 | +# 3. Neither the name of the copyright holder nor the names of its |
| 16 | +# contributors may be used to endorse or promote products derived from |
| 17 | +# this software without specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 23 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | +# POSSIBILITY OF SUCH DAMAGE. |
| 30 | + |
| 31 | +# ACX_LANG_OPENACC_FLAG([ACTION-IF-SUCCESS], |
| 32 | +# [ACTION-IF-FAILURE = FAILURE]) |
| 33 | +# ----------------------------------------------------------------------------- |
| 34 | +# Finds the compiler flag needed to enable OpenACC support. The result is |
| 35 | +# either "unknown", or the actual compiler flag required to enable OpenACC |
| 36 | +# support, which may be an empty string. |
| 37 | +# |
| 38 | +# Known flags: |
| 39 | +# GNU: -fopenacc |
| 40 | +# Cray: -hacc |
| 41 | +# Nvidia: -acc |
| 42 | +# |
| 43 | +# If successful, runs ACTION-IF-SUCCESS, otherwise runs ACTION-IF-FAILURE |
| 44 | +# (defaults to failing with an error message). |
| 45 | +# |
| 46 | +# The flag is cached in the acx_cv_[]_AC_LANG_ABBREV[]_openacc_flag variable. |
| 47 | +# |
| 48 | +# Upon successful run, you can check for the version of the standard supported |
| 49 | +# by the compiler by expanding: |
| 50 | +# AS_VAR_APPEND([_AC_LANG_PREFIX[]FLAGS], |
| 51 | +# [" $acx_cv_[]_AC_LANG_ABBREV[]_openacc_flag"]) |
| 52 | +# ACX_LANG_MACRO_CHECK_VALUE([_OPENACC]) |
| 53 | +# and checking for the value of the |
| 54 | +# acx_cv_[]_AC_LANG_ABBREV[]_macro__OPENACC_value shell variable. The possible |
| 55 | +# (successful) values of the variable are dates, which map to the versions of |
| 56 | +# the standard in the following way: |
| 57 | +# 202111 3.2 |
| 58 | +# 202011 3.1 |
| 59 | +# 201911 3.0 |
| 60 | +# 201811 2.7 |
| 61 | +# 201711 2.6 |
| 62 | +# 201510 2.5 |
| 63 | +# 201308 2.0 (the corrected version) |
| 64 | +# 201306 2.0 |
| 65 | +# 201111 1.0 |
| 66 | +# |
| 67 | +AC_DEFUN([ACX_LANG_OPENACC_FLAG], |
| 68 | + [m4_pushdef([acx_cache_var], [acx_cv_[]_AC_LANG_ABBREV[]_openacc_flag])dnl |
| 69 | + AC_MSG_CHECKING([for _AC_LANG compiler flag needed to enable OpenACC dnl |
| 70 | +support]) |
| 71 | + AC_CACHE_VAL([acx_cache_var], |
| 72 | + [acx_cache_var=unknown |
| 73 | + acx_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS |
| 74 | + AC_LANG_CONFTEST([_ACX_LANG_OPENACC]) |
| 75 | + for acx_lang_openacc_flag in '' -fopenacc -hacc -acc; do |
| 76 | + _AC_LANG_PREFIX[]FLAGS="${acx_save_[]_AC_LANG_PREFIX[]FLAGS} dnl |
| 77 | +$acx_lang_openacc_flag" |
| 78 | + AC_LINK_IFELSE([], [acx_cache_var=$acx_lang_openacc_flag]) |
| 79 | + test "x$acx_cache_var" != xunknown && break |
| 80 | + done |
| 81 | + rm -f conftest.$ac_ext |
| 82 | + _AC_LANG_PREFIX[]FLAGS=$acx_save_[]_AC_LANG_PREFIX[]FLAGS]) |
| 83 | + AS_IF([test -n "$acx_cache_var"], |
| 84 | + [AC_MSG_RESULT([$acx_cache_var])], |
| 85 | + [AC_MSG_RESULT([none needed])]) |
| 86 | + AS_VAR_IF([acx_cache_var], [unknown], [m4_default([$2], |
| 87 | + [AC_MSG_FAILURE([unable to detect _AC_LANG compiler flag needed to dnl |
| 88 | +enable OpenACC support])])], [$1]) |
| 89 | + m4_popdef([acx_cache_var])]) |
| 90 | + |
| 91 | +# _ACX_LANG_OPENACC() |
| 92 | +# ----------------------------------------------------------------------------- |
| 93 | +# Expands into the source code of a program in the current language that is |
| 94 | +# compiled successfully only when OpenACC support is enabled for the current |
| 95 | +# compiler. By default, expands to m4_fatal with the message saying that |
| 96 | +# _AC_LANG is not supported. |
| 97 | +# |
| 98 | +m4_define([_ACX_LANG_OPENACC], |
| 99 | + [m4_ifdef([$0(]_AC_LANG[)], |
| 100 | + [m4_indir([$0(]_AC_LANG[)], $@)], |
| 101 | + [m4_fatal([the OpenACC test program is not defined for ]dnl |
| 102 | +_AC_LANG[ language])])])]) |
| 103 | + |
| 104 | +# _ACX_LANG_OPENACC(C)() |
| 105 | +# ----------------------------------------------------------------------------- |
| 106 | +# Implementation of _ACX_LANG_OPENACC for C language. |
| 107 | +# |
| 108 | +m4_define([_ACX_LANG_OPENACC(C)], |
| 109 | + [AC_LANG_PROGRAM([[#include <openacc.h>]], |
| 110 | +[[#ifndef _OPENACC |
| 111 | + choke me |
| 112 | +#endif |
| 113 | +return (int) acc_get_device_type()]])]) |
| 114 | + |
| 115 | +# _ACX_LANG_OPENACC(C++) |
| 116 | +# ----------------------------------------------------------------------------- |
| 117 | +# Implementation of _ACX_LANG_OPENACC for C++ language. |
| 118 | +# |
| 119 | +m4_copy([_ACX_LANG_OPENACC(C)], [_ACX_LANG_OPENACC(C++)]) |
| 120 | + |
| 121 | +# _ACX_LANG_OPENACC(Fortran)() |
| 122 | +# ----------------------------------------------------------------------------- |
| 123 | +# Implementation of _ACX_LANG_OPENACC for Fortran language. |
| 124 | +# |
| 125 | +# The implementation implies that the Fortran module should be available when |
| 126 | +# OpenACC is enabled. |
| 127 | +# |
| 128 | +m4_define([_ACX_LANG_OPENACC(Fortran)], |
| 129 | + [AC_PROVIDE_IFELSE([AC_FC_PP_SRCEXT], [], |
| 130 | + [m4_warn([syntax], |
| 131 | + [ACX_LANG_OPENACC_FLAG requires calling the Fortran compiler with ]dnl |
| 132 | +[a preprocessor but no call to AC_FC_PP_SRCEXT is detected])])dnl |
| 133 | + AC_LANG_PROGRAM([], |
| 134 | +[[#ifndef _OPENACC |
| 135 | + choke me |
| 136 | +#endif |
| 137 | + use openacc, only : acc_get_device_type |
| 138 | + implicit none |
| 139 | + integer :: t |
| 140 | + t = acc_get_device_type()]])]) |
| 141 | + |
0 commit comments