OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
cuda_dispatch.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// C U D A D I S P A T C H H E L P E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#ifdef OPENNN_HAS_CUDA
12
13namespace opennn {
14// Cached at first call (C++11 magic statics make this thread-safe). Configuration
15// is set once at startup, so the value never changes after init.
16inline bool is_gpu_cached() {
17 static const bool v = is_gpu();
18 return v;
19}
20}
21
22 #define TRY_GPU_DISPATCH(view, ...) \
23 (::opennn::is_gpu_cached() \
24 ? ((view).dispatch(__VA_ARGS__), true) \
25 : false)
26
27 #define IF_GPU(...) \
28 do { \
29 if (::opennn::is_gpu_cached()) { \
30 __VA_ARGS__ \
31 } \
32 } while (0)
33
34#else
35
36 #define TRY_GPU_DISPATCH(view, ...) (false)
37
38 #define IF_GPU(...) ((void)0)
39
40#endif
41
42// OpenNN: Open Neural Networks Library.
43// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
44// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition adaptive_moment_estimation.h:14
bool is_gpu()
Returns true when the resolved configuration runs on a CUDA GPU.
Definition configuration.h:186