Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into crop_op
Conflicts: paddle/pybind/pybind.cc python/paddle/v2/framework/tests/op_test_util.pyupdate-doc-pybind
commit
b299d07fbe
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include "paddle/framework/lod_tensor.h"
|
||||
#include "paddle/platform/assert.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
__global__ void test(size_t* a, int size) {
|
||||
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < size;
|
||||
i += blockDim.x * gridDim.x) {
|
||||
a[i] *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LoDTensor, LoDInGPU) {
|
||||
paddle::framework::Tensor tensor;
|
||||
paddle::framework::LoDTensor lod_tensor;
|
||||
paddle::platform::GPUPlace place(0);
|
||||
|
||||
paddle::framework::LoD src_lod;
|
||||
src_lod.push_back(std::vector<size_t>{0, 2, 4, 6, 8, 10, 12, 14});
|
||||
|
||||
tensor.Resize({14, 16});
|
||||
tensor.mutable_data<float>(place);
|
||||
|
||||
lod_tensor.set_lod(src_lod);
|
||||
lod_tensor.set_tensor(&tensor);
|
||||
CHECK_EQ(lod_tensor.lod_element(0, 2), 4);
|
||||
CHECK_EQ(lod_tensor.lod_element(0, 4), 8);
|
||||
|
||||
auto lod = lod_tensor.lod();
|
||||
|
||||
test<<<1, 8>>>(lod[0].data(), lod[0].size());
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
for (size_t i = 0; i < src_lod[0].size(); ++i) {
|
||||
CHECK_EQ(lod[0].data()[i], src_lod[0].data()[i] * 2);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue