Context Design
Created by: QiJune
In our Operator Design, an operator must implement Run method to take variables from scope, and then make computation. The computing part are finished by Eigen. Following is an example: (d_a, d_b and d_c are raw pointers token from tensor)
template <typename T>
using Vec = Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>,
Eigen::Aligned>;
Vec<float> a(d_a, size);
Vec<float> b(d_b, size);
Vec<float> c(d_c, size);
Eigen::CudaStreamDevice sd;
Eigen::GpuDevice dd(&sd);
c.device(dd) = a + b;
We must set a CudaStreamDevice and get a GpuDevice to make computation on GPU card. A CudaStreamDevice is usually bind with a specific stream.
So, a Context concepts needs to be put forward to handle runtime resources, such as stream, cudnnHandle, and cublasHandle.
The Run method in Operator will be defined as follows, which make computation on a specific context:
Error Run(Scope* scope, Context* context) = 0;