CellularAutomata
Loading...
Searching...
No Matches
epoch.inl
1#include "epoch.hpp"
2#include "cpu.hpp"
3#include "exceptions.hpp"
4
5#ifdef __CUDACC__
6#include "../cuda/cuda.cuh"
7#endif
8
9float test(float x) { return x; }
10
11namespace CellularAutomata
12{
13 template <typename T, typename Activation>
14 void Epoch(State<T>* state, Kernel<T>* kernel, Activation activation, bool recursive)
15 {
16 if (state->device != kernel->device)
17 throw exception::DevicesUnequal("Devices of state and kernel are unequal");
18
19 if (state->device == Device::CUDA)
20 {
21 #ifdef __CUDACC__
22 CellularAutomata::cuda::epoch(
23 state->curr, kernel->kernel, state->next, activation,
24 state->height, state->width, kernel->size, recursive
25 );
26 #endif
27 }
28 else
29 {
30 CellularAutomata::cpu::epoch(
31 state->curr, kernel->kernel, state->next, activation,
32 state->height, state->width, kernel->size, recursive
33 );
34 }
35
36 state->swap();
37 }
38 }
2D convolution kernel
Definition common.hpp:130
const Device device
Computational device.
Definition common.hpp:143
T * kernel
2D Matrix
Definition common.hpp:135
const unsigned int size
Side length of matrix.
Definition common.hpp:139
2D buffered matrices
Definition common.hpp:56
const unsigned int width
Width of 2D Matrix.
Definition common.hpp:76
T * curr
Current 2D Matrix buffer.
Definition common.hpp:61
void swap()
Swaps the current- and next state buffer.
Definition common.inl:139
const unsigned int height
Height of 2D Matrix.
Definition common.hpp:71
const Device device
Computational device.
Definition common.hpp:81
T * next
Next 2D Matrix buffer.
Definition common.hpp:66
Objects are on different devices.
Definition exceptions.hpp:36
Main namespace.
Definition common.hpp:33
void Epoch(State< T > *state, Kernel< T > *kernel, Activation activation, bool recursive)
Runs a single epoch on a given state using a kernel.
Definition epoch.inl:14
@ CUDA
Allocation & computation on NVIDIA GPU via CUDA.
Definition common.hpp:47