2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <thrust/detail/config.h>
20 #include <thrust/system/cuda/detail/execution_policy.h>
21 #include <thrust/detail/raw_pointer_cast.h>
22 #include <thrust/system/cuda/detail/guarded_cuda_runtime_api.h>
23 #include <thrust/system/system_error.h>
24 #include <thrust/system/cuda/error.h>
25 #include <thrust/system/detail/bad_alloc.h>
37 // note that malloc returns a raw pointer to avoid
38 // depending on the heavyweight thrust/system/cuda/memory.h header
39 template<typename DerivedPolicy>
40 void *malloc(execution_policy<DerivedPolicy> &, std::size_t n)
44 cudaError_t error = cudaMalloc(reinterpret_cast<void**>(&result), n);
48 throw thrust::system::detail::bad_alloc(thrust::cuda_category().message(error).c_str());
55 template<typename DerivedPolicy, typename Pointer>
56 void free(execution_policy<DerivedPolicy> &, Pointer ptr)
58 cudaError_t error = cudaFree(thrust::raw_pointer_cast(ptr));
62 throw thrust::system_error(error, thrust::cuda_category());