本文整理汇总了C++中Tensor::FlatTo2D方法的典型用法代码示例。如果您正苦于以下问题:C++ Tensor::FlatTo2D方法的具体用法?C++ Tensor::FlatTo2D怎么用?C++ Tensor::FlatTo2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tensor
的用法示例。
在下文中一共展示了Tensor::FlatTo2D方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Copy
inline void Copy(Tensor<cpu,dim> _dst, const Tensor<cpu,dim> &_src ){
utils::Assert( _dst.shape == _src.shape, "Copy:shape mismatch" );
Tensor<cpu,2> dst = _dst.FlatTo2D();
Tensor<cpu,2> src = _src.FlatTo2D();
for (index_t y = 0; y < dst.shape[1]; ++y ) {
memcpy( dst[y].dptr, src[y].dptr, sizeof(real_t) * dst.shape[0] );
}
}
示例2: Copy
inline void Copy(Tensor<A,dim> _dst, Tensor<B,dim> _src, cudaMemcpyKind kind){
utils::Assert( _dst.shape == _src.shape, "Copy:shape mismatch" );
Tensor<A,2> dst = _dst.FlatTo2D();
Tensor<B,2> src = _src.FlatTo2D();
cudaError_t err = cudaMemcpy2D( dst.dptr, dst.shape.stride_ * sizeof(real_t),
src.dptr, src.shape.stride_ * sizeof(real_t),
dst.shape[0] * sizeof(real_t),
dst.shape[1], kind );
utils::Assert( err == cudaSuccess, cudaGetErrorString(err) );
}
示例3: MapPlan
inline void MapPlan(Tensor<cpu,dim> _dst, const expr::Plan<E> &plan){
Tensor<cpu,2> dst = _dst.FlatTo2D();
for (index_t y = 0; y < dst.shape[1]; ++y ) {
for (index_t x = 0; x < dst.shape[0]; ++x ) {
// trust your compiler! -_- they will optimize it
Saver::Save(dst[y][x], plan.Eval( y, x ) );
}
}
}
示例4: AllocSpace
inline void AllocSpace(Tensor<cpu,dim> &obj, bool pad ){
size_t pitch;
if( pad ){
obj.dptr = (real_t*)sse2::AlignedMallocPitch
( pitch, obj.shape[0] * sizeof(real_t), obj.FlatTo2D().shape[1] );
obj.shape.stride_ = static_cast<index_t>( pitch / sizeof(real_t) );
}else{
obj.shape.stride_ = obj.shape[0];
obj.dptr = (real_t*)sse2::AlignedMallocPitch
( pitch, obj.shape.Size() * sizeof(real_t), 1 );
}
}
示例5: AllocSpace
inline void AllocSpace(Tensor<gpu,dim> &obj, bool pad){
size_t pitch;
// common choice for cuda mem align unit is 32
if( pad && obj.shape[0] >= MSHADOW_MIN_PAD_RATIO * 32 ){
cudaError_t err = cudaMallocPitch( (void**)&obj.dptr, &pitch, \
obj.shape[0] * sizeof(real_t), obj.FlatTo2D().shape[1] );
utils::Assert( err == cudaSuccess, cudaGetErrorString(err) );
obj.shape.stride_ = static_cast<index_t>( pitch / sizeof(real_t) );
}else{
obj.shape.stride_ = obj.shape[0];
cudaError_t err = cudaMallocPitch( (void**)&obj.dptr, &pitch, \
obj.shape.Size() * sizeof(real_t), 1 );
utils::Assert( err == cudaSuccess, cudaGetErrorString(err) );
}
}
示例6: MapPlan
inline void MapPlan(Tensor<gpu,dim> _dst, const expr::Plan<E> &plan){
cuda::MapPlan<Saver>( _dst.FlatTo2D(), plan );
}