#include "caffe2/core/context_gpu.h" #include "caffe2/operators/cast_op.h" namespace caffe2 { namespace { template __global__ void CastKernel(const int N, const SrcType* X, DstType* Y) { CUDA_1D_KERNEL_LOOP(i, N) { Y[i] = static_cast(X[i]); } } } // namespace template <> template bool CastOp::DoRunWithType() { auto& input = Input(0); auto* output = Output(0); output->ResizeLike(input); const auto* data = input.template data(); auto* out = output->template mutable_data(); DCHECK(input.size() < INT_MAX); int N = input.size(); CastKernel<<< CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS, 0, context_.cuda_stream()>>>(N, data, out); return true; } REGISTER_CUDA_OPERATOR(Cast, CastOp); } // namespace caffe2