diff options
Diffstat (limited to 'runtime/neurun/backend/hi_perf_cpu')
6 files changed, 213 insertions, 0 deletions
diff --git a/runtime/neurun/backend/hi_perf_cpu/CMakeLists.txt b/runtime/neurun/backend/hi_perf_cpu/CMakeLists.txt new file mode 100644 index 000000000..816edba5e --- /dev/null +++ b/runtime/neurun/backend/hi_perf_cpu/CMakeLists.txt @@ -0,0 +1,44 @@ +set(LIB_NEURUN_BACKEND_HI_PERF_CPU neurun_backend_hi_perf) + +nnfw_find_package(NNPACK QUIET) + +option(BUILD_NEURUN_HI_PERF_CPU_BACKEND + "Build neurun HI_PERF_CPU backend" + ${NNPACK_FOUND} # Default value when there is no explicit user request +) + +message(STATUS "Build neurun HI_PERF_CPU backend: ${BUILD_NEURUN_HI_PERF_CPU_BACKEND}") + +if(NOT BUILD_NEURUN_HI_PERF_CPU_BACKEND) + return() +endif(NOT BUILD_NEURUN_HI_PERF_CPU_BACKEND) + +file(GLOB_RECURSE SOURCES "*.cc") +file(GLOB_RECURSE TESTS "*.test.cc") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_library(${LIB_NEURUN_BACKEND_HI_PERF_CPU} SHARED ${SOURCES}) + +target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_lib_misc) +target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_lib_cpp14) +target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE neurun_core) +target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_common) +target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnpack pthreadpool cpuinfo) +target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_coverage) +target_include_directories(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE ${NNPACK_INCLUDE_DIRS}) + +set_target_properties(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PROPERTIES OUTPUT_NAME backend_NNPACK) + +install(TARGETS ${LIB_NEURUN_BACKEND_HI_PERF_CPU} DESTINATION lib) + +# Unit Tests +set(TEST_NEURUN_BACKEND_HI_PERF_CPU test_neurun_backend_hi_perf) + +add_executable(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${TESTS}) + +target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${LIB_NEURUN_BACKEND_HI_PERF_CPU}) +target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} gtest gtest_main ${LIB_PTHREAD}) +target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} nnpack) + +add_test(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${TEST_NEURUN_BACKEND_HI_PERF_CPU}) +install(TARGETS ${TEST_NEURUN_BACKEND_HI_PERF_CPU} DESTINATION unittest) diff --git a/runtime/neurun/backend/hi_perf_cpu/HighPerformanceBackend.test.cc b/runtime/neurun/backend/hi_perf_cpu/HighPerformanceBackend.test.cc new file mode 100644 index 000000000..625fe1c36 --- /dev/null +++ b/runtime/neurun/backend/hi_perf_cpu/HighPerformanceBackend.test.cc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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 <gtest/gtest.h> + +#include "nnpack.h" + +TEST(High_performance_backend, NNPACK_Test) +{ + // Check that it is possible to import + const enum nnp_status init_status = nnp_initialize(); + + // One of the allowed nnp status codes + ASSERT_GE(init_status, 0); + ASSERT_LE(init_status, 54); + + // If it is possible to test, test relu + if (init_status == nnp_status_success) + { + float in[] = {-1, 1, -1, 1}; + float out[4]; + nnp_relu_output(1, 4, in, out, 0, nullptr); + for (int i = 0; i < 4; i++) + { + ASSERT_EQ(out[i], in[i] >= 0 ? in[i] : 0); + } + } + nnp_deinitialize(); +} diff --git a/runtime/neurun/backend/hi_perf_cpu/KernelGenerator.cc b/runtime/neurun/backend/hi_perf_cpu/KernelGenerator.cc new file mode 100644 index 000000000..a13fe12b9 --- /dev/null +++ b/runtime/neurun/backend/hi_perf_cpu/KernelGenerator.cc @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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 "KernelGenerator.h" +// to force compilation diff --git a/runtime/neurun/backend/hi_perf_cpu/KernelGenerator.h b/runtime/neurun/backend/hi_perf_cpu/KernelGenerator.h new file mode 100644 index 000000000..3197995e1 --- /dev/null +++ b/runtime/neurun/backend/hi_perf_cpu/KernelGenerator.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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. + */ + +#ifndef __NEURUN_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ +#define __NEURUN_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ + +#include <backend/IKernelGenerator.h> + +#include "ir/Operands.h" +#include "TensorBuilder.h" + +namespace neurun +{ +namespace backend +{ +namespace hi_perf_cpu +{ + +class KernelGenerator : public IKernelGenerator +{ +public: + KernelGenerator(const Operands &ctx, const std::shared_ptr<TensorBuilder> &tensor_builder); + // TODO add more ops + +private: + const Operands &_ctx; + std::shared_ptr<TensorBuilder> _tensor_builder; +}; + +} // namespace hi_perf_cpu +} // namespace backend +} // namespace neurun + +#endif // __NEURUN_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ diff --git a/runtime/neurun/backend/hi_perf_cpu/TensorBuilder.cc b/runtime/neurun/backend/hi_perf_cpu/TensorBuilder.cc new file mode 100644 index 000000000..e6ebf5f0b --- /dev/null +++ b/runtime/neurun/backend/hi_perf_cpu/TensorBuilder.cc @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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 "TensorBuilder.h" +// to force compilation diff --git a/runtime/neurun/backend/hi_perf_cpu/TensorBuilder.h b/runtime/neurun/backend/hi_perf_cpu/TensorBuilder.h new file mode 100644 index 000000000..af879a41e --- /dev/null +++ b/runtime/neurun/backend/hi_perf_cpu/TensorBuilder.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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. + */ + +#ifndef NNFW_TENSORBUILDER_H +#define NNFW_TENSORBUILDER_H + +#include <unordered_map> + +#include <backend/ITensorBuilder.h> +#include "ir/OperandIndexMap.h" + +namespace neurun +{ +namespace backend +{ +namespace hi_perf_cpu +{ + +class TensorBuilder : public ITensorBuilder +{ +public: + TensorBuilder(); + +private: +}; + +} // namespace hi_perf_cpu +} // namespace backend +} // namespace neurun + +#endif // NNFW_TENSORBUILDER_H |