clDNN
helper_functions.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #include <initializer_list>
17 
18 #include <../api/CPP/cldnn_defs.h>
19 #include <../api/CPP/memory.hpp>
20 
21 
22 
23 using namespace cldnn;
24 template<typename T>
25 void set_values(const cldnn::memory& mem, std::initializer_list<T> args)
26 {
27  auto ptr = mem.pointer<T>();
28  auto it = ptr.begin();
29  for (auto x : args)
30  {
31  *it++ = x;
32  }
33 }
34 
35 template<typename T>
36 void set_values(const cldnn::memory& mem, std::vector<T>&& args)
37 {
38  auto ptr = mem.pointer<T>();
39  auto it = ptr.begin();
40  for (auto x : args)
41  {
42  *it++ = x;
43  }
44 }
45 
46 template <typename T>
47 std::vector<T> get_simple_data(const memory& m)
48 {
49  std::vector<T> data(m.get_layout().get_linear_size());
50  for (size_t i = 0; i < data.size(); i++)
51  {
52  data[i] = static_cast<T>(i);
53  }
54 
55  return std::move(data);
56 }
size_t get_linear_size() const
Get aligned linear size calculated as multiplication of all elements.
Definition: layout.hpp:329
Provides input data to topology.
Definition: data.hpp:36
const layout & get_layout() const
Associated layout.
Definition: memory.hpp:114
Represents buffer with particular layout.
Definition: memory.hpp:42