2 // Copyright (c) 2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <../api/CPP/cldnn_defs.h>
17 #include <../api/CPP/engine.hpp>
18 #include <../api/CPP/memory.hpp>
19 #include <../api/CPP/tensor.hpp>
20 #include <../api/CPP/input_layout.hpp>
21 #include <../api/CPP/data.hpp>
23 /*! @page c1 Engine, layout, tensor, memory, data and input
24 * @section intro Introduction
25 * In this chapter we will explain how to create engine, define and allocate memory. What is and how to use: tensor, layout, input_layout and data.
27 * @include chapter_1.cpp
32 using namespace cldnn;
37 std::cout << std::endl << "-- Chapter 1 --" << std::endl;
38 // To create memory we have to create engine first. Engine is responsible for memory and kernel handling (creation, compilation, allocation).
39 // Currently OCL backend implementation only is available.
41 // Add profiling information
42 const bool profiling = true;
45 engine engine(profiling);
46 // We have to choose data type (f32 or f16):
47 data_types data_type = data_types::f32;
48 // Format (order of dimensions in memory), bfyx is the most optimal and common:
49 format::type format = format::byxf;
51 // Before memory allocation we have to create tensor that describes memory size. We can do it in serveral ways:
55 32, // width (spatial x)
56 32); // height (spatial y)
58 tensor tensor2(spatial(32, 32), batch(4), feature(1));
59 tensor tensor3(spatial(32, 32), batch(4)); // default value for non-initialized dimension is 1
61 std::cout << "Is tensor1 == tensor2 == tensor3?:" <<
62 (((tensor1 == tensor2) && (tensor2 == tensor3)) ? "yes" : "no") << std::endl;
63 std::cout << "print tensor:" << tensor1 << std::endl;
65 // Now we are ready to create layout:
66 layout layout1(data_type, format, tensor1);
67 // which can be used to allocate memory for given engine:
68 memory memory1 = memory::allocate(engine, layout1);
70 // Special type of layout is input layout. It is named layout. Name is a string with identifier of layout.
71 input_layout in_layout("input", layout1);
73 // You can also give name to memory to create a data.
74 data data("named_memory", memory1);