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

Commit c7d9ee3

Browse files
authored
Bug fix in gpu implementation : global_vars.cpp was compiled with (#83)
OpenACC resulting in nrnran123_set_globalindex call for gpu device kernel. This device call was resulting in failure and hence abnormal program termination. * update mod2c submodule
1 parent 386e52a commit c7d9ee3

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

coreneuron/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,13 @@ endif()
235235
set(GENERATED_MECH_C_FILES ${MOD_FUNC_C} ${MOD_FUNC_PTRS_C} ${MOD2C_STDMECH_OUTPUTS} ${MOD2C_OPTMECH_OUTPUTS})
236236

237237
# artificial cells must be on cpu, defaul nrnran123.c is for cpu, nrn_setup.cpp uses nrnran123 for only memory calculation purpose which should use cpu version of nrnran123
238-
set(NOACC_MECH_C_FILES ${CMAKE_CURRENT_BINARY_DIR}/netstim.c ${CMAKE_CURRENT_BINARY_DIR}/netstim_inhpoisson.c ${CMAKE_CURRENT_BINARY_DIR}/pattern.c ${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.c ${CMAKE_CURRENT_SOURCE_DIR}/nrniv/nrn_setup.cpp)
238+
set(NOACC_MECH_C_FILES
239+
${CMAKE_CURRENT_BINARY_DIR}/netstim.c
240+
${CMAKE_CURRENT_BINARY_DIR}/netstim_inhpoisson.c
241+
${CMAKE_CURRENT_BINARY_DIR}/pattern.c
242+
${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.c
243+
${CMAKE_CURRENT_SOURCE_DIR}/nrniv/nrn_setup.cpp
244+
${CMAKE_CURRENT_SOURCE_DIR}/nrniv/global_vars.cpp)
239245

240246
if(ENABLE_OPENACC)
241247
set_source_files_properties(${GENERATED_MECH_C_FILES} PROPERTIES COMPILE_FLAGS "")

coreneuron/utils/randoms/nrnran123.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,15 @@ size_t nrnran123_instance_count() {
4242
return instance_count_;
4343
}
4444

45-
/* now this is declated in nrnran123.h so that its available for prototype declaration
46-
47-
struct nrnran123_State {
48-
philox4x32_ctr_t c;
49-
philox4x32_ctr_t r;
50-
unsigned char which_;
51-
};
52-
*/
53-
5445
size_t nrnran123_state_size() {
5546
return sizeof(nrnran123_State);
5647
}
5748

5849
void nrnran123_set_globalindex(uint32_t gix) {
5950
k.v[0] = gix;
51+
#if (defined(__CUDACC__) || defined(_OPENACC))
52+
nrnran123_set_gpu_globalindex(gix);
53+
#endif
6054
}
6155

6256
/* if one sets the global, one should reset all the stream sequences. */

coreneuron/utils/randoms/nrnran123.cu

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ __device__ size_t nrnran123_state_size() {
4343
return sizeof(nrnran123_State);
4444
}
4545

46-
__device__ void nrnran123_set_globalindex(uint32_t gix) {
46+
__global__ void nrnran123_set_globalindex(uint32_t gix) {
4747
k.v[0] = gix;
4848
}
4949

@@ -164,3 +164,9 @@ void nrnran123_deletestream(nrnran123_State* s) {
164164

165165
cudaFree(s);
166166
}
167+
168+
/* set global index for random123 stream on gpu */
169+
void nrnran123_set_gpu_globalindex(uint32_t gix) {
170+
nrnran123_set_globalindex<<<1,1>>>(gix);
171+
cudaDeviceSynchronize();
172+
}

coreneuron/utils/randoms/nrnran123.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extern DEVICE void nrnran123_mutconstruct(void);
9898

9999
/* global index. eg. run number */
100100
/* all generator instances share this global index */
101-
extern DEVICE void nrnran123_set_globalindex(uint32_t gix);
101+
extern GLOBAL void nrnran123_set_globalindex(uint32_t gix);
102102
extern DEVICE uint32_t nrnran123_get_globalindex();
103103

104104
extern DEVICE size_t nrnran123_instance_count(void);
@@ -155,7 +155,7 @@ extern DEVICE double nrnran123_gauss(nrnran123_State*); /* mean 0.0, std 1.0 */
155155
/* more fundamental (stateless) (though the global index is still used) */
156156
extern DEVICE nrnran123_array4x32 nrnran123_iran(uint32_t seq, uint32_t id1, uint32_t id2);
157157
extern DEVICE double nrnran123_uint2dbl(uint32_t);
158-
158+
extern void nrnran123_set_gpu_globalindex(uint32_t gix);
159159
#if defined(__cplusplus)
160160
}
161161
#endif

0 commit comments

Comments
 (0)