| 1 |
/* |
| 2 |
* (C) Copyright 2024- ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "acc.h" |
| 12 |
|
| 13 |
#include "atlas/library/defines.h" |
| 14 |
|
| 15 |
#if ATLAS_HAVE_ACC |
| 16 |
#include "pluto/pluto.h" |
| 17 |
#include "atlas_acc_support/atlas_acc.h" |
| 18 |
#endif |
| 19 |
|
| 20 |
namespace atlas::acc { |
| 21 |
|
| 22 |
int devices() { |
| 23 |
#if ATLAS_HAVE_ACC |
| 24 |
static int num_devices = [](){ |
| 25 |
if (pluto::devices() == 0) { |
| 26 |
return 0; |
| 27 |
} |
| 28 |
auto devicetype = atlas_acc_get_device_type(); |
| 29 |
int _num_devices = atlas_acc_get_num_devices(); |
| 30 |
if (_num_devices == 1 && devicetype == atlas_acc_device_host) { |
| 31 |
--_num_devices; |
| 32 |
} |
| 33 |
return _num_devices; |
| 34 |
}(); |
| 35 |
return num_devices; |
| 36 |
#else |
| 37 |
return 0; |
| 38 |
#endif |
| 39 |
} |
| 40 |
|
| 41 |
void map(void* host_data, void* device_data, std::size_t bytes) { |
| 42 |
#if ATLAS_HAVE_ACC |
| 43 |
atlas_acc_map_data(host_data, device_data, bytes); |
| 44 |
#endif |
| 45 |
} |
| 46 |
void unmap(void* host_data) { |
| 47 |
#if ATLAS_HAVE_ACC |
| 48 |
atlas_acc_unmap_data(host_data); |
| 49 |
#endif |
| 50 |
} |
| 51 |
|
| 52 |
bool is_present(void* host_data, std::size_t bytes) { |
| 53 |
#if ATLAS_HAVE_ACC |
| 54 |
return atlas_acc_is_present(host_data, bytes); |
| 55 |
#else |
| 56 |
return false; |
| 57 |
#endif |
| 58 |
} |
| 59 |
|
| 60 |
void* deviceptr(void* host_data) { |
| 61 |
#if ATLAS_HAVE_ACC |
| 62 |
return atlas_acc_deviceptr(host_data); |
| 63 |
#else |
| 64 |
return nullptr; |
| 65 |
#endif |
| 66 |
} |
| 67 |
|
| 68 |
CompilerId compiler_id() { |
| 69 |
#if ATLAS_HAVE_ACC |
| 70 |
static CompilerId id = []() { |
| 71 |
switch (atlas_acc_compiler_id()) { |
| 72 |
case atlas_acc_compiler_id_cray: return CompilerId::cray; |
| 73 |
case atlas_acc_compiler_id_nvidia: return CompilerId::nvidia; |
| 74 |
default: return CompilerId::unknown; |
| 75 |
} |
| 76 |
}(); |
| 77 |
return id; |
| 78 |
#else |
| 79 |
return CompilerId::unknown; |
| 80 |
#endif |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
} |
| 85 |
|