2 #include <dlprim/context.hpp> 3 #include <dlprim/shape.hpp> 29 return shape_ == other.shape_ && dtype_ == other.dtype_ && is_trainable_ == other.is_trainable_;
34 return !(*
this == other);
61 is_trainable_ =
false;
77 return shape_.
total_size() * size_of_data_type(dtype_);
136 return specs_->shape();
144 return specs_->is_trainable();
158 return specs_->dtype();
165 void reshape(
Shape const &ns);
195 size_t size =
memory_size() / size_of_data_type(d);
196 return sub_tensor(0,
Shape(size),d);
209 size_t bytes = offset * size_of_data_type(d);
210 int this_sizeof = size_of_data_type(dtype());
211 DLPRIM_CHECK(bytes % this_sizeof == 0);
212 return sub_tensor(bytes / this_sizeof,s,d,trainable);
222 Tensor sub_tensor(
size_t offset,
Shape const &s,
DataType d=float_data,
bool trainable =
true)
const;
249 return static_cast<T*
>(host_data());
274 k.setArg(pos++,device_buffer());
275 k.setArg(pos++,device_offset());
280 std::shared_ptr<TensorSpecs> specs_;
281 std::shared_ptr<HostMem> host_;
286 size_t full_capacity_;
293 bool requires_gradient=
true;
294 float accumulate_gradient=0.0;
299 inline std::ostream &operator<<(std::ostream &out,
TensorSpecs const &ts)
301 out <<
'[' << ts.
shape() <<
",dtype=" << data_type_to_string(ts.dtype()) <<
']';
305 inline std::ostream &operator<<(std::ostream &out,
Tensor const &ts)
TensorSpecs(Shape const &s=Shape(), DataType d=float_data, bool trainable=true)
Specifications defined by shape, data type,.
Definition: tensor.hpp:20
Definition of Tensor without actual memory/object.
Definition: tensor.hpp:11
size_t total_size() const
Total number of elements - product of all items.
Definition: shape.hpp:72
void set_arg(cl::Kernel &k, int &pos)
Assign buffer and offset as kernel argumnets, at position pos and pos+1, pos incrementeded twice...
Definition: tensor.hpp:272
Tensor sub_tensor_target_offset(size_t offset, Shape const &s, DataType d=float_data, bool trainable=true) const
Create tensor on the memory of existing tensor.
Definition: tensor.hpp:207
Tensor workspace_as_type(DataType d=float_data) const
Create tensor over all avalible size for data type d.
Definition: tensor.hpp:193
Tensor shape.
Definition: shape.hpp:18
Tensor diff
value
Definition: tensor.hpp:296
T * data()
get pointer to the host pointer and cast to relevant type
Definition: tensor.hpp:246
cl_ulong device_offset()
Get offset - you should always bind both buffer and offset since there is no pointer arithmetics at h...
Definition: tensor.hpp:180
Tensor alias() const
Create a tensor with same memory but shape isn't connected to original - it is alias to same data but...
Definition: tensor.hpp:228
bool is_trainable() const
return if tensor need to participate in gradient decent
Definition: tensor.hpp:142
void freeze()
Mark tensor as one that does not participate in gradients calculations.
Definition: tensor.hpp:59
Shape const & shape() const
get tensor shape
Definition: tensor.hpp:134
Shape const & shape() const
get tensor shape
Definition: tensor.hpp:38
This is main object that represent the pair of OpenCL platform and device all other objects use it...
Definition: context.hpp:302
Tensor alias(Shape const &new_shape) const
same as t=alias(); t.reshape(s); return t;
Definition: tensor.hpp:235
DataType
type definition
Definition: definitions.hpp:70
size_t memory_size() const
Get reuired memory size for the tensor.
Definition: tensor.hpp:75
cl::Buffer & device_buffer()
Get cl::Buffer for the tensor.
Definition: tensor.hpp:170
Definition: definitions.hpp:95
Pair of tensor and its gradient for backpropogation.
Definition: tensor.hpp:292
void is_trainable(bool v)
set - non-trainable property
Definition: tensor.hpp:67
size_t memory_size() const
Get reuired memory size for the tensor.
Definition: tensor.hpp:150
Mane namespace.
Definition: context.hpp:9
bool is_floating_point_data_type(DataType d)
returns true of data is double, float, half or bfloat16 type
Definition: definitions.hpp:89
Central Data Contrainer - Tensor.
Definition: tensor.hpp:99
bool is_trainable() const
return if tensor need to participate in gradient decent
Definition: tensor.hpp:51
void reshape(Shape const &ns)
Reshape the tensor, the only requirement that ns.total_size() <= shape().total_size() ...
This class is used to pass cl::Events that the kernel should wait for and/or signal event completion...
Definition: context.hpp:121