Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit d4ed738

Browse files
authored
CMake build options refactoring for Makefile and removing PG_ACC_BUGS (#455)
* CMake build options refactoring for Makefile * move all makefile related options into single file MakefileBuildOptions.cmake * remove all option processing from extra/CMakeLists.txt * fix with neuron linking : type CN_PGI_ACC_FLAGS -> PGI_ACC_FLAGS * Use PGI archive module because of issue with latest NVHPC modules * fix ISPC build issue and nrnivmodl-core failure on OSX * Avoid P2 UC2 ndoes as GPFS is not mounted (HELP-13390) * Use spack branch only if specified * Remove use of PG_ACC_BUGS * PG_ACC_BUGS was added when we saw bugs with PGI compiler version 16.3 * Except the case of union, no more real buggy scenario exists * So remove all usages of PG_ACC_BUGS * Remove some hardcoded ion array size by const variable * update mod2c to master * mods files and cpp translated files are in same x86_64/corenrn/mod2c directory
1 parent 2cd992e commit d4ed738

File tree

17 files changed

+184
-161
lines changed

17 files changed

+184
-161
lines changed

CMake/MakefileBuildOptions.cmake

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# =============================================================================
2+
# Common CXX and ISPC flags
3+
# =============================================================================
4+
5+
# ISPC should compile with --pic by default
6+
set(CMAKE_ISPC_FLAGS "${CMAKE_ISPC_FLAGS} --pic")
7+
8+
# =============================================================================
9+
# NMODL CLI options : common and backend specific
10+
# =============================================================================
11+
# if user pass arguments then use those as common arguments
12+
if ("${CORENRN_NMODL_FLAGS}" STREQUAL "")
13+
set(NMODL_COMMON_ARGS "passes --inline")
14+
else()
15+
set(NMODL_COMMON_ARGS ${CORENRN_NMODL_FLAGS})
16+
endif()
17+
18+
set(NMODL_CPU_BACKEND_ARGS "host --c")
19+
set(NMODL_ISPC_BACKEND_ARGS "host --ispc")
20+
set(NMODL_ACC_BACKEND_ARGS "host --c acc --oacc")
21+
22+
# =============================================================================
23+
# Extract Compile definitions : common to all backend
24+
# =============================================================================
25+
get_directory_property(COMPILE_DEFS COMPILE_DEFINITIONS)
26+
if(COMPILE_DEFS)
27+
set(CORENRN_COMMON_COMPILE_DEFS "")
28+
foreach(flag ${COMPILE_DEFS})
29+
set(CORENRN_COMMON_COMPILE_DEFS "${CORENRN_COMMON_COMPILE_DEFS} -D${flag}")
30+
endforeach()
31+
endif()
32+
33+
# =============================================================================
34+
# link flags : common to all backend
35+
# =============================================================================
36+
# ~~~
37+
# find_cuda uses FindThreads that adds below imported target we
38+
# shouldn't add imported target to link line
39+
# ~~~
40+
list(REMOVE_ITEM CORENRN_LINK_LIBS "Threads::Threads")
41+
42+
# replicate CMake magic to transform system libs to -l<libname>
43+
foreach(link_lib ${CORENRN_LINK_LIBS})
44+
if(${link_lib} MATCHES "\-l.*")
45+
string(APPEND CORENRN_COMMON_LDFLAGS " ${link_lib}")
46+
continue()
47+
endif()
48+
get_filename_component(path ${link_lib} DIRECTORY)
49+
if(NOT path)
50+
string(APPEND CORENRN_COMMON_LDFLAGS " -l${link_lib}")
51+
elseif("${path}" MATCHES "^(/lib|/lib64|/usr/lib|/usr/lib64)$")
52+
get_filename_component(libname ${link_lib} NAME_WE)
53+
string(REGEX REPLACE "^lib" "" libname ${libname})
54+
string(APPEND CORENRN_COMMON_LDFLAGS " -l${libname}")
55+
else()
56+
string(APPEND CORENRN_COMMON_LDFLAGS " ${link_lib}")
57+
endif()
58+
endforeach()
59+
60+
# =============================================================================
61+
# compile flags : common to all backend
62+
# =============================================================================
63+
# PGI compiler adds --c++14;-A option for C++14, remove ";"
64+
string(REPLACE ";" " " CXX14_STD_FLAGS "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}")
65+
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
66+
set(CORENRN_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE}} ${CXX14_STD_FLAGS}")
67+
68+
# =============================================================================
69+
# nmodl/mod2c related options : TODO
70+
# =============================================================================
71+
# name of nmodl/mod2c binary
72+
get_filename_component(nmodl_name ${CORENRN_MOD2CPP_BINARY} NAME)
73+
set(nmodl_binary_name ${nmodl_name})

