DLPrimitives
pointwise.hpp
1 #pragma once
2 #include <dlprim/tensor.hpp>
3 #include <dlprim/context.hpp>
4 namespace dlprim {
5 namespace core {
6 
10  void bind_as_dtype(cl::Kernel &k,int &p,double value,DataType dt);
19  void pointwise_operation(std::vector<Tensor> xs,
20  std::vector<Tensor> ys,
21  std::vector<double> ws,
22  std::string const &code,
23  ExecutionContext const &ec);
28  void pointwise_operation_broadcast( std::vector<Tensor> xs,
29  std::vector<Tensor> ys,
30  std::vector<double> weights,
31  std::string const &code,
32  ExecutionContext const &e);
33 
37  void pointwise_operation_broadcast( std::vector<Tensor> xs,
38  std::vector<Tensor> ys,
39  std::vector<double> weights,
40  std::vector<DataType> weights_types,
41  std::string const &code,
42  ExecutionContext const &e);
56  public:
57 
62  virtual size_t workspace() = 0;
68  // \param parameters - the weight paramerters, size should match weights_count
73  virtual void enqueue(std::vector<Tensor> xs,
74  std::vector<Tensor> ys,
76  std::vector<double> parameters,
77  std::vector<double> alpha,
78  std::vector<double> beta,
79  ExecutionContext const &e) = 0;
80 
86  // \param weights_count - size of parameters vector in enqueue
95  static std::unique_ptr<PointwiseOperationBroadcastReduce> create(
96  Context &ctx,
97  std::vector<TensorSpecs> xs,
98  std::vector<TensorSpecs> ys,
99  int weights_count,DataType weights_type,
100  std::string const &compute_code,
101  std::string const &reduce_init,
102  std::string const &reduce);
103 
104  };
105 
106 } // core
107 } // dlprim
void pointwise_operation(std::vector< Tensor > xs, std::vector< Tensor > ys, std::vector< double > ws, std::string const &code, ExecutionContext const &ec)
per form operations function(xs,ws)->yw such that each tensor in xs and ys has same shape...
void pointwise_operation_broadcast(std::vector< Tensor > xs, std::vector< Tensor > ys, std::vector< double > weights, std::string const &code, ExecutionContext const &e)
Similar to pointwise_operation but xs are broadcasted numpy style. ys must much broadcasted shape...
This is main object that represent the pair of OpenCL platform and device all other objects use it...
Definition: context.hpp:302
virtual size_t workspace()=0
Get size of workspace in bytes needed.
DataType
type definition
Definition: definitions.hpp:70
Perform pointwise operation with both boradcasting and reduction.
Definition: pointwise.hpp:55
virtual void enqueue(std::vector< Tensor > xs, std::vector< Tensor > ys, Tensor &workspace, std::vector< double > parameters, std::vector< double > alpha, std::vector< double > beta, ExecutionContext const &e)=0
Perform coputations.
void bind_as_dtype(cl::Kernel &k, int &p, double value, DataType dt)
Bind a parameter to kernet casting it to apropriate opencl type dt.
Mane namespace.
Definition: context.hpp:9
Central Data Contrainer - Tensor.
Definition: tensor.hpp:99
static std::unique_ptr< PointwiseOperationBroadcastReduce > create(Context &ctx, std::vector< TensorSpecs > xs, std::vector< TensorSpecs > ys, int weights_count, DataType weights_type, std::string const &compute_code, std::string const &reduce_init, std::string const &reduce)
Create objects:
This class is used to pass cl::Events that the kernel should wait for and/or signal event completion...
Definition: context.hpp:121