Skip to content

Commit

Permalink
ocl: allow get_ndevices/set_active_device before init (#594)
Browse files Browse the repository at this point in the history
* Introduced ACC_OPENCL_LAZYINIT.
* Prettify.
  • Loading branch information
hfp authored Mar 24, 2022
1 parent 6cad275 commit 4f13428
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/acc/opencl/acc_opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ int c_dbcsr_acc_get_ndevices(int* ndevices) {
static const int routine_name_len = (int)sizeof(LIBXSMM_FUNCNAME) - 1;
c_dbcsr_timeset((const char**)&routine_name_ptr, &routine_name_len, &routine_handle);
# endif
# if defined(__DBCSR_ACC)
# if defined(ACC_OPENCL_LAZYINIT)
/* DBCSR calls c_dbcsr_acc_get_ndevices before calling c_dbcsr_acc_init. */
result = c_dbcsr_acc_init();
if (EXIT_SUCCESS == result)
Expand Down
3 changes: 3 additions & 0 deletions src/acc/opencl/acc_opencl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
# define ACC_OPENCL_DELIMS ",;"
#endif

#if !defined(ACC_OPENCL_LAZYINIT) && (defined(__DBCSR_ACC) || 1)
# define ACC_OPENCL_LAZYINIT
#endif
#if !defined(ACC_OPENCL_DEBUG) && (defined(_DEBUG) || 0)
# define ACC_OPENCL_DEBUG
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/dbcsr_lib.F
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ SUBROUTINE dbcsr_finalize_lib()
CALL acc_finalize()
!$OMP END MASTER
!$OMP END PARALLEL
ENDIF
END IF
! Check the number of communicators
IF (check_comm_count .AND. mp_get_comm_count() .NE. 0) THEN
Expand Down
5 changes: 5 additions & 0 deletions tests/dbcsr_acc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ int main(int argc, char* argv[]) {
randnums[i] = rand();
}

/* allow get_ndevices/set_active_device before init */
ACC_CHECK(c_dbcsr_acc_get_ndevices(&ndevices));
if (0 <= device && device < ndevices) { /* not an error */
ACC_CHECK(c_dbcsr_acc_set_active_device(device));
}
ACC_CHECK(c_dbcsr_acc_init());
ACC_CHECK(c_dbcsr_acc_get_ndevices(&ndevices));
PRINTF("ndevices: %i\n", ndevices);
Expand Down

0 comments on commit 4f13428

Please sign in to comment.