| 75 | |
| 76 | template<typename Dtype> |
| 77 | GPUParams<Dtype>::GPUParams(shared_ptr<Solver<Dtype> > root_solver, int device) |
| 78 | : Params<Dtype>(root_solver) { |
| 79 | #ifndef CPU_ONLY |
| 80 | int initial_device; |
| 81 | CUDA_CHECK(cudaGetDevice(&initial_device)); |
| 82 | |
| 83 | // Allocate device buffers |
| 84 | CUDA_CHECK(cudaSetDevice(device)); |
| 85 | CUDA_CHECK(cudaMalloc(&data_, size_ * sizeof(Dtype))); |
| 86 | |
| 87 | // Copy blob values |
| 88 | const vector<Blob<Dtype>*>& net = |
| 89 | root_solver->net()->learnable_params(); |
| 90 | apply_buffers(net, data_, size_, copy); |
| 91 | |
| 92 | CUDA_CHECK(cudaMalloc(&diff_, size_ * sizeof(Dtype))); |
| 93 | caffe_gpu_set(size_, Dtype(0), diff_); |
| 94 | |
| 95 | CUDA_CHECK(cudaSetDevice(initial_device)); |
| 96 | #else |
| 97 | NO_GPU; |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | template<typename Dtype> |
| 102 | GPUParams<Dtype>::~GPUParams() { |
nothing calls this directly
no test coverage detected