未验证 提交 ab6daf84 编写于 作者: L Leo Chen 提交者: GitHub

[new-exec] add standalone executor test (#38101)

* refine test

* add download_program target

* update ut code

* refine code

* disable profiler

* add comments

* refine cmake

* skip coverage ci
上级 3a2093a5
......@@ -12,4 +12,56 @@ cc_library(stream_analyzer SRCS stream_analyzer.cc DEPS ${DEVICE_EVENT_LIBS} glo
cc_library(interpretercore SRCS interpretercore.cc DEPS workqueue ${DEVICE_EVENT_LIBS} interpretercore_util interpretercore_garbage_collector stream_analyzer event_manager)
cc_library(standalone_executor SRCS standalone_executor.cc DEPS interpretercore)
cc_test(workqueue_test SRCS workqueue_test.cc DEPS workqueue)
# cc_binary(standalone_executor_test SRCS standalone_executor_test.cc DEPS interpretercore standalone_executor operator op_registry executor ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS} profiler)
# skip win32 since wget is not installed by default on windows machine.
# skip COVERAGE_CI since the test runs slowly because of instrumentation.
if (WITH_TESTING AND NOT WIN32 AND NOT WITH_COVERAGE)
add_custom_target(
download_program
COMMAND wget -nc https://paddle-ci.gz.bcebos.com/new_exec/lm_main_program
COMMAND wget -nc https://paddle-ci.gz.bcebos.com/new_exec/lm_startup_program
)
# all operators used in the program
set(OPS
fill_constant_op
uniform_random_op
lookup_table_op
transpose_op
reshape_op
split_op
slice_op
concat_op
matmul_op
elementwise_add_op
elementwise_mul_op
softmax_with_cross_entropy_op
reduce_mean_op
reduce_sum_op
activation_op
sum_op
elementwise_max_op
elementwise_div_op
sgd_op
squared_l2_norm_op
memcpy_h2d_op
memcpy_d2h_op)
# All deps of the operators above, part of GLOB_OPERATOR_DEPS.
set(OP_DEPS
generator
softmax
selected_rows_functor
jit_kernel_helper
concat_and_split
cross_entropy)
cc_test(standalone_executor_test SRCS standalone_executor_test.cc DEPS interpretercore standalone_executor operator op_registry executor ${OPS} ${OP_DEPS})
set_tests_properties(standalone_executor_test PROPERTIES TIMEOUT 100)
add_dependencies(standalone_executor_test download_program)
if (WITH_PROFILER)
target_link_libraries(standalone_executor_test profiler)
add_dependencies(standalone_executor_test profiler)
endif()
endif()
......@@ -12,15 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <chrono>
#include <iostream>
#include <string>
#include <chrono>
#include <map>
#include <memory>
#include <unordered_map>
#include <vector>
// #include "gperftools/profiler.h"
#include "paddle/fluid/framework/new_executor/standalone_executor.h"
......@@ -63,8 +59,12 @@ USE_OP(sgd);
USE_OP(squared_l2_norm);
USE_OP(memcpy_h2d);
USE_OP(memcpy_d2h);
DECLARE_double(eager_delete_tensor_gb);
namespace paddle {
namespace framework {
paddle::framework::ProgramDesc load_from_file(const std::string& file_name) {
ProgramDesc load_from_file(const std::string& file_name) {
std::ifstream fin(file_name, std::ios::in | std::ios::binary);
fin.seekg(0, std::ios::end);
std::string buffer(fin.tellg(), ' ');
......@@ -72,18 +72,16 @@ paddle::framework::ProgramDesc load_from_file(const std::string& file_name) {
fin.read(&buffer[0], buffer.size());
fin.close();
paddle::framework::ProgramDesc program_desc(buffer);
ProgramDesc program_desc(buffer);
return program_desc;
}
int main(int argc, char* argv[]) {
paddle::framework::InitDevices();
std::cout << "main" << std::endl;
int64_t batch_size = std::stoi(argv[1]);
paddle::framework::InitDevices();
auto place = paddle::platform::CUDAPlace(0);
auto test_prog = load_from_file("lm_startup_program");
TEST(StandaloneExecutor, run) {
FLAGS_eager_delete_tensor_gb = 0.1;
int64_t batch_size = 20;
auto place = platform::CUDAPlace(0);
auto test_prog = load_from_file("lm_startup_program");
auto main_prog = load_from_file("lm_main_program");
auto& global_block = main_prog.Block(0);
......@@ -103,12 +101,13 @@ int main(int argc, char* argv[]) {
shape3[0] = batch_size;
op3->SetAttr("shape", shape3);
paddle::framework::Scope scope;
paddle::framework::StandaloneExecutor exec(place, test_prog, main_prog,
&scope);
Scope scope;
StandaloneExecutor exec(place, test_prog, main_prog, &scope);
exec.Run({}, {}, {});
auto start = std::chrono::steady_clock::now();
// ProfilerStart("new_executor.prof");
for (size_t i = 0; i < 2320; ++i) {
if (i % 200 == 0) {
std::cout << i << std::endl;
......@@ -116,11 +115,15 @@ int main(int argc, char* argv[]) {
exec.Run({}, {}, {});
}
// ProfilerStop();
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "time cost " << diff.count() << std::endl;
return 1;
ASSERT_LT(diff.count(), 30);
}
} // namespace framework
} // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册