2 // Copyright (c) 2018 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.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 #include "../C/mutable_data.h"
20 #include "primitive.hpp"
25 /// @addtogroup cpp_api C++ API
27 /// @addtogroup cpp_topology Network Topology
29 /// @addtogroup cpp_primitives Primitives
32 /// @brief Provides mutable data.
33 /// @details This primitive allows to pass data which can be written to during training.
34 /// For example, weights and biases for scoring networks.
35 /// This primitive can be also set as other primitive's output. In this case the underlying buffer will be the same in mutable_data and preceding primitive.
36 struct mutable_data : public primitive_base<mutable_data, CLDNN_PRIMITIVE_DESC(mutable_data)> {
37 CLDNN_DECLARE_PRIMITIVE(mutable_data)
39 /// @brief Enum type to specify function for data filling.
40 enum filler_type { no_fill, zero, one, xavier };
42 /// @brief Constructs mutable_data primitive.
43 /// @param id This primitive id.
44 /// @param mem @ref memory object which contains data.
45 /// @param filler_type @ref data filling function, default is zero
46 /// @note If memory is attached by memory::attach(), the attached buffer should be valid till network build.
47 mutable_data(const primitive_id& id, const memory& mem, filler_type fill_type = filler_type::no_fill)
48 : primitive_base(id, {}, padding()), mem(mem), fill_type(fill_type) {}
50 /// @brief Constructs mutable_data primitive with inputs.
51 /// @param id This primitive id.
52 /// @param input Vector of input primitives ids.
53 /// @param mem @ref memory object which contains data.
54 /// @note If memory is attached by memory::attach(), the attached buffer should be valid till network build.
55 /// @param filler_type @ref data filling function, default is zero
56 mutable_data(const primitive_id& id,
57 const std::vector<primitive_id>& input,
59 filler_type fill_type = filler_type::no_fill)
60 : primitive_base(id, {input}, padding()), mem(mem), fill_type(fill_type) {}
62 /// @brief Constructs a copy from C API @CLDNN_PRIMITIVE_DESC{mutable_data}
63 explicit mutable_data(const dto* dto)
64 : primitive_base(dto), mem(dto->mem), fill_type(static_cast<filler_type>(dto->fill_type)) {
68 /// @brief @ref memory object which contains data.
69 /// @note If memory is attached by memory::attach(), the attached buffer should be valid till network build.
72 /// @brief Specifies function which will be used to fill weights.
73 filler_type fill_type;
76 void update_dto(dto& dto) const override {
78 dto.fill_type = static_cast<cldnn_filler_type>(fill_type);