1/* 2 * Copyright 2008-2018 NVIDIA Corporation 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17#pragma once 18 19#include <thrust/detail/config.h> 20#include <thrust/system/cuda/memory.h> 21#include <thrust/system/cuda/detail/malloc_and_free.h> 22#include <limits> 23 24namespace thrust 25{ 26namespace cuda_cub 27{ 28 29__host__ __device__ 30pointer<void> malloc(std::size_t n) 31{ 32 tag cuda_tag; 33 return pointer<void>(thrust::cuda_cub::malloc(cuda_tag, n)); 34} // end malloc() 35 36template<typename T> 37__host__ __device__ 38pointer<T> malloc(std::size_t n) 39{ 40 pointer<void> raw_ptr = thrust::cuda_cub::malloc(sizeof(T) * n); 41 return pointer<T>(reinterpret_cast<T*>(raw_ptr.get())); 42} // end malloc() 43 44__host__ __device__ 45void free(pointer<void> ptr) 46{ 47 tag cuda_tag; 48 return thrust::cuda_cub::free(cuda_tag, ptr.get()); 49} // end free() 50 51} // end cuda_cub 52} // end thrust 53 54