Add bureaucracy for openacc in autotools

This commit is contained in:
2023-01-05 00:06:37 +01:00
parent 249f1c0b51
commit 77e1aaabeb
5 changed files with 144 additions and 9 deletions

70
etc/m4/atrip_openacc.m4 Normal file
View File

@@ -0,0 +1,70 @@
# SYNOPSIS
#
# ATRIP_OPENACC([ACTION-SUCCESS], [ACTION-FAILURE])
#
# DESCRIPTION
#
# Check whether the given the -fopenacc flag works with the current language's compiler
# or gives an error.
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# LICENSE
#
# Copyright (c) 2023 Alejandro Gallo <aamsgallo@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
AC_DEFUN([ATRIP_OPENACC],
[
AC_MSG_CHECKING([that the compiler works with the -fopenacc])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_ATRIP_OPENACC_SOURCE])],
[
$1
AC_MSG_RESULT([yes])
],
[
$2
AC_MSG_ERROR([no])
])
])dnl DEFUN
m4_define([_ATRIP_OPENACC_SOURCE], [[
#include <stdio.h>
#include <stdlib.h>
#include <openacc.h>
#define SIZE 10
int main(int argc, char **argv) {
float matrix[SIZE * SIZE];
float result[SIZE * SIZE];
// Initialize the matrix with random values
for (int i = 0; i < SIZE * SIZE; i++) {
matrix[i] = rand() / (float)RAND_MAX;
}
#pragma acc data \
copy(matrix[0:SIZE * SIZE]) \
copyout(result[0:SIZE * SIZE])
{
// Calculate the matrix multiplication
#pragma acc parallel loop collapse(2)
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
float sum = 0.0f;
for (int k = 0; k < SIZE; k++) {
sum += matrix[i * SIZE + k] * matrix[j * SIZE + k];
}
result[i * SIZE + j] = sum;
}
}
}
return 0;
}
]])

View File

@@ -43,7 +43,7 @@
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 14
#serial 15
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).
@@ -189,7 +189,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201103L
// MSVC always sets __cplusplus to 199711L in older versions; newer versions
// only set it correctly if /Zc:__cplusplus is specified as well as a
// /std:c++NN switch:
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#elif __cplusplus < 201103L && !defined _MSC_VER
#error "This is not a C++11 compiler"
@@ -480,7 +484,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201402L
#elif __cplusplus < 201402L && !defined _MSC_VER
#error "This is not a C++14 compiler"
@@ -604,7 +608,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201703L
#elif __cplusplus < 201703L && !defined _MSC_VER
#error "This is not a C++17 compiler"
@@ -970,7 +974,7 @@ namespace cxx17
} // namespace cxx17
#endif // __cplusplus < 201703L
#endif // __cplusplus < 201703L && !defined _MSC_VER
]])
@@ -983,7 +987,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 202002L
#elif __cplusplus < 202002L && !defined _MSC_VER
#error "This is not a C++20 compiler"
@@ -1000,6 +1004,6 @@ namespace cxx20
} // namespace cxx20
#endif // __cplusplus < 202002L
#endif // __cplusplus < 202002L && !defined _MSC_VER
]])