CMake/OpenAccHelper.cmake

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
# See top-level LICENSE file for details.
55
# =============================================================================
66

7+
# =============================================================================
8+
# Prepare compiler flags for GPU target
9+
# =============================================================================
710
if(CORENRN_ENABLE_GPU)
11+
812
# cuda unified memory support
913
if(CORENRN_ENABLE_CUDA_UNIFIED_MEMORY)
10-
add_definitions(-DUNIFIED_MEMORY)
14+
set(UNIFIED_MEMORY_DEF -DUNIFIED_MEMORY)
1115
endif()
1216

1317
# if user don't specify host compiler, use gcc from $PATH
@@ -20,44 +24,50 @@ if(CORENRN_ENABLE_GPU)
2024

2125
# various flags for PGI compiler with GPU build
2226
if(${CMAKE_C_COMPILER_ID} STREQUAL "PGI")
27+
2328
# workaround for old PGI version
24-
add_definitions(-DPG_ACC_BUGS)
25-
set(ACC_FLAGS "-acc")
29+
set(PGI_ACC_FLAGS "-acc")
2630
# disable very verbose diagnosis messages and obvious warnings for mod2c
2731
set(PGI_DIAG_FLAGS "--diag_suppress 161,177,550")
28-
# some of the mod files can have too many functions, increase inline level
32+
# inlining of large functions for OpenACC
2933
set(PGI_INLINE_FLAGS "-Minline=size:200,levels:10")
30-
# C/C++ compiler flags
31-
set(CMAKE_C_FLAGS "${ACC_FLAGS} ${CMAKE_C_FLAGS}")
32-
set(CMAKE_CXX_FLAGS "${ACC_FLAGS} ${CMAKE_CXX_FLAGS} ${PGI_DIAG_FLAGS}")
34+
3335
# avoid PGI adding standard compliant "-A" flags
3436
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION --c++11)
3537
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14)
38+
3639
else()
3740
message(FATAL_ERROR "GPU support is available via OpenACC using PGI/NVIDIA compilers."
3841
" Use NVIDIA HPC SDK with -DCMAKE_C_COMPILER=nvc -DCMAKE_CXX_COMPILER=nvc++")
3942
endif()
4043

41-
# set property for neuron to link with coreneuron libraries
42-
set_property(
43-
GLOBAL
44-
PROPERTY
45-
CORENEURON_LIB_LINK_FLAGS
46-
"-acc -rdynamic -lrt -Wl,--whole-archive -L${CMAKE_HOST_SYSTEM_PROCESSOR} -lcorenrnmech -L${CMAKE_INSTALL_PREFIX}/lib -lcoreneuron -lcudacoreneuron -Wl,--no-whole-archive ${CUDA_cudart_static_LIBRARY}"
47-
)
48-
4944
# find_cuda produce verbose messages : use new behavior to use _ROOT variables
5045
if(POLICY CMP0074)
5146
cmake_policy(SET CMP0074 NEW)
5247
endif()
5348
find_package(CUDA 9.0 REQUIRED)
5449
set(CUDA_SEPARABLE_COMPILATION ON)
5550
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
56-
add_definitions(-DCUDA_PROFILING)
57-
else(CORENRN_ENABLE_GPU)
58-
# OpenACC pragmas are not guarded, disable all unknown pragm warnings
59-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
60-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
51+
set(CUDA_PROFILING_DEF -DCUDA_PROFILING)
52+
53+
set(CORENRN_ACC_GPU_DEFS "${UNIFIED_MEMORY_DEF} ${CUDA_PROFILING_DEF}")
54+
set(CORENRN_ACC_GPU_FLAGS "${PGI_ACC_FLAGS} ${PGI_DIAG_FLAGS} ${PGI_INLINE_FLAGS}")
55+
56+
add_definitions(${CORENRN_ACC_GPU_DEFS})
57+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORENRN_ACC_GPU_FLAGS}")
58+
endif()
59+
60+
# =============================================================================
61+
# Set global property that will be used by NEURON to link with CoreNEURON
62+
# =============================================================================
63+
if(CORENRN_ENABLE_GPU)
64+
set_property(
65+
GLOBAL
66+
PROPERTY
67+
CORENEURON_LIB_LINK_FLAGS
68+
"${PGI_ACC_FLAGS} -rdynamic -lrt -Wl,--whole-archive -L${CMAKE_HOST_SYSTEM_PROCESSOR} -lcorenrnmech -L${CMAKE_INSTALL_PREFIX}/lib -lcoreneuron -lcudacoreneuron -Wl,--no-whole-archive ${CUDA_cudart_static_LIBRARY}"
69+
)
70+
else()
6171
set_property(GLOBAL PROPERTY CORENEURON_LIB_LINK_FLAGS
6272
"-L${CMAKE_HOST_SYSTEM_PROCESSOR} -lcorenrnmech")
6373
endif(CORENRN_ENABLE_GPU)

