Skip to content

Instantly share code, notes, and snippets.

@chengduoZH
Last active March 5, 2018 15:45
Show Gist options
  • Save chengduoZH/bc20fa8c12f8f045b74240dcdad41c84 to your computer and use it in GitHub Desktop.
Save chengduoZH/bc20fa8c12f8f045b74240dcdad41c84 to your computer and use it in GitHub Desktop.
test_concat
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"
@chengduoZH
Copy link
Author

chengduoZH commented Mar 4, 2018

Experiment Result:
axis = 0

input_shape copy(D->D) D->H->concat->D kernel
1 x 10^6 0.074824667 / 0.100071
1 x 10^7 0.472866667 / 0.568678
1 x 10^8 4.530733333 / 9.6112

axis = 1

input_shape copy(D->D) D->H->concat->D kernel
100 x 10^4 0.893866667 3.3531 0.076095
100 x 10^5 1.227483333 34.148 0.58596
1000 x 10^4 10.02413333 35.25233333 0.5465
100 x 10^6 5.195033333 362.9734997 9.7122
1000 x 10^5 10.5971 391.4569667 9.506333333

axis = 2

input_shape copy(D->D) D->H->concat->D kernel
10^4 x 100 87.12066667 3.2949 0.078481
10^4 x 1000 89.871 39.51366667 0.55338
10^5 x 1000 938.5879967 389.6895 8.571266667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment