Skip to content

Commit

Permalink
atlas::acc Add runtime compiler_id detection
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Feb 20, 2025
1 parent 7ae9a1d commit 1a6e059
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/atlas/parallel/acc/acc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,21 @@ void* deviceptr(void* host_data) {
#endif
}

CompilerId compiler_id() {
#if ATLAS_HAVE_ACC
static CompilerId id = []() {
switch (atlas_acc_compiler_id()) {
case atlas_acc_compiler_id_cray: return CompilerId::cray;
case atlas_acc_compiler_id_nvidia: return CompilerId::nvidia;
default: return CompilerId::unknown;
}
}();
return id;
#else
return CompilerId::unknown;
#endif
}


}

7 changes: 7 additions & 0 deletions src/atlas/parallel/acc/acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@

namespace atlas::acc {

enum class CompilerId {
unknown,
nvidia,
cray,
};

int devices();
void map(void* host_data, void* device_data, std::size_t bytes);
void unmap(void* host_data);
bool is_present(void* host_data, std::size_t bytes);
void* deviceptr(void* host_data);
CompilerId compiler_id();

}

11 changes: 11 additions & 0 deletions src/atlas_acc_support/atlas_acc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ module atlas_acc

contains

function atlas_acc_compiler_id() bind(C,name="atlas_acc_compiler_id") result(compiler_id)
use, intrinsic :: iso_c_binding, only : c_int
integer(c_int) :: compiler_id
! compiler_id must match number in atlas_acc.h enum type
#ifdef _CRAYFTN
compiler_id = 2 ! cray
#else
compiler_id = 0 ! unknown
#endif
end function

function atlas_acc_get_num_devices() bind(C,name="atlas_acc_get_num_devices") result(num_devices)
use, intrinsic :: iso_c_binding, only : c_int
integer(c_int) :: num_devices
Expand Down
9 changes: 9 additions & 0 deletions src/atlas_acc_support/atlas_acc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,13 @@ const char* atlas_acc_info_str() {
int atlas_acc_get_num_devices() {
return acc_get_num_devices(acc_get_device_type());
}

atlas_acc_compiler_id_t atlas_acc_compiler_id() {
#if defined(__NVCOMPILER)
return atlas_acc_compiler_id_nvidia;
#else
return atlas_acc_compiler_id_unknown;
#endif
}

}
8 changes: 8 additions & 0 deletions src/atlas_acc_support/atlas_acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ void* atlas_acc_deviceptr(void* cpu_ptr);
atlas_acc_device_t atlas_acc_get_device_type();
int atlas_acc_get_num_devices();

typedef enum {
atlas_acc_compiler_id_unknown = 0,
atlas_acc_compiler_id_nvidia = 1,
atlas_acc_compiler_id_cray = 2
} atlas_acc_compiler_id_t;

atlas_acc_compiler_id_t atlas_acc_compiler_id();

#ifdef __cplusplus
}
#endif

0 comments on commit 1a6e059

Please sign in to comment.