CMakeLists.txt

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ set(LIKWID_DIR
9595
""
9696
CACHE PATH "Path to likwid performance analysis suite")
9797

98-
set(CORENRN_FRONTEND_C_COMPILER
99-
gcc
100-
CACHE FILEPATH "C compiler for building mod2c [frontend]")
101-
set(CORENRN_FRONTEND_CXX_COMPILER
102-
g++
103-
CACHE FILEPATH "C++ compiler for building mod2c [frontend]")
104-
10598
if(CORENEURON_AS_SUBPROJECT)
10699
set(CORENRN_ENABLE_UNIT_TESTS OFF)
107100
endif()
@@ -126,11 +119,6 @@ include(OpenAccHelper)
126119
find_package(PythonInterp REQUIRED)
127120
find_package(Perl REQUIRED)
128121

129-
# =============================================================================
130-
# ISPC should compile with --pic by default
131-
# =============================================================================
132-
set(CMAKE_ISPC_FLAGS "--pic ${CMAKE_ISPC_FLAGS}")
133-
134122
# =============================================================================
135123
# Common build options
136124
# =============================================================================
@@ -147,7 +135,6 @@ endif()
147135
# Build option specific compiler flags
148136
# =============================================================================
149137
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "PGI")
150-
add_definitions(-DSWAP_ENDIAN_DISABLE_ASM)
151138
# PGI with llvm code generation doesn't have necessary assembly intrinsic headers
152139
add_definitions(-DEIGEN_DONT_VECTORIZE=1)
153140
endif()
@@ -168,7 +155,6 @@ endif()
168155

169156
if(CORENRN_ENABLE_ISPC)
170157
enable_language(ISPC)
171-
add_definitions("-DISPC_INTEROP=1")
172158
set(CORENRN_ENABLE_NMODL ON)
173159
endif()
174160

@@ -283,7 +269,6 @@ if(CORENRN_ENABLE_NMODL)
283269
if(CORENRN_ENABLE_GPU)
284270
string(APPEND CORENRN_NMODL_FLAGS " acc --oacc")
285271
endif()
286-
separate_arguments(NMODL_EXTRA_FLAGS_LIST UNIX_COMMAND "${CORENRN_NMODL_FLAGS}")
287272
else()
288273
include(AddMod2cSubmodule)
289274
set(CORENRN_MOD2CPP_BINARY ${CMAKE_BINARY_DIR}/bin/mod2c_core${CMAKE_EXECUTABLE_SUFFIX})
@@ -309,10 +294,17 @@ if(CORENRN_ENABLE_LIKWID_PROFILING)
309294
add_definitions("-DLIKWID_PERFMON")
310295
endif()
311296

297+
# =============================================================================
298+
# Common CXX flags : ignore unknown pragma warnings
299+
# =============================================================================
300+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
301+
312302
# =============================================================================
313303
# Add main directories
314304
# =============================================================================
315305
add_subdirectory(coreneuron)
306+
307+
include(MakefileBuildOptions)
316308
add_subdirectory(extra)
317309

318310
if(CORENRN_ENABLE_UNIT_TESTS)
@@ -325,14 +317,6 @@ endif()
325317
install(FILES CMake/coreneuron-config.cmake DESTINATION share/cmake)
326318
install(EXPORT coreneuron DESTINATION share/cmake)
327319

328-
# just for printing the compiler flags in the build status
329-
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UPPER)
330-
if(BUILD_TYPE_UPPER MATCHES "CUSTOM")
331-
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS}")
332-
else()
333-
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS_${BUILD_TYPE_UPPER}}")
334-
endif()
335-
336320
if(NOT CORENEURON_AS_SUBPROJECT)
337321
# =============================================================================
338322
# Setup Doxygen documentation
@@ -402,7 +386,7 @@ if(cmake_generator_tolower MATCHES "makefile")
402386

403387
message(STATUS "C COMPILER | ${CMAKE_C_COMPILER}")
404388
message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
405-
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
389+
message(STATUS "COMPILE FLAGS | ${CORENRN_CXX_FLAGS}")
406390
message(STATUS "Build Type | ${COMPILE_LIBRARY_TYPE}")
407391
message(STATUS "MPI | ${CORENRN_ENABLE_MPI}")
408392
if(CORENRN_ENABLE_MPI)

coreneuron/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ set(NMODL_UNITS_FILE "${CMAKE_BINARY_DIR}/share/mod2c/nrnunits.lib")
5656
file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/mechanism/mech/modfile
5757
DESTINATION ${CMAKE_BINARY_DIR}/share)
5858

59-
# eion.cpp depends on CORENRN_USE_LEGACY_UNITS
60-
set(LegacyFR_FILES mechanism/eion.cpp apps/main1.cpp io/global_vars.cpp)
61-
set_source_files_properties(${LegacyFR_FILES} PROPERTIES COMPILE_FLAGS
62-
"-DCORENRN_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS}")
63-
6459
# =============================================================================
6560
# coreneuron GPU library
6661
# =============================================================================
@@ -85,12 +80,6 @@ if(CORENRN_ENABLE_GPU)
8580
set_source_files_properties(${OPENACC_EXCLUDED_FILES} PROPERTIES COMPILE_FLAGS
8681
"-DDISABLE_OPENACC")
8782

88-
# TODO : only older PGI versions?
89-
if(${CMAKE_C_COMPILER_ID} STREQUAL "PGI")
90-
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/scopmath_core/sparse_thread.c
91-
PROPERTIES COMPILE_FLAGS "-ta=tesla:nollvm")
92-
endif()
93-
9483
# compile cuda files for multiple architecture
9584
cuda_add_library(
9685
"cudacoreneuron" ${CORENEURON_CUDA_FILES}

coreneuron/apps/main1.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ bool corenrn_units_use_legacy() {
7777

7878
void (*nrn2core_part2_clean_)();
7979

80-
#ifdef ISPC_INTEROP
8180
// cf. utils/ispc_globals.c
8281
extern double ispc_celsius;
83-
#endif
8482

8583
/**
8684
* If "export OMP_NUM_THREADS=n" is not set then omp by default sets
@@ -213,9 +211,9 @@ void nrn_init_and_load_data(int argc,
213211

214212
corenrn_param.celsius = celsius;
215213

216-
#ifdef ISPC_INTEROP
214+
// for ispc backend
217215
ispc_celsius = celsius;
218-
#endif
216+
219217
// create net_cvode instance
220218
mk_netcvode();
221219

coreneuron/gpu/nrn_acc_manager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,7 @@ void nrn_ion_global_map_copyto_device() {
969969
(double**)acc_copyin(nrn_ion_global_map, sizeof(double*) * nrn_ion_global_map_size);
970970
for (int j = 0; j < nrn_ion_global_map_size; j++) {
971971
if (nrn_ion_global_map[j]) {
972-
/* @todo: fix this constant size 3 :( */
973-
double* d_mechmap = (double*)acc_copyin(nrn_ion_global_map[j], 3 * sizeof(double));
972+
double* d_mechmap = (double*)acc_copyin(nrn_ion_global_map[j], ion_global_map_member_size * sizeof(double));
974973
acc_memcpy_to_device(&(d_data[j]), &d_mechmap, sizeof(double*));
975974
}
976975
}

coreneuron/mechanism/eion.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,12 @@ THE POSSIBILITY OF SUCH DAMAGE.
4848
#endif
4949

5050
#if defined(_OPENACC)
51-
#if defined(PG_ACC_BUGS)
5251
#define _PRAGMA_FOR_INIT_ACC_LOOP_ \
5352
_Pragma( \
54-
"acc parallel loop present(pd[0:_cntml_padded*5], ppd[0:1], nrn_ion_global_map[0:nrn_ion_global_map_size][0:3]) if(nt->compute_gpu)")
53+
"acc parallel loop present(pd[0:_cntml_padded*5], ppd[0:1], nrn_ion_global_map[0:nrn_ion_global_map_size][0:ion_global_map_member_size]) if(nt->compute_gpu)")
5554
#define _PRAGMA_FOR_CUR_ACC_LOOP_ \
5655
_Pragma( \
57-
"acc parallel loop present(pd[0:_cntml_padded*5], nrn_ion_global_map[0:nrn_ion_global_map_size][0:3]) if(nt->compute_gpu) async(stream_id)")
58-
#else
59-
#define _PRAGMA_FOR_INIT_ACC_LOOP_ \
60-
_Pragma( \
61-
"acc parallel loop present(pd[0:_cntml_padded*5], ppd[0:1], nrn_ion_global_map[0:nrn_ion_global_map_size]) if(nt->compute_gpu)")
62-
#define _PRAGMA_FOR_CUR_ACC_LOOP_ \
63-
_Pragma( \
64-
"acc parallel loop present(pd[0:_cntml_padded*5], nrn_ion_global_map[0:nrn_ion_global_map_size]) if(nt->compute_gpu) async(stream_id)")
65-
#endif
56+
"acc parallel loop present(pd[0:_cntml_padded*5], nrn_ion_global_map[0:nrn_ion_global_map_size][0:ion_global_map_member_size]) if(nt->compute_gpu) async(stream_id)")
6657
#define _PRAGMA_FOR_SEC_ORDER_CUR_ACC_LOOP_ \
6758
_Pragma( \
6859
"acc parallel loop present(pd[0:_cntml_padded*5], ni[0:_cntml_actual], _vec_rhs[0:_nt->end]) if(_nt->compute_gpu) async(stream_id)")
@@ -74,6 +65,10 @@ THE POSSIBILITY OF SUCH DAMAGE.
7465

7566
namespace coreneuron {
7667

68+
// for each ion it refers to internal concentration, external concentration, and charge,
69+
const int ion_global_map_member_size = 3;
70+
71+
7772
#define nparm 5
7873
static const char* mechanism[] = {/*just a template*/
7974
"0", "na_ion", "ena", "nao", "nai", 0, "ina", "dina_dv_", 0, 0};
@@ -130,7 +125,7 @@ void ion_reg(const char* name, double valence) {
130125
}
131126
nrn_ion_global_map_size = mechtype + 1;
132127
}
133-
nrn_ion_global_map[mechtype] = (double*)emalloc(3 * sizeof(double));
128+
nrn_ion_global_map[mechtype] = (double*)emalloc(ion_global_map_member_size * sizeof(double));
134129

135130
register_mech((const char**)mechanism, nrn_alloc_ion, nrn_cur_ion, (mod_f_t)0, (mod_f_t)0,
136131
(mod_f_t)nrn_init_ion, -1, 1);

coreneuron/mechanism/mechanism.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ THE POSSIBILITY OF SUCH DAMAGE.
3333
#include "coreneuron/utils/memory.h"
3434

3535
namespace coreneuron {
36-
#if PG_ACC_BUGS
36+
// OpenACC with PGI compiler has issue when union is used and hence use struct
37+
// \todo check if newer PGI versions has resolved this issue
38+
#if defined(_OPENACC)
3739
struct ThreadDatum {
3840
int i;
3941
double* pval;

coreneuron/mechanism/membfunc.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct BAMech {
8686

8787
extern int nrn_ion_global_map_size;
8888
extern double** nrn_ion_global_map;
89+
extern const int ion_global_map_member_size;
8990

9091
#define NRNPOINTER \
9192
4 /* added on to list of mechanism variables.These are \
@@ -94,6 +95,7 @@ pointers which connect variables from other mechanisms via the _ppval array. \
9495

9596
#define _AMBIGUOUS 5
9697

98+
9799
extern int nrn_get_mechtype(const char*);
98100
extern const char* nrn_get_mechname(int); // slow. use memb_func[i].sym if posible
99101
extern int register_mech(const char** m,

coreneuron/mechanism/register_mech.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@ THE POSSIBILITY OF SUCH DAMAGE.
4040
namespace coreneuron {
4141
int secondorder = 0;
4242
double t, dt, celsius;
43-
#if defined(PG_ACC_BUGS)
44-
// clang-format off
45-
#pragma acc declare copyin(secondorder)
46-
#pragma acc declare copyin(celsius)
47-
// clang-format on
48-
#endif
43+
// declare copyin required for correct initialization
44+
#pragma acc declare copyin(secondorder)
45+
#pragma acc declare copyin(celsius)
4946
int rev_dt;
5047

5148
using Pfrv = void (*)();

0 commit comments

Comments
 (0)