From 4d88cdb88197a8d20f84e05cf54f8ca8d94f3bb6 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 18 Aug 2021 12:02:18 +0800 Subject: [PATCH] [CustomOp] Fix ext_tensor.cast failed bug (#34884) * fix ext_tensor.cast failed bug * remove useless deps * fix windows cmake failed * try to fix windows make failed * fix make error on windwos --- paddle/fluid/extension/src/ext_tensor.cu | 1 + paddle/fluid/framework/CMakeLists.txt | 14 +++++++++++--- paddle/fluid/framework/custom_tensor_test.cc | 7 +++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 120000 paddle/fluid/extension/src/ext_tensor.cu diff --git a/paddle/fluid/extension/src/ext_tensor.cu b/paddle/fluid/extension/src/ext_tensor.cu new file mode 120000 index 00000000000..23ae5233318 --- /dev/null +++ b/paddle/fluid/extension/src/ext_tensor.cu @@ -0,0 +1 @@ +ext_tensor.cc \ No newline at end of file diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index d0c64f44af3..6853b03c612 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -17,7 +17,7 @@ function(windows_symbolic TARGET) add_custom_command(OUTPUT ${final_path}/.${src}.cu COMMAND ${CMAKE_COMMAND} -E copy_if_different "${final_path}/${src}.cc" "${final_path}/.${src}.cu" COMMENT "create hidden file of ${src}.cu") - add_custom_target(${TARGET} ALL DEPENDS .${src}.cu) + add_custom_target(${TARGET} ALL DEPENDS ${final_path}/.${src}.cu) endforeach() endfunction() @@ -413,8 +413,16 @@ include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/extension/include) include_directories(${PADDLE_SOURCE_DIR}/paddle/utils) -if(WITH_ROCM) - hip_library(custom_tensor SRCS ../extension/src/ext_tensor.cc DEPS lod_tensor memory enforce) +if (WITH_GPU) + if (WIN32) + windows_symbolic(ext_tensor_cu SRCS ext_tensor.cu PATH ../extension/src) + nv_library(custom_tensor SRCS ../extension/src/.ext_tensor.cu DEPS lod_tensor memory enforce) + add_dependencies(custom_tensor ext_tensor_cu) + else() + nv_library(custom_tensor SRCS ../extension/src/ext_tensor.cu DEPS lod_tensor memory enforce) + endif(WIN32) +elseif (WITH_ROCM) + hip_library(custom_tensor SRCS ../extension/src/ext_tensor.cu DEPS lod_tensor memory enforce) else() cc_library(custom_tensor SRCS ../extension/src/ext_tensor.cc DEPS lod_tensor memory enforce) endif() diff --git a/paddle/fluid/framework/custom_tensor_test.cc b/paddle/fluid/framework/custom_tensor_test.cc index 7fbc4f554ba..5d181bfb53b 100644 --- a/paddle/fluid/framework/custom_tensor_test.cc +++ b/paddle/fluid/framework/custom_tensor_test.cc @@ -144,6 +144,13 @@ void TestCast(paddle::DataType data_type) { t1.template mutable_data(); auto t2 = t1.cast(data_type); CHECK(t2.type() == data_type); +#ifdef PADDLE_WITH_CUDA + auto tg1 = paddle::Tensor(paddle::PlaceType::kGPU); + tg1.reshape(tensor_shape); + tg1.template mutable_data(); + auto tg2 = tg1.cast(data_type); + CHECK(tg2.type() == data_type); +#endif } void GroupTestCopy() { -- GitLab