fml  0.1-0
Fused Matrix Library
cpuhelpers.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_CPU_CPUHELPERS_H
6 #define FML_CPU_CPUHELPERS_H
7 #pragma once
8 
9 
10 #include <stdexcept>
11 
12 #include "../_internals/arraytools/src/arraytools.hpp"
13 
14 #include "cpumat.hh"
15 #include "cpuvec.hh"
16 
17 
19 namespace cpuhelpers
20 {
37  template <typename REAL_IN, typename REAL_OUT>
38  void cpu2cpu(const cpuvec<REAL_IN> &cpu_in, cpuvec<REAL_OUT> &cpu_out)
39  {
40  cpu_out.resize(cpu_in.size());
41 
42  arraytools::copy(cpu_in.size(), cpu_in.data_ptr(), cpu_out.data_ptr());
43  }
44 
46  template <typename REAL>
48  {
49  cpuvec<REAL> cpu_out;
50  cpu2cpu(cpu_in, cpu_out);
51 
52  return cpu_out;
53  }
54 
56  template <typename REAL_IN, typename REAL_OUT>
57  void cpu2cpu(const cpumat<REAL_IN> &cpu_in, cpumat<REAL_OUT> &cpu_out)
58  {
59  cpu_out.resize(cpu_in.nrows(), cpu_in.ncols());
60 
61  size_t len = (size_t) cpu_in.nrows() * cpu_in.ncols();
62  arraytools::copy(len, cpu_in.data_ptr(), cpu_out.data_ptr());
63  }
64 
66  template <typename REAL>
68  {
69  cpumat<REAL> cpu_out;
70  cpu2cpu(cpu_in, cpu_out);
71 
72  return cpu_out;
73  }
74 }
75 
76 
77 #endif
unimat::data_ptr
REAL * data_ptr()
Pointer to the internal array.
Definition: unimat.hh:35
univec::data_ptr
T * data_ptr()
Pointer to the internal array.
Definition: univec.hh:26
cpuhelpers::cpu2cpu
void cpu2cpu(const cpuvec< REAL_IN > &cpu_in, cpuvec< REAL_OUT > &cpu_out)
Copy data from a CPU object to another.
Definition: cpuhelpers.hh:38
cpuvec
Vector class for data held on a single CPU.
Definition: cpuvec.hh:29
unimat::nrows
len_t nrows() const
Number of rows.
Definition: unimat.hh:31
univec::size
len_t size() const
Number of elements in the vector.
Definition: univec.hh:24
unimat::ncols
len_t ncols() const
Number of columns.
Definition: unimat.hh:33
cpuvec::resize
void resize(len_t size)
Resize the internal object storage.
Definition: cpuvec.hh:179
cpumat
Matrix class for data held on a single CPU.
Definition: cpumat.hh:34
cpuhelpers
CPU class helpers.
Definition: cpuhelpers.hh:19
cpumat::resize
void resize(len_t nrows, len_t ncols)
Resize the internal object storage.
Definition: cpumat.hh:204