From 58c638774072704c97515abc982941abe5abc608 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Fri, 13 Apr 2018 10:39:43 -0700 Subject: [PATCH 1/3] Remove device_ptr_cast.h --- .../fluid/platform/details/device_ptr_cast.h | 56 ------------------- paddle/fluid/platform/transform.h | 22 ++++---- 2 files changed, 12 insertions(+), 66 deletions(-) delete mode 100644 paddle/fluid/platform/details/device_ptr_cast.h diff --git a/paddle/fluid/platform/details/device_ptr_cast.h b/paddle/fluid/platform/details/device_ptr_cast.h deleted file mode 100644 index 1c502a19c056c7..00000000000000 --- a/paddle/fluid/platform/details/device_ptr_cast.h +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#pragma once - -#ifndef __NVCC__ -#error device_ptr_cast must be include by .cu file -#endif - -#include - -namespace paddle { -namespace platform { -namespace details { -template -struct DevicePtrCast; - -template -struct DevicePtrCast { - using ELEM = typename std::remove_pointer::type; - using RTYPE = thrust::device_ptr; - - inline thrust::device_ptr operator()(ELEM* ele) const { - return thrust::device_pointer_cast(ele); - } -}; - -template -struct DevicePtrCast { - using RTYPE = T; - inline RTYPE operator()(RTYPE it) const { return it; } -}; - -// Cast T to thrust::device_ptr if T is a pointer. -// Otherwise, e.g., T is a iterator, return T itself. -template -auto DevPtrCast(T t) -> - typename DevicePtrCast::value>::RTYPE { - DevicePtrCast::value> cast; - return cast(t); -} - -} // namespace details -} // namespace platform -} // namespace paddle diff --git a/paddle/fluid/platform/transform.h b/paddle/fluid/platform/transform.h index 917c48b47f8d70..a76b6c1ee87399 100644 --- a/paddle/fluid/platform/transform.h +++ b/paddle/fluid/platform/transform.h @@ -14,17 +14,17 @@ limitations under the License. */ #pragma once +#include +#include + #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/hostdevice.h" #include "paddle/fluid/platform/place.h" -#include -#include #ifdef __NVCC__ -#include -#include -#include "paddle/fluid/platform/details/device_ptr_cast.h" +#include "thrust/execution_policy.h" +#include "thrust/transform.h" #endif namespace paddle { @@ -70,8 +70,9 @@ struct Transform { auto place = context.GetPlace(); PADDLE_ENFORCE(is_gpu_place(place), "It must use GPU place."); thrust::transform(thrust::cuda::par.on(context.stream()), - details::DevPtrCast(first), details::DevPtrCast(last), - details::DevPtrCast(result), op); + thrust::device_pointer_cast(first), + thrust::device_pointer_cast(last), + thrust::device_pointer_cast(result), op); } template { auto place = context.GetPlace(); PADDLE_ENFORCE(is_gpu_place(place), "It must use GPU place."); thrust::transform(thrust::cuda::par.on(context.stream()), - details::DevPtrCast(first1), details::DevPtrCast(last1), - details::DevPtrCast(first2), details::DevPtrCast(result), - op); + thrust::device_pointer_cast(first1), + thrust::device_pointer_cast(last1), + thrust::device_pointer_cast(first2), + thrust::device_pointer_cast(result), op); } }; #endif From b424dfaef932b6b0d771fae20fb120b58a57aa09 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Fri, 13 Apr 2018 11:48:38 -0700 Subject: [PATCH 2/3] Update inference_lib.cmake --- cmake/inference_lib.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index cc758019827b9a..fc3c2a95235265 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -132,8 +132,8 @@ copy(inference_lib DEPS paddle_fluid_shared paddle_fluid set(module "platform") copy(platform_lib DEPS profiler_py_proto - SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/dynload/*.h ${src_dir}/${module}/details/*.h - DSTS ${dst_dir}/${module} ${dst_dir}/${module}/dynload ${dst_dir}/${module}/details + SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/dynload/*.h + DSTS ${dst_dir}/${module} ${dst_dir}/${module}/dynload ) set(module "string") From a6f006cb7ccccaef537f7a570a023878328218e1 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Fri, 13 Apr 2018 12:21:45 -0700 Subject: [PATCH 3/3] Add header file --- paddle/fluid/platform/transform.h | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/fluid/platform/transform.h b/paddle/fluid/platform/transform.h index a76b6c1ee87399..2fe541c3166741 100644 --- a/paddle/fluid/platform/transform.h +++ b/paddle/fluid/platform/transform.h @@ -23,6 +23,7 @@ limitations under the License. */ #include "paddle/fluid/platform/place.h" #ifdef __NVCC__ +#include "thrust/device_ptr.h" #include "thrust/execution_policy.h" #include "thrust/transform.h" #endif