From d7b834aae3ac54ca4b4e857b449ca4884745ad80 Mon Sep 17 00:00:00 2001 From: zhangyang Date: Wed, 5 Sep 2018 12:47:05 +0800 Subject: [PATCH] add test code for FPGA track --- src/fpga/api.cpp | 17 +----------- test/CMakeLists.txt | 3 +++ test/fpga/test_format_data.cpp | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 test/fpga/test_format_data.cpp diff --git a/src/fpga/api.cpp b/src/fpga/api.cpp index ca3c80b147..4a1617b402 100644 --- a/src/fpga/api.cpp +++ b/src/fpga/api.cpp @@ -12,33 +12,18 @@ 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 +#include "api.h" #include -#include #include #include #include -#include -#include -#include -#include #include -#include -#include #include -#include - -#include "api.h" #include "bias_scale.h" -#include "common/enforce.h" -#include "common/types.h" #include "filter.h" #include "image.h" #define FPGA_TEST_MODE -#ifdef FPGA_TEST_MODE -#include "common/log.h" -#endif namespace paddle_mobile { namespace fpga { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f2229a1bfc..bfc9fb3eb3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,6 +35,9 @@ elseif("FPGAnets" IN_LIST NET) ADD_EXECUTABLE(test-fpga-concat-op fpga/test_concat_op.cpp test_helper.h test_include.h) target_link_libraries(test-fpga-concat-op paddle-mobile) + + ADD_EXECUTABLE(test-format-data fpga/test_format_data.cpp test_helper.h test_include.h) + target_link_libraries(test-format-data paddle-mobile) elseif("mobilenetssd" IN_LIST NET) # gen test ADD_EXECUTABLE(test-mobilenetssd net/test_mobilenet+ssd.cpp test_helper.h test_include.h executor_for_test.h) diff --git a/test/fpga/test_format_data.cpp b/test/fpga/test_format_data.cpp new file mode 100644 index 0000000000..0fa3c23d2a --- /dev/null +++ b/test/fpga/test_format_data.cpp @@ -0,0 +1,49 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +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 +#include "../test_helper.h" +#include "../test_include.h" +#include "fpga/api.h" + +namespace frame = paddle_mobile::framework; +namespace fpga = paddle_mobile::fpga; +using std::cout; +using std::endl; + +int main() { + std::vector dims{1, 1, 3, 3}; + std::vector elements{1, 2, 3, 4, 5, 6, 7, 8, 9}; + frame::DDim ddim = frame::make_ddim(dims); + frame::Tensor image(elements, ddim); + int num = image.numel(); + float *data_ptr = image.mutable_data(); + + for (int i = 0; i < num; i++) { + cout << data_ptr[i] << " "; + } + cout << endl; + + fpga::format_image(&image); + data_ptr = image.mutable_data(); + + for (int i = 0; i < 48; i++) { + cout << data_ptr[i] << " "; + } + cout << endl; + auto dd = image.dims(); + cout << dims[0] << dims[1] << dims[2] << dims[3] << endl; + + return 0; +} -- GitLab