未验证 提交 6c675ed9 编写于 作者: R ronnywang 提交者: GitHub

[CustomDevice] fix SplitDenseTensor (#55615)

上级 f9b9b8b6
...@@ -531,7 +531,9 @@ void Free<platform::CustomPlace>(const platform::CustomPlace &place, ...@@ -531,7 +531,9 @@ void Free<platform::CustomPlace>(const platform::CustomPlace &place,
size_t size) { size_t size) {
#ifdef PADDLE_WITH_CUSTOM_DEVICE #ifdef PADDLE_WITH_CUSTOM_DEVICE
VLOG(10) << "Free pointer=" << p << " on " << platform::Place(place); VLOG(10) << "Free pointer=" << p << " on " << platform::Place(place);
if (phi::DeviceManager::HasDeviceType(place.GetDeviceType())) {
GetBuddyAllocator(place)->Free(p); GetBuddyAllocator(place)->Free(p);
}
#else #else
PADDLE_THROW(platform::errors::PermissionDenied( PADDLE_THROW(platform::errors::PermissionDenied(
"'CustomPlace' is not supported in CPU only device.")); "'CustomPlace' is not supported in CPU only device."));
......
...@@ -96,12 +96,22 @@ struct SplitDenseTensor<platform::CustomDeviceContext, T> { ...@@ -96,12 +96,22 @@ struct SplitDenseTensor<platform::CustomDeviceContext, T> {
const phi::Scalar &, const phi::Scalar &,
std::vector<phi::DenseTensor *>); std::vector<phi::DenseTensor *>);
auto *kernel_fn = kernel.GetVariadicKernelFn<kernel_signature>(); auto *kernel_fn = kernel.GetVariadicKernelFn<kernel_signature>();
auto in_dims = phi::vectorize(in.dims());
auto origin_out_dims = phi::vectorize(out->at(0)->dims());
for (auto *tensor : *out) {
if (origin_out_dims.size() != in_dims.size()) {
std::vector<int> new_dims({1});
new_dims.insert(
new_dims.end(), origin_out_dims.begin(), origin_out_dims.end());
tensor->Resize(phi::make_ddim(new_dims));
}
}
(*kernel_fn)(context, in, out->size(), phi::Scalar(0), *out); (*kernel_fn)(context, in, out->size(), phi::Scalar(0), *out);
for (auto *tensor : *out) { for (auto *tensor : *out) {
auto dim_vec = phi::vectorize<int>(tensor->dims()); auto tensor_dims = phi::vectorize(tensor->dims());
if (dim_vec.size() > 0 && dim_vec[0] == 1) { if (tensor_dims.size() != origin_out_dims.size()) {
tensor->Resize(phi::make_ddim( tensor->Resize(phi::make_ddim(origin_out_dims));
std::vector<int>(dim_vec.begin() + 1, dim_vec.end())));
} }
} }
} }
......
...@@ -150,12 +150,12 @@ class TestProcessGroup(TestMultipleCustomCPU): ...@@ -150,12 +150,12 @@ class TestProcessGroup(TestMultipleCustomCPU):
cur_dir = os.path.dirname(os.path.abspath(__file__)) cur_dir = os.path.dirname(os.path.abspath(__file__))
self.temp_dir = tempfile.TemporaryDirectory() self.temp_dir = tempfile.TemporaryDirectory()
cmd = 'cd {} \ cmd = 'cd {} \
&& git clone {} \ && git clone --depth 1 {} \
&& cd PaddleCustomDevice \ && cd PaddleCustomDevice \
&& git fetch origin \ && git fetch origin \
&& git checkout {} -b dev \ && git checkout {} -b dev \
&& cd backends/custom_cpu \ && cd backends/custom_cpu \
&& mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} && make -j8'.format( && mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} -DWITH_TESTING=OFF && make -j8'.format(
self.temp_dir.name, self.temp_dir.name,
os.getenv('PLUGIN_URL'), os.getenv('PLUGIN_URL'),
os.getenv('PLUGIN_TAG'), os.getenv('PLUGIN_TAG'),
......
...@@ -26,12 +26,12 @@ class TestCustomCPUPlugin(unittest.TestCase): ...@@ -26,12 +26,12 @@ class TestCustomCPUPlugin(unittest.TestCase):
cur_dir = os.path.dirname(os.path.abspath(__file__)) cur_dir = os.path.dirname(os.path.abspath(__file__))
self.temp_dir = tempfile.TemporaryDirectory() self.temp_dir = tempfile.TemporaryDirectory()
cmd = 'cd {} \ cmd = 'cd {} \
&& git clone {} \ && git clone --depth 1 {} \
&& cd PaddleCustomDevice \ && cd PaddleCustomDevice \
&& git fetch origin \ && git fetch origin \
&& git checkout {} -b dev \ && git checkout {} -b dev \
&& cd backends/custom_cpu \ && cd backends/custom_cpu \
&& mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} && make -j8'.format( && mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} -DWITH_TESTING=OFF && make -j8'.format(
self.temp_dir.name, self.temp_dir.name,
os.getenv('PLUGIN_URL'), os.getenv('PLUGIN_URL'),
os.getenv('PLUGIN_TAG'), os.getenv('PLUGIN_TAG'),
......
...@@ -24,12 +24,12 @@ class TestCustomCPUProfilerPlugin(unittest.TestCase): ...@@ -24,12 +24,12 @@ class TestCustomCPUProfilerPlugin(unittest.TestCase):
cur_dir = os.path.dirname(os.path.abspath(__file__)) cur_dir = os.path.dirname(os.path.abspath(__file__))
self.temp_dir = tempfile.TemporaryDirectory() self.temp_dir = tempfile.TemporaryDirectory()
cmd = 'cd {} \ cmd = 'cd {} \
&& git clone {} \ && git clone --depth 1 {} \
&& cd PaddleCustomDevice \ && cd PaddleCustomDevice \
&& git fetch origin \ && git fetch origin \
&& git checkout {} -b dev \ && git checkout {} -b dev \
&& cd backends/custom_cpu \ && cd backends/custom_cpu \
&& mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} && make -j8'.format( && mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} -DWITH_TESTING=OFF && make -j8'.format(
self.temp_dir.name, self.temp_dir.name,
os.getenv('PLUGIN_URL'), os.getenv('PLUGIN_URL'),
os.getenv('PLUGIN_TAG'), os.getenv('PLUGIN_TAG'),
......
...@@ -106,12 +106,12 @@ class TestCustomCPUPlugin(unittest.TestCase): ...@@ -106,12 +106,12 @@ class TestCustomCPUPlugin(unittest.TestCase):
cur_dir = os.path.dirname(os.path.abspath(__file__)) cur_dir = os.path.dirname(os.path.abspath(__file__))
self.temp_dir = tempfile.TemporaryDirectory() self.temp_dir = tempfile.TemporaryDirectory()
cmd = 'cd {} \ cmd = 'cd {} \
&& git clone {} \ && git clone --depth 1 {} \
&& cd PaddleCustomDevice \ && cd PaddleCustomDevice \
&& git fetch origin \ && git fetch origin \
&& git checkout {} -b dev \ && git checkout {} -b dev \
&& cd backends/custom_cpu \ && cd backends/custom_cpu \
&& mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} && make -j8'.format( && mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} -DWITH_TESTING=OFF && make -j8'.format(
self.temp_dir.name, self.temp_dir.name,
os.getenv('PLUGIN_URL'), os.getenv('PLUGIN_URL'),
os.getenv('PLUGIN_TAG'), os.getenv('PLUGIN_TAG'),
......
...@@ -104,12 +104,12 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase): ...@@ -104,12 +104,12 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
self.cur_dir = os.path.dirname(os.path.abspath(__file__)) self.cur_dir = os.path.dirname(os.path.abspath(__file__))
self.temp_dir = tempfile.TemporaryDirectory() self.temp_dir = tempfile.TemporaryDirectory()
cmd = 'cd {} \ cmd = 'cd {} \
&& git clone {} \ && git clone --depth 1 {} \
&& cd PaddleCustomDevice \ && cd PaddleCustomDevice \
&& git fetch origin \ && git fetch origin \
&& git checkout {} -b dev \ && git checkout {} -b dev \
&& cd backends/custom_cpu \ && cd backends/custom_cpu \
&& mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} && make -j8 \ && mkdir build && cd build && cmake .. -DPython_EXECUTABLE={} -DWITH_TESTING=OFF && make -j8 \
&& cd {}'.format( && cd {}'.format(
self.temp_dir.name, self.temp_dir.name,
os.getenv('PLUGIN_URL'), os.getenv('PLUGIN_URL'),
......
...@@ -18,12 +18,12 @@ set -e ...@@ -18,12 +18,12 @@ set -e
temp_dir=$(mktemp --directory) temp_dir=$(mktemp --directory)
pushd ${temp_dir} \ pushd ${temp_dir} \
&& git clone ${PLUGIN_URL} \ && git clone --depth 1 ${PLUGIN_URL} \
&& pushd PaddleCustomDevice/ \ && pushd PaddleCustomDevice/ \
&& git fetch origin \ && git fetch origin \
&& git checkout ${PLUGIN_TAG} -b dev \ && git checkout ${PLUGIN_TAG} -b dev \
&& pushd backends/custom_cpu \ && pushd backends/custom_cpu \
&& mkdir build && pushd build && cmake .. -DPython_EXECUTABLE=${PYTHON_EXECUTABLE} && make -j8 && popd && popd && popd && popd && mkdir build && pushd build && cmake .. -DPython_EXECUTABLE=${PYTHON_EXECUTABLE} -DWITH_TESTING=OFF && make -j8 && popd && popd && popd && popd
echo "begin test use custom_cpu" echo "begin test use custom_cpu"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册