Last active
March 5, 2018 15:45
-
-
Save chengduoZH/bc20fa8c12f8f045b74240dcdad41c84 to your computer and use it in GitHub Desktop.
test_concat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import paddle.fluid as fluid | |
shape1 = [100,1000,100] | |
shape2 = [100,1000,100] | |
axis=0 | |
x1 = fluid.layers.data( | |
name='x1', | |
shape=shape1, | |
dtype='float32', | |
append_batch_size=False) | |
x2 = fluid.layers.data( | |
name='x2', | |
shape=shape2, | |
dtype='float32', | |
append_batch_size=False) | |
y = fluid.layers.concat(input=[x1, x2], axis=axis) | |
place = fluid.CUDAPlace(0) | |
exe = fluid.Executor(place) | |
exe.run(fluid.default_startup_program()) | |
x1 = np.random.random(shape1).astype('float32') | |
x2 = np.random.random(shape2).astype('float32') | |
tensor_x = fluid.core.LoDTensor() | |
tensor_x.set(x1, place) | |
tensor_y = fluid.core.LoDTensor() | |
tensor_y.set(x2, place) | |
out_py = np.concatenate([x1,x2],axis = axis) | |
out = exe.run(fluid.default_main_program(), | |
feed={"x1": tensor_x, | |
"x2": tensor_y}, fetch_list=[y]) | |
out_data = np.array(out) | |
assert np.allclose(out_data, out_py) is True | |
PASS_NUM = 300 #, | |
with fluid.profiler.profiler("GPU", 'total',"/temp/Paddle") as prof: | |
for pass_id in range(PASS_NUM): | |
exe.run(fluid.default_main_program(), | |
feed={"x1": tensor_x, | |
"x2": tensor_y}) | |
print "over" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Experiment Result:
axis = 0
axis = 1
axis = 2