From 225f102b579bf6b37f4e238f7710c41e462ae880 Mon Sep 17 00:00:00 2001 From: Jarod Wang Date: Thu, 30 Nov 2017 20:21:24 +0800 Subject: [PATCH] Initial release of NVDLA virtual platform --- .dockerignore | 2 + .gitignore | 18 ++ .gitlab-ci.yml | 7 + .gitmodules | 18 ++ CMakeLists.txt | 163 +++++++++++ LICENSE | 206 ++++++++++++++ README.md | 86 ++++++ cmake/FindLua.cmake | 117 ++++++++ cmake/FindNvdlaCmod.cmake | 77 ++++++ cmake/FindSystemC.cmake | 114 ++++++++ cmake/FindTLM.cmake | 85 ++++++ conf/aarch64_nvdla.lua | 20 ++ conf/aarch64_nvdla_dump_dts.lua | 20 ++ docker/Dockerfile | 25 ++ docker/docker_gen.sh | 66 +++++ docker/docker_run.sh | 19 ++ libs/greenlib | 1 + libs/log/CMakeLists.txt | 78 ++++++ libs/log/README.md | 74 +++++ libs/log/include/log/log.h | 18 ++ libs/log/src/log.cpp | 214 ++++++++++++++ libs/qbox | 1 + libs/tlm2c | 1 + models/cpu | 1 + models/memory | 1 + models/nvdla/CMakeLists.txt | 113 ++++++++ models/nvdla/README.md | 21 ++ models/nvdla/cmake/FindGREENLIB.cmake | 70 +++++ models/nvdla/cmake/FindNvdlaCmod.cmake | 75 +++++ models/nvdla/cmake/FindSystemC.cmake | 179 ++++++++++++ models/nvdla/cmake/FindTLM.cmake | 75 +++++ models/nvdla/include/adaptors/gp2str.h | 21 ++ models/nvdla/include/adaptors/gsgp2tlm.h | 45 +++ models/nvdla/include/adaptors/irq_adaptor.h | 44 +++ models/nvdla/include/adaptors/tlm2gsgp.h | 48 ++++ models/nvdla/include/nvdla/IRQ.h | 60 ++++ models/nvdla/include/nvdla/nvdla_top.h | 70 +++++ models/nvdla/misc/FindNVDLA.cmake | 48 ++++ models/nvdla/src/adaptors/gp2str.cpp | 100 +++++++ models/nvdla/src/adaptors/gsgp2tlm.cpp | 75 +++++ models/nvdla/src/adaptors/irq_adaptor.cpp | 55 ++++ models/nvdla/src/adaptors/tlm2gsgp.cpp | 72 +++++ models/nvdla/src/nvdla_top.cpp | 92 +++++++ scripts/build.sh | 5 + scripts/dump_dts.sh | 5 + scripts/run.sh | 4 + src/aarch64_toplevel.cpp | 189 +++++++++++++ tests/hello/Makefile | 10 + tests/hello/aarch64_hello | Bin 0 -> 9646 bytes tests/hello/hello.c | 18 ++ tests/nvdla_bdma_mmio/Makefile | 11 + tests/nvdla_bdma_mmio/aarch64_nvdla_bdma_mmio | Bin 0 -> 14463 bytes tests/nvdla_bdma_mmio/nvdla_bdma_mmio.c | 260 ++++++++++++++++++ tests/socket/Makefile | 13 + tests/socket/client | Bin 0 -> 9154 bytes tests/socket/client.c | 60 ++++ tests/socket/server | Bin 0 -> 14603 bytes tests/socket/server.c | 61 ++++ 58 files changed, 3331 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 README.md create mode 100644 cmake/FindLua.cmake create mode 100644 cmake/FindNvdlaCmod.cmake create mode 100644 cmake/FindSystemC.cmake create mode 100644 cmake/FindTLM.cmake create mode 100644 conf/aarch64_nvdla.lua create mode 100644 conf/aarch64_nvdla_dump_dts.lua create mode 100644 docker/Dockerfile create mode 100755 docker/docker_gen.sh create mode 100755 docker/docker_run.sh create mode 160000 libs/greenlib create mode 100644 libs/log/CMakeLists.txt create mode 100644 libs/log/README.md create mode 100644 libs/log/include/log/log.h create mode 100644 libs/log/src/log.cpp create mode 160000 libs/qbox create mode 160000 libs/tlm2c create mode 160000 models/cpu create mode 160000 models/memory create mode 100644 models/nvdla/CMakeLists.txt create mode 100644 models/nvdla/README.md create mode 100644 models/nvdla/cmake/FindGREENLIB.cmake create mode 100644 models/nvdla/cmake/FindNvdlaCmod.cmake create mode 100644 models/nvdla/cmake/FindSystemC.cmake create mode 100644 models/nvdla/cmake/FindTLM.cmake create mode 100644 models/nvdla/include/adaptors/gp2str.h create mode 100644 models/nvdla/include/adaptors/gsgp2tlm.h create mode 100644 models/nvdla/include/adaptors/irq_adaptor.h create mode 100644 models/nvdla/include/adaptors/tlm2gsgp.h create mode 100644 models/nvdla/include/nvdla/IRQ.h create mode 100644 models/nvdla/include/nvdla/nvdla_top.h create mode 100644 models/nvdla/misc/FindNVDLA.cmake create mode 100644 models/nvdla/src/adaptors/gp2str.cpp create mode 100644 models/nvdla/src/adaptors/gsgp2tlm.cpp create mode 100644 models/nvdla/src/adaptors/irq_adaptor.cpp create mode 100644 models/nvdla/src/adaptors/tlm2gsgp.cpp create mode 100644 models/nvdla/src/nvdla_top.cpp create mode 100755 scripts/build.sh create mode 100755 scripts/dump_dts.sh create mode 100755 scripts/run.sh create mode 100644 src/aarch64_toplevel.cpp create mode 100644 tests/hello/Makefile create mode 100755 tests/hello/aarch64_hello create mode 100644 tests/hello/hello.c create mode 100644 tests/nvdla_bdma_mmio/Makefile create mode 100755 tests/nvdla_bdma_mmio/aarch64_nvdla_bdma_mmio create mode 100644 tests/nvdla_bdma_mmio/nvdla_bdma_mmio.c create mode 100644 tests/socket/Makefile create mode 100755 tests/socket/client create mode 100644 tests/socket/client.c create mode 100755 tests/socket/server create mode 100644 tests/socket/server.c diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..db6e258 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/*README.md +**/*.git* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a67e7c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*~ +CMakeCache.txt +CMakeFiles/ +CPackConfig.cmake +CPackSourceConfig.cmake +Makefile +aarch64_toplevel +build/ +cmake_install.cmake +install_manifest.txt +libs/log.build/ +libs/qbox.build/ +libs/tlm2c.build/ +make.log +models/cpu.build/ +models/memory.build/ +models/nvdla.build/ +images/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..dac4bec --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,7 @@ +before_script: + - export SC_SIGNAL_WRITE_CHECK=DISABLE +variables: + GIT_SUBMODULE_STRATEGY: recursive +Build_Runtests: + script: + - ./scripts/build.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..96c9b55 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,18 @@ +[submodule "libs/tlm2c"] + path = libs/tlm2c + url = https://git.greensocs.com/tlm/tlm2c.git +[submodule "models/cpu"] + path = models/cpu + url = ../simple_cpu.git + branch = nvdla_vp +[submodule "models/memory"] + path = models/memory + url = https://git.greensocs.com/models/simple_memory.git +[submodule "libs/greenlib"] + path = libs/greenlib + url = ../greenlib.git + branch = nvdla_vp +[submodule "libs/qbox"] + path = libs/qbox + url = ../qbox.git + branch = nvdla_vp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c749a0e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,163 @@ +# +# CMakeLists.txt +# +# Copyright (C) 2015, GreenSocs ltd. +# +# Developped by Frederic Konrad +# and Guillaume Delbrgue +# + +cmake_minimum_required(VERSION 2.8) +include(ExternalProject) + +project(NVDLA_VIRTUAL_PLATFORM) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +set(INCLUDE_DIRS include) + +include_directories(${INCLUDE_DIRS}) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSC_INCLUDE_DYNAMIC_PROCESSES -Wall -Werror") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSC_INCLUDE_DYNAMIC_PROCESSES -Wall -Werror -DDEBUG_LOG=1") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DSC_INCLUDE_DYNAMIC_PROCESSES -Wall -Werror") + +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") + +#REQUIRED LIBRARIES. +find_package(SystemC) +if(SystemC_FOUND) + include_directories(${SystemC_INCLUDE_DIRS}) +else() + message( FATAL_ERROR "SystemC library not found." ) +endif() + +find_package(TLM) +if(TLM_FOUND) + include_directories(${TLM_INCLUDE_DIRS}) +else() + message( FATAL_ERROR "TLM library not found." ) +endif() + +find_package(Lua REQUIRED) +if(LUA_FOUND) + include_directories(${LUA_INCLUDE_DIR}) +else() + message( FATAL_ERROR "LUA library not found." ) +endif() + +find_package(NvdlaCmod) +if(NVDLA_CMOD_FOUND) + link_directories(${NVDLA_CMOD_LIBRARY_DIR}) +else() + message( FATAL_ERROR "NVDLA CMOD library not found." ) +endif() + +add_subdirectory(libs/greenlib) +include_directories(libs/greenlib/greencontrol/include + libs/greenlib/greenmemory/include + libs/greenlib/greenscript/include + libs/greenlib/greensignalbus/include + libs/greenlib/greensocket/include + libs/greenlib/greenmessage/include + libs/greenlib/greenrouter/include + libs/greenlib/greenserialsocket/include + libs/greenlib/greensignalsocket/include + libs/greenlib/gsgpsocket/include + libs/greenlib/greenreg/include + libs/greenlib/include +) +link_directories(${CMAKE_SOURCE_DIR}/libs/greenlib/greenreg/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greencontrol/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greenmemory/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greenscript/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greensignalbus/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greensocket/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greenmessage/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greenrouter/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greenserialsocket/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/greensignalsocket/lib + ${CMAKE_SOURCE_DIR}/libs/greenlib/gsgpsocket/lib +) + +set(GREENLIB_FOUND TRUE) +set(GREENLIB_LIBRARY_DIRS ${CMAKE_SOURCE_DIR}/libs/greenlib/greenreg/lib) +set(GREENLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/greenlib/greencontrol/include) + +add_subdirectory(libs/tlm2c libs/tlm2c.build/lib) +include_directories(libs/tlm2c/include) +link_directories(${CMAKE_SOURCE_DIR}/libs/tlm2c.build) +file(COPY libs/tlm2c/include DESTINATION libs/tlm2c.build/) + +set(TLM2C_FOUND TRUE) +set(TLM2C_LIBRARY_DIRS ${CMAKE_SOURCE_DIR}/libs/tlm2c.build) +set(TLM2C_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/tlm2c/include) + +add_subdirectory(libs/log libs/log.build/lib) +include_directories(libs/log/include) +link_directories(${CMAKE_SOURCE_DIR}/libs/log.build) +file(COPY libs/log/include DESTINATION libs/log.build/) + +set(LOG_FOUND TRUE) +set(LOG_LIBRARY_DIRS ${CMAKE_SOURCE_DIR}/libs/log.build) +set(LOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/log/include) + +add_subdirectory(models/cpu models/cpu.build) +include_directories(models/cpu/include) +link_directories(${CMAKE_SOURCE_DIR}/models/cpu.build) + +add_subdirectory(models/memory models/memory.build) +include_directories(models/memory/include) +link_directories(${CMAKE_SOURCE_DIR}/models/memory.build) + +add_subdirectory(models/nvdla models/nvdla.build) +include_directories(models/nvdla/include) +link_directories(${CMAKE_SOURCE_DIR}/models/nvdla.build) + +### QBOX ### +if (CMAKE_BUILD_TYPE MATCHES Debug) + set(QBOX_DEBUG_BUILD --enable-debug) +else () + set(QBOX_DEBUG_BUILD --disable-debug-info) +endif () +ExternalProject_Add(qbox + SOURCE_DIR ${CMAKE_SOURCE_DIR}/libs/qbox + INSTALL_DIR ${CMAKE_SOURCE_DIR}/libs/qbox.build + BINARY_DIR ${CMAKE_SOURCE_DIR}/libs/qbox.build + TMP_DIR ${CMAKE_SOURCE_DIR}/libs/qbox.build/tmp + STAMP_DIR ${CMAKE_SOURCE_DIR}/libs/qbox.build/stampdir + CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/libs/qbox/configure --target-list=aarch64-softmmu --disable-xfsctl ${QBOX_DEBUG_BUILD} --library --qbox --nvdla --with-tlm2c=${CMAKE_SOURCE_DIR}/libs/tlm2c.build --prefix=${CMAKE_SOURCE_DIR}/libs/qbox.build --disable-pie --extra-cflags=-fPIC\ -fpic\ -ftls-model=initial-exec\ -DNVDLA_HW_VERSION=${NVDLA_HW_VERSION} + PREFIX ${CMAKE_SOURCE_DIR}/libs/qbox.build + BUILD_COMMAND $(MAKE) +) +ExternalProject_Add_Step(qbox force-build + DEPENDEES update + DEPENDERS build + ALWAYS 1 +) +add_dependencies(qbox tlm2c) +link_directories(${CMAKE_SOURCE_DIR}/libs/qbox.build/aarch64-softmmu) +install(FILES ${CMAKE_SOURCE_DIR}/libs/qbox.build/aarch64-softmmu/libqbox-nvdla${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION lib) + +### Toplevel ### +add_executable(aarch64_toplevel src/aarch64_toplevel.cpp) +add_dependencies(aarch64_toplevel + simplecpu + qbox + nvdla +) + +target_link_libraries(aarch64_toplevel ${SystemC_LIBRARIES} + ${LUA_LIBRARIES} + qbox-nvdla + greenreg + greenscript + simplecpu + dl + tlm2c + log + nvdla +) +install(TARGETS aarch64_toplevel DESTINATION bin) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f9bb874 --- /dev/null +++ b/LICENSE @@ -0,0 +1,206 @@ +NVIDIA Open NVDLA License and Agreement v1.0 + +NVIDIA's Deep Learning Accelerator ("NVDLA") is a hardware design that +accelerates inferencing in System-on-a-Chip designs. Subject to the terms +and conditions of this Open NVDLA License and Agreement, NVIDIA offers its +NVDLA design on a royalty-free, open-source basis, promoting the adoption of +deep learning inferencing in third-party designs and IoT devices, and +expanding the overall market for AI. + +By exercising the rights granted hereunder, You accept and agree to be bound +by these terms and conditions. You are granted the rights hereunder in +consideration of Your agreement to these terms and conditions. If You do +not agree to these terms and conditions, do not download or use the NVDLA +Specification. + +If You are agreeing to these terms and conditions on behalf of a legal +entity, You represent that You have the legal authority to bind the legal +entity to these terms and conditions. + +In consideration of the mutual covenants contained herein, You agree as +follows: + +1. DEFINITIONS. + +"NVDLA Specification" shall mean and include the design information, code, +and documentation used in designing a deep learning accelerator or creating +a DLA Product, which may include: HDL, netlists, GDSII files, mask works, +architectural descriptions, interface specifications, microcode, software +source code, documentation source, and configuration files. + +"Contributor" shall mean NVIDIA and any owner of a NVDLA Contribution that +NVIDIA has incorporated within the NVDLA Specification. + +"Derivative Work" shall mean any work that is based on (or derived from) +any portion of the NVDLA Specification. For the purposes of this License, +Derivative Works shall not include works that remain separable from, or +merely link (or bind by name) to the interfaces of, any portion of the NVDLA +Specification and Derivative Works thereof. + +"DLA Product" shall mean a semiconductor chip product or portions thereof +designed or manufactured in accordance with a NVDLA Specification or a +Derivative Work, including any semiconductor chip product embodying a mask +work included in a NVDLA Specification or a Derivative Work. + +"NVDLA" means NVIDIA's Deep Learning Accelerator, a hardware design that +accelerates inferencing in System-on-a-Chip designs. + +"NVDLA Contribution" shall mean any work of authorship, design, or +inventorship that is intentionally submitted to NVIDIA for inclusion in the +NVDLA Specification by a person authorized to submit the contribution on +behalf of the owner. + +"NVDLA Patents" shall mean patents that are necessary to practice the NVDLA +Specification and any Derivative Works. + +"NVDLA Patent Rights" shall mean the right to make, have made, use, sell, +offer for sale, and import patents that are necessary to practice the NVDLA +Specification and any Derivative Works. + +"Other NVDLA Rights" includes copyright, design right (whether registered or +unregistered), semiconductor topography (mask work) rights, and database +rights to the NVDLA Specification and any Derivative Work. For the +avoidance of doubt, Other NVDLA Rights does not include patents or +trademarks. + +"License" and "Agreement" shall mean the terms and conditions for use, +reproduction, and distribution as set forth in this document. + +"You" (or "Your") shall mean an individual or Legal Entity agreeing to the +terms and conditions of this License. + +2. LICENSE TO NVDLA PATENTS. + +Subject to the terms and conditions of this License, NVIDIA and each +Contributor hereby grant to You a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this section) +license under the NVDLA Patents to make, have made, use, offer to sell, +sell, import, and otherwise transfer DLA Products and the NVDLA +Specification, where such license applies only to those patent claims +licensable by such Contributor that are necessarily infringed either by (i) +their Contribution(s) alone or (ii) the combination of their NVDLA +Contribution(s) with the portion of the NVDLA Specification to which such +NVDLA Contribution(s) was submitted. + +If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that any portion of the +NVDLA Specification, a NVDLA Contribution incorporated within the NVDLA +Specification, or any portion of a DLA Product directly or contributorily +infringes any patent, then any patent licenses granted to You under this +License and Agreement shall terminate as of the date such litigation is +filed. + +3. LICENSE TO OTHER NVDLA RIGHTS. + +Subject to the terms and conditions of this License, NVIDIA and each +Contributor hereby grant to You a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable license under the Other NVDLA Rights to +reproduce, prepare Derivative Works of, publicly display, publicly perform, +sublicense, and distribute the NVDLA Specification and such Derivative +Works, and to commercially exploit any mask works included in the NVDLA +Specification or such Derivative Works. + +4. REDISTRIBUTION. + +You may reproduce and distribute copies of the NVDLA Specification or +Derivative Works thereof in any medium, with or without modifications, +provided that You meet the following conditions: + + 1. You must give any other recipients of the NVDLA Specification or + Derivative Works a copy of this License and Agreement; and + + 2. You must cause any modified files or other portions of the NVDLA + Specification to carry prominent notices stating that You changed such + files or other portions; and + + 3. You must retain, in any Derivative Works that You distribute, all + notices, including copyright, patent, trademark, and attribution + notices, from the NVDLA Specification, excluding those notices that do + not pertain to any part of the Derivative Works; and + + 4. You may add Your own copyright statement to Your modifications and may + provide additional or different license terms and conditions for use, + reproduction, or distribution of Your modifications, or for any such + Derivative Works as a whole, provided Your use, reproduction, and + distribution of the NVDLA Specification otherwise complies with the + conditions stated in this License and Agreement. + +5. SUBMISSION OF NVDLA CONTRIBUTIONS. + +You are not required to submit contributions to the NVDLA Specification, but +you may do so at your discretion. Unless You explicitly state otherwise, +any NVDLA Contribution intentionally submitted by you to NVIDIA for +inclusion in the NVDLA Specification shall be provided under the terms and +conditions of this License and Agreement, without any additional terms or +conditions. NVIDIA is under no obligation to consider, review, or +incorporate any NVDLA Contribution into any version of the NVDLA +Specification + +6. TRADEMARKS. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names ("Marks") of NVIDIA or any Contributor, +except as required for reasonable and customary use in describing the origin +of the NVDLA Specification. For DLA Products that are compatible with NVDLA +interfaces, NVIDIA and You may mutually agree on certain marketing +activities and branding involving the use of NVIDIA's Marks under separate +agreement and/or supplemental terms. + +7. NO IMPLIED RIGHTS. + +Except for the licenses expressly set forth herein, no other licenses are +granted hereunder whether by implication, estoppel or otherwise. This +License and Agreement provides you with no implied rights or licenses to the +intellectual property of NVIDIA or any Contributor. + +8. DISCLAIMER OF WARRANTY. + +Unless required by applicable law or agreed to in writing, NVIDIA provides +the NVDLA Specification (and each Contributor provides its NVDLA +Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied, including, without limitation, any +warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or +FITNESS FOR A PARTICULAR PURPOSE. + +You are solely responsible for determining the appropriateness of Your use +of NVDLA, the NVDLA Specification, or any DLA Product, and You assume all +associated risks, including but not limited to the risks and costs of damage +to or loss of data, programs or equipment, and unavailability or +interruption of operations. You agree to comply with all regulations and +safety standards applicable to Your use of NVDLA and the NVDLA +Specification. You acknowledge that the NVDLA and NVDLA Specification +provided to You under this Agreement are not intended to be used, without +additional safeguards and/or process technology, to control or operate +machines that can lead to personal injury, death, or severe physical or +environmental damage, and if You make, use, or sell such machines, You agree +to assume all liability therefor and will comply with all applicable +safety-related laws, regulations, and best industry practices. + +9. LIMITATION OF LIABILITY. + +In no event and under no legal theory, whether in tort (including +negligence), contract, or otherwise, shall NVIDIA or any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a result of +this License and Agreement, or arising out of the use or inability to use +any DLA Product (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all other +commercial damages or losses). + +10. WAIVER AND INDEMNITY. + +You agree to waive any and all claims against NVIDIA and each Contributor +arising from Your use of NVDLA or the NVDLA Specification. If Your use of +the NVDLA, the NVDLA Specification, or any portion thereof, results in any +liabilities, demands, damages, expenses or losses arising from such use, +including any damages from products based on, or resulting from, Your use of +NVDLA or the NVDLA Specification licensed under this Agreement, You shall +indemnify and hold harmless NVIDIA and each Contributor to the extent +permitted by law. In addition, You agree to defend, indemnify, and hold +NVIDIA and each Contributor harmless from any claim brought by a third party +alleging any defect in the design, manufacture, or any Product which You +make, have made, sell, or distribute pursuant to this Agreement. Your sole +remedy for any such matter shall be the immediate, unilateral termination of +this Agreement. + +END OF OPEN NVDLA LICENSE AND AGREEMENT diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ce4795 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# NVDLA Open Source Virtual Platform +--- + +## NVDLA + +The NVIDIA Deep Learning Accelerator (NVDLA) is a free and open architecture that promotes a standard way to design deep learning inference accelerators. With its modular architecture, NVDLA is scalable, highly configurable, and designed to simplify integration and portability. Learn more about NVDLA on the project web page. + + + +## Online Documentation + +You can find the latest NVDLA Virtual Platform documentation [here](http://nvdla.org/vp.html). This README file contains only basic information. + +## Download +Git clone the repository and update the submodules. After cloning the repository, run the following command to update the submodule: +```sh +git submodule update --init --recursive +``` + +## Build steps + +***Download and build the NVDLA CMOD*** + +Please refer to [Integrator's Manual](http://nvdla.org/integration_guide.html) for details on building the hardware tree, and make sure the required tools listed in [Environment Setup](http://nvdla.org/integration_guide.html#environment-setup) are installed first. + +```sh +$ git clone https://github.com/nvdla/hw.git +$ cd hw +$ make +$ tools/bin/tmake -build cmod_top +``` + +The header files and library will be generated in ```hw/outdir//cmod/release```. + +***Install required tools/libraries*** + +```sh +$ sudo apt-get install g++ cmake libboost-dev python-dev libglib2.0-dev libpixman-1-dev liblua5.2-dev swig libcap-dev libattr1-dev +``` + +***Download and install SystemC 2.3.0*** + +```sh +$ sudo wget -O systemc-2.3.0a.tar.gz http://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.0a.tar.gz +$ tar -xzvf systemc-2.3.0a.tar.gz +$ cd systemc-2.3.0a +$ sudo mkdir -p /usr/local/systemc-2.3.0/ +$ mkdir objdir +$ cd objdir +$ ../configure --prefix=/usr/local/systemc-2.3.0 +$ make +$ sudo make install +``` + +***Cmake build*** + +```sh +$ cmake -DCMAKE_INSTALL_PREFIX=[install dir] -DSYSTEMC_PREFIX=[systemc prefix] -DNVDLA_HW_PREFIX=[nvdla_hw prefix] -DNVDLA_HW_PROJECT=[nvdla_hw project name] +``` + +```install dir``` is the installation path, ```systemc prefix``` is the SystemC installation directory, ```nvdla_hw prefix``` is the local NVDLA HW repository, and ```nvdla_hw project name``` is the NVDLA HW project name. Example: + +```sh +$ cmake -DCMAKE_INSTALL_PREFIX=build -DSYSTEMC_PREFIX=/usr/local/systemc-2.3.0/ -DNVDLA_HW_PREFIX=/usr/local/nvdla/hw -DNVDLA_HW_PROJECT=nv_full +``` + +***Compile*** + +```sh +$ make +``` + +***Installation*** + +```sh +$ make install +``` + +## Run + +```sh +$ export SC_SIGNAL_WRITE_CHECK=DISABLE +$ ./build/bin/aarch64_toplevel --conf [platform.lua] +``` + +```platform.lua``` is the path to your platform conf file. A demo example is in ```conf/aarch64_nvdla.lua```. You will need a linux kernel image to run the NVDLA software, please refer to [here](http://nvdla.org/vp.html#building-linux-kernel-for-nvdla-virtual-simulator) on how to build a kernel image for NVDLA. diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake new file mode 100644 index 0000000..ef1be78 --- /dev/null +++ b/cmake/FindLua.cmake @@ -0,0 +1,117 @@ +# locate Lua library +# This module defines +# LUA_EXECUTABLE, if found +# LUA_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# Modified to support Lua 5.2 by LuaDist 2012 +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) +# +# The required version of Lua can be specified using the +# standard syntax, e.g. FIND_PACKAGE(Lua 5.1) +# Otherwise the module will search for any available Lua implementation + +# Always search for non-versioned lua first (recommended) +SET(_POSSIBLE_LUA_INCLUDE include include/lua) +SET(_POSSIBLE_LUA_EXECUTABLE lua) +SET(_POSSIBLE_LUA_LIBRARY lua) + +# Determine possible naming suffixes (there is no standard for this) +IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") +ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1") +ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + +# Set up possible search names and locations +FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) + LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}") + LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}") + LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") +ENDFOREACH(_SUFFIX) + +# Find the lua executable +FIND_PROGRAM(LUA_EXECUTABLE + NAMES ${_POSSIBLE_LUA_EXECUTABLE} +) + +# Find the lua header +FIND_PATH(LUA_INCLUDE_DIR lua.h + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE} + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Find the lua library +FIND_LIBRARY(LUA_LIBRARY + NAMES ${_POSSIBLE_LUA_LIBRARY} + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +IF(LUA_LIBRARY) + # include the math library for Unix + IF(UNIX AND NOT APPLE) + FIND_LIBRARY(LUA_MATH_LIBRARY m) + SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + ELSE(UNIX AND NOT APPLE) + SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + ENDIF(UNIX AND NOT APPLE) +ENDIF(LUA_LIBRARY) + +# Determine Lua version +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + +INCLUDE(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE) diff --git a/cmake/FindNvdlaCmod.cmake b/cmake/FindNvdlaCmod.cmake new file mode 100644 index 0000000..5eb82c4 --- /dev/null +++ b/cmake/FindNvdlaCmod.cmake @@ -0,0 +1,77 @@ +# - Find NvdlaCmod +# This module finds if NVDLA CMOD is built and determines where the +# include files and libraries are. +# + +MESSAGE(STATUS "Searching for NVDLA CMOD") + +# The HINTS option should only be used for values computed from the system. +SET(_NVDLA_CMOD_HINTS + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/include + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib-linux + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib-linux64 + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib-macos + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/include + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib-linux + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib-linux64 + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib-macos + ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib-linux + ${CMAKE_INSTALL_PREFIX}/lib-linux64 + ${CMAKE_INSTALL_PREFIX}/lib-macos +) + +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +SET(_NVDLA_CMOD_PATHS + /usr/include + /usr/lib + /usr/lib-linux + /usr/lib-linux64 + /usr/lib-macos + /usr/local/lib + /usr/local/lib-linux + /usr/local/lib-linux64 + /usr/local/lib-macos +) + +FIND_FILE(NVDLA_HW_VERSION_FILE + NAMES VERSION + HINTS ${NVDLA_HW_PREFIX} + PATHS ${NVDLA_HW_PREFIX} +) + +FILE(READ ${NVDLA_HW_VERSION_FILE} NVDLA_HW_VERSION) +STRING(STRIP ${NVDLA_HW_VERSION} NVDLA_HW_VERSION) +STRING(TOLOWER ${NVDLA_HW_VERSION} NVDLA_HW_VERSION) + +FIND_PATH(NVDLA_CMOD_INCLUDE_DIR + NAMES NV_nvdla.h + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +find_library(NVDLA_CMOD_LIBRARY + NAMES nvdla_cmod + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +FIND_PATH(NVDLA_CMOD_LIBRARY_DIR + NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}nvdla_cmod${CMAKE_SHARED_LIBRARY_SUFFIX} + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +if("${NVDLA_CMOD_INCLUDE_DIR}" MATCHES "NVDLA_CMOD_INCLUDE_DIR-NOTFOUND") + SET(NVDLA_CMOD_FOUND FALSE) +else("${NVDLA_CMOD_INCLUDE_DIR}" MATCHES "NVDLA_CMOD_INCLUDE_DIR-NOTFOUND") + SET(NVDLA_CMOD_FOUND TRUE) + MESSAGE(STATUS "NVDLA HW VERSION = ${NVDLA_HW_VERSION}") + MESSAGE(STATUS "NVDLA CMOD include directory = ${NVDLA_CMOD_INCLUDE_DIR}") + MESSAGE(STATUS "NVDLA CMOD library directory = ${NVDLA_CMOD_LIBRARY_DIR}") + MESSAGE(STATUS "NVDLA CMOD library = ${NVDLA_CMOD_LIBRARY}") +endif("${NVDLA_CMOD_INCLUDE_DIR}" MATCHES "NVDLA_CMOD_INCLUDE_DIR-NOTFOUND") diff --git a/cmake/FindSystemC.cmake b/cmake/FindSystemC.cmake new file mode 100644 index 0000000..f12e55d --- /dev/null +++ b/cmake/FindSystemC.cmake @@ -0,0 +1,114 @@ +# - Find SystemC +# This module finds if SystemC is installed and determines where the +# include files and libraries are. This code sets the following +# variables: (from kernel/sc_ver.h) +# +# SystemC_VERSION_MAJOR = The major version of the package found. +# SystemC_VERSION_MINOR = The minor version of the package found. +# SystemC_VERSION_REV = The patch version of the package found. +# SystemC_VERSION = This is set to: $major.$minor.$rev +# +# The minimum required version of SystemC can be specified using the +# standard CMake syntax, e.g. FIND_PACKAGE(SystemC 2.2) +# +# For these components the following variables are set: +# +# SystemC_INCLUDE_DIRS - Full paths to all include dirs. +# SystemC_LIBRARIES - Full paths to all libraries. +# +# Example Usages: +# FIND_PACKAGE(SystemC) +# FIND_PACKAGE(SystemC 2.3) +# + +#============================================================================= +# Copyright 2012 GreenSocs +# +#============================================================================= + +message(STATUS "Searching for SystemC") + +# The HINTS option should only be used for values computed from the system. +SET(_SYSTEMC_HINTS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SystemC\\2.2;SystemcHome]/include" + ${SYSTEMC_PREFIX}/include + ${SYSTEMC_PREFIX}/lib + ${SYSTEMC_PREFIX}/lib-linux + ${SYSTEMC_PREFIX}/lib-linux64 + ${SYSTEMC_PREFIX}/lib-macos + $ENV{SYSTEMC_PREFIX}/include + $ENV{SYSTEMC_PREFIX}/lib + $ENV{SYSTEMC_PREFIX}/lib-linux + $ENV{SYSTEMC_PREFIX}/lib-linux64 + $ENV{SYSTEMC_PREFIX}/lib-macos + ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib-linux + ${CMAKE_INSTALL_PREFIX}/lib-linux64 + ${CMAKE_INSTALL_PREFIX}/lib-macos + ) +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +SET(_SYSTEMC_PATHS + /usr/include/systemc + /usr/lib + /usr/lib-linux + /usr/lib-linux64 + /usr/lib-macos + /usr/local/lib + /usr/local/lib-linux + /usr/local/lib-linux64 + /usr/local/lib-macos + ) +FIND_FILE(_SYSTEMC_VERSION_FILE + NAMES sc_ver.h + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS} + PATH_SUFFIXES sysc/kernel +) + +# SystemC < 2.3.1 +EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 7 " + OUTPUT_VARIABLE SystemC_MAJOR) +EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 8 " + OUTPUT_VARIABLE SystemC_MINOR) +EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 9 " + OUTPUT_VARIABLE SystemC_REV) + +# SystemC >= 2.3.1 +if("${SystemC_MAJOR}" MATCHES "") +EXEC_PROGRAM("grep '#define SC_VERSION_MAJOR' ${_SYSTEMC_VERSION_FILE} | cut -d ' ' -f 8" + OUTPUT_VARIABLE SystemC_MAJOR) +EXEC_PROGRAM("grep '#define SC_VERSION_MINOR' ${_SYSTEMC_VERSION_FILE} | cut -d ' ' -f 8" + OUTPUT_VARIABLE SystemC_MINOR) +EXEC_PROGRAM("grep '#define SC_VERSION_PATCH' ${_SYSTEMC_VERSION_FILE} | cut -d ' ' -f 8" + OUTPUT_VARIABLE SystemC_REV) +endif("${SystemC_MAJOR}" MATCHES "") + +set(SystemC_VERSION ${SystemC_MAJOR}.${SystemC_MINOR}.${SystemC_REV}) + +if("${SystemC_MAJOR}" MATCHES "2") + set(SystemC_FOUND TRUE) +endif("${SystemC_MAJOR}" MATCHES "2") + +message(STATUS "SystemC version = ${SystemC_VERSION}") + +FIND_PATH(SystemC_INCLUDE_DIRS + NAMES systemc.h + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS} +) + +find_library(SystemC_LIBRARIES + NAMES systemc + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS} +) + +FIND_PATH(SystemC_LIBRARY_DIRS + NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}systemc${CMAKE_SHARED_LIBRARY_SUFFIX} + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS} +) + +message(STATUS "SystemC library = ${SystemC_LIBRARIES}") diff --git a/cmake/FindTLM.cmake b/cmake/FindTLM.cmake new file mode 100644 index 0000000..765b2fa --- /dev/null +++ b/cmake/FindTLM.cmake @@ -0,0 +1,85 @@ +# - Find TLM +# This module finds if TLM is installed and determines where the +# include files and libraries are. This code sets the following +# variables: (from kernel/sc_ver.h) +# +# TLM_VERSION_STRING = Version of the package found, eg. "2.2.0" +# TLM_VERSION_MAJOR = The major version of the package found. +# TLM_VERSION_MINOR = The minor version of the package found. +# TLM_VERSION_PATCH = The patch version of the package found. +# TLM_VERSION_DATE = The date of release (from TLM_VERSION) +# TLM_VERSION = This is set to: $major.$minor.$patch +# +# The minimum required version of TLM can be specified using the +# standard CMake syntax, e.g. FIND_PACKAGE(TLM 2.2) +# +# For these components the following variables are set: +# +# TLM_FOUND - TRUE if all components are found. +# TLM_INCLUDE_DIRS - Full paths to all include dirs. +# TLM_LIBRARIES - Full paths to all libraries. +# TLM__FOUND - TRUE if is found. +# +# Example Usages: +# FIND_PACKAGE(TLM) +# FIND_PACKAGE(TLM 2.3) +# + +#============================================================================= +# Copyright 2012 GreenSocs +# +#============================================================================= + +message(STATUS "Searching for TLM") + +# The HINTS option should only be used for values computed from the system. +SET(_TLM_HINTS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\TLM\\2.2;TLMHome]/include" + $ENV{TLM_HOME} + ${SYSTEMC_PREFIX}/include + ${SYSTEMC_PREFIX}/lib + ${SYSTEMC_PREFIX}/lib-linux + ${SYSTEMC_PREFIX}/lib-linux64 + ${SYSTEMC_PREFIX}/lib-macos + $ENV{SYSTEMC_PREFIX}/include + $ENV{SYSTEMC_PREFIX}/lib + $ENV{SYSTEMC_PREFIX}/lib-linux + $ENV{SYSTEMC_PREFIX}/lib-linux64 + $ENV{SYSTEMC_PREFIX}/lib-macos + ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib-linux + ${CMAKE_INSTALL_PREFIX}/lib-linux64 + ${CMAKE_INSTALL_PREFIX}/lib-macos + ) +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +SET(_TLM_PATHS + /usr/include/TLM + /usr/include/systemc + /usr/lib + /usr/lib-linux + /usr/lib-linux64 + /usr/lib-macos + /usr/local/lib + /usr/local/lib-linux + /usr/local/lib-linux64 + /usr/local/lib-macos + ) + +FIND_PATH(TLM_INCLUDE_DIRS + NAMES tlm.h + HINTS ${_TLM_HINTS} + PATHS ${_TLM_PATHS} + PATH_SUFFIXES include/tlm +) + +EXEC_PROGRAM("ls ${TLM_INCLUDE_DIRS}/tlm.h" + RETURN_VALUE ret) + +if("${ret}" MATCHES "0") + set(TLM_FOUND TRUE) +endif("${ret}" MATCHES "0") + +message(STATUS "TLM library = ${TLM_INCLUDE_DIRS}/tlm.h") + diff --git a/conf/aarch64_nvdla.lua b/conf/aarch64_nvdla.lua new file mode 100644 index 0000000..203f504 --- /dev/null +++ b/conf/aarch64_nvdla.lua @@ -0,0 +1,20 @@ +CPU = { + library = "libqbox-nvdla.so", + extra_arguments = "-machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 1024 -kernel images/linux-4.13.3/Image --append \"root=/dev/vda\" -drive file=images/linux-4.13.3/rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -fsdev local,id=r,path=.,security_model=none -device virtio-9p-device,fsdev=r,mount_tag=r -netdev user,id=user0,hostfwd=tcp::6666-:6666,hostfwd=tcp::6667-:22 -device virtio-net-device,netdev=user0" +} + +ram = { + size = 1048576, + target_port = { + base_addr = 0xc0000000, + high_addr = 0xffffffff + } +} + +nvdla = { + irq_number = 176, + csb_port = { + base_addr = 0x10200000, + high_addr = 0x1021ffff + } +} diff --git a/conf/aarch64_nvdla_dump_dts.lua b/conf/aarch64_nvdla_dump_dts.lua new file mode 100644 index 0000000..24ba3e1 --- /dev/null +++ b/conf/aarch64_nvdla_dump_dts.lua @@ -0,0 +1,20 @@ +CPU = { + library = "libqbox-nvdla.so", + extra_arguments = "-machine virt -cpu cortex-a57 -machine dumpdtb=virt.dtb -nographic -smp 1 -m 1024 -kernel images/linux-4.13.3/Image --append \"root=/dev/vda\" -drive file=images/linux-4.13.3/rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -fsdev local,id=r,path=.,security_model=none -device virtio-9p-device,fsdev=r,mount_tag=r -netdev user,id=user0,hostfwd=tcp::6666-:6666 -device virtio-net-device,netdev=user0" +} + +ram = { + size = 1048576, + target_port = { + base_addr = 0xc0000000, + high_addr = 0xffffffff + } +} + +nvdla = { + irq_number = 176, + csb_port = { + base_addr = 0x10200000, + high_addr = 0x1021ffff + } +} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..015c74e --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:14.04 + +RUN apt-get update && apt-get install -y --force-yes \ +g++ cmake libboost-dev python-dev libglib2.0-dev libpixman-1-dev liblua5.2-dev swig libcap-dev git vim libattr1-dev wget \ +&& rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /usr/src/systemc-2.3.0a +WORKDIR /usr/src/systemc-2.3.0a + +RUN wget -O systemc-2.3.0a.tar.gz http://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.0a.tar.gz \ +&& tar xzvf systemc-2.3.0a.tar.gz + +RUN cd /usr/src/systemc-2.3.0a/systemc-2.3.0a \ +&& ls \ +&& mkdir -p /usr/local/systemc-2.3.0/ \ +&& mkdir objdir \ +&& cd objdir \ +&& ../configure --prefix=/usr/local/systemc-2.3.0 \ +&& make \ +&& make install + +RUN mkdir -p /usr/local/vp-build +COPY ./vp-build /usr/local/vp-build + +WORKDIR /usr/local/vp-build \ No newline at end of file diff --git a/docker/docker_gen.sh b/docker/docker_gen.sh new file mode 100755 index 0000000..1826d39 --- /dev/null +++ b/docker/docker_gen.sh @@ -0,0 +1,66 @@ +#! /bin/bash + +docker_dns="/etc/docker/daemon.json" +if sudo test -f $docker_dns ; then + echo "File $docker_dns exists... skip to update the script, please make sure the DNS ip works fine" +else + echo "File $docker_dns does not exist." + sudo touch $docker_dns + sudo chmod 755 $docker_dns + echo "Create $docker_dns" + dns_ipv4s=`nmcli device list | grep 'IP4.DNS' | perl -pe 's/IP4\.DNS\[\d*\]\:\s*//g'` + dns="\"dns\": []" + for dns_ipv4 in $dns_ipv4s; + do dns=`echo $dns | perl -pe 's/\]/\"'$dns_ipv4'\"\, \]/g'`; + done + dns=`echo $dns | perl -pe 's/\, \]/\]\n/g'` + echo $dns + echo "{" | sudo tee -a $docker_dns > /dev/null + echo $dns | sudo tee -a $docker_dns > /dev/null + echo "}" | sudo tee -a $docker_dns > /dev/null + sudo service docker restart +fi + +host_vp_build="/usr/local/vp-build" +if sudo test -d $host_vp_build ; then + echo "File $host_vp_build exists... Remove it" + sudo rm -rf $host_vp_build + echo "Remove Done" +fi + +top_path=$PWD +echo "Copy local source code to $host_vp_build ..." +sudo mkdir -p $host_vp_build +sudo cp -rf . $host_vp_build +echo "Find the relative path" +relative=$(perl -MFile::Spec -e 'print File::Spec->abs2rel("'$host_vp_build'","'$PWD'")') +echo "Relative path is $relative" +echo "Build source code in $host_vp_build ..." +sudo chmod -R 777 $host_vp_build +cd $host_vp_build +./scripts/build.sh +echo "Build source Done" + +cd $top_path +sudo mkdir -p ./vp-build +sudo mkdir -p ./vp-build/build +sudo mkdir -p ./vp-build/images +sudo mkdir -p ./vp-build/libs/qbox.build/share + +echo "Copy back files to $top_path" +sudo cp -rf $host_vp_build/build/bin $top_path/vp-build/build/ +sudo cp -rf $host_vp_build/build/lib $top_path/vp-build/build/ +sudo cp -rf $host_vp_build/images/linux-4.13.3 $top_path/vp-build/images/ +sudo cp -rf $host_vp_build/conf $top_path/vp-build/ +sudo cp -rf $host_vp_build/scripts $top_path/vp-build/ +sudo cp -rf $host_vp_build/libs/qbox.build/share/qemu $top_path/vp-build/libs/qbox.build/share/ + +sudo docker build -t vp/ubuntu14.04:1.0 -f ./docker/Dockerfile . +sudo docker save vp/ubuntu14.04:1.0 > ./docker/ubuntu_vp.tar +echo "Docker Image is created as ./docker/ubuntu_vp.tar" +echo "Remove Directory $host_vp_build ..." +sudo rm -rf $host_vp_build +echo "Remove Directory $host_vp_build Done" +echo "Remove Directory $top_path/vp-build ..." +sudo rm -rf $top_path/vp-build +echo "Remove Directory $top_path/vp-build Done" \ No newline at end of file diff --git a/docker/docker_run.sh b/docker/docker_run.sh new file mode 100755 index 0000000..de09f3b --- /dev/null +++ b/docker/docker_run.sh @@ -0,0 +1,19 @@ +#! /bin/bash + +if [ "$1" == "" ] ; +then + echo "No docker image specified" + echo "Usage: $0 [DockerImagePath]" + exit +else + echo "Using $1 docker image" +fi +docker_img=$1 +if [ -f "$docker_img" ] ; +then + sudo docker load -i $docker_img + sudo docker run -it -v /home:/home vp/ubuntu14.04:1.0 +else + echo "$docker_img is not valid" + exit +fi \ No newline at end of file diff --git a/libs/greenlib b/libs/greenlib new file mode 160000 index 0000000..fb0225b --- /dev/null +++ b/libs/greenlib @@ -0,0 +1 @@ +Subproject commit fb0225bdea32439f5a0a4045189a07ba24e6c347 diff --git a/libs/log/CMakeLists.txt b/libs/log/CMakeLists.txt new file mode 100644 index 0000000..4d39f73 --- /dev/null +++ b/libs/log/CMakeLists.txt @@ -0,0 +1,78 @@ +# +# CMakeLists.txt +# +# Copyright (C) 2014, GreenSocs ltd. +# +# Developped by Konrad Frederic +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# Linking GreenSocs code, statically or dynamically with other modules +# is making a combined work based on GreenSocs code. Thus, the terms and +# conditions of the GNU General Public License cover the whole +# combination. +# +# In addition, as a special exception, the copyright holders, GreenSocs +# Ltd, give you permission to combine GreenSocs code with free software +# programs or libraries that are released under the GNU LGPL, under the +# OSCI license, under the OCP TLM Kit Research License Agreement or +# under the OVP evaluation license.You may copy and distribute such a +# system following the terms of the GNU GPL and the licenses of the +# other code concerned. +# +# Note that people who make modified versions of GreenSocs code are not +# obligated to grant this special exception for their modified versions; +# it is their choice whether to do so. The GNU General Public License +# gives permission to release a modified version without this exception; +# this exception also makes it possible to release a modified version +# which carries forward this exception. + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(LOG) + +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +FIND_PACKAGE(SystemC) +if(SystemC_FOUND) + INCLUDE_DIRECTORIES(${SystemC_INCLUDE_DIRS}) +else() + MESSAGE(FATAL_ERROR "SystemC library not found.") +endif() + +set (INCLUDE_DIRS include) + +INCLUDE_DIRECTORIES(${INCLUDE_DIRS}) + +set(CMAKE_CXX_FLAGS "-Wall -Werror -pedantic -O2 -DSC_INCLUDE_DYNAMIC_PROCESSES -Wp,-w -std=c++11") + +if(NOT MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +endif() + +add_library(log SHARED + src/log.cpp +) + +# Installation paths +INSTALL(DIRECTORY include/log + DESTINATION include + PATTERN "*~" EXCLUDE +) +# Not sure it's the right destination? Maybe we want lib64 in case of 64bits? +INSTALL(TARGETS log DESTINATION lib) + +# Make tests +# ENABLE_TESTING() +# ADD_SUBDIRECTORY(tests) + diff --git a/libs/log/README.md b/libs/log/README.md new file mode 100644 index 0000000..384dc04 --- /dev/null +++ b/libs/log/README.md @@ -0,0 +1,74 @@ +# Standard log print in VP (virtual platform) + +## Introduction +The log print is based sc_report API in systemc.There are four standard APIs from sc_report +> SC_REPORT_INFO +> SC_REPORT_WARNING +> SC_REPORT_ERROR +> SC_REPORT_FATAL + +Each API has different actions when called. + +For example, *SC_REPORT_FATAL* will display log info and call *sc_abort* and *SC_REPORT_INFO* just display the log info. At most time, we use *SC_REPORT_INFO* and there are different verbosity levels in it. +> SC_NONE = 0, +> SC_LOW = 100, +> SC_MEDIUM = 200, +> SC_HIGH = 300, +> SC_FULL = 400, +> SC_DEBUG = 500 + + The default level is ***SC_MEDIUM*** which means *SC_HIGH/SC_FULL/SC_DEBUG* will not display in default configuration. + + The log print can be controlled by two ways. + +> 1. ENV variable "SC_LOG" +> 2. Command line -s/--sc_log + +***The final controlled string will use the value from the env variable if the control string is in both places.*** + +## Control string usage: + + "outfile:;verbosity_level:;:" + : log output file name -- Log file name string + : info verbosity -- sc_none/sc_low/sc_medium/sc_high/sc_full/sc_debug + : message string specified in sc_report. + :sc report level -- info/warning/error/fatal/enable/disable + +## Example for control string format: + + [outfile:sc_log_file;verbosity_level:sc_debug;McAdaptor:enable] + outfile: sc_log_file -- SC log will output to file sc_log_file. + verbosity_level:sc_debug -- All sc_info report will display. + McAdaptor: enable -- All report level can display with msg string "McAdaptor" + + *The control string can be set by ENV variable "SC_LOG"* + + In bash shell +> export SC_LOG="outfile:sc_log_file;verbosity_level:sc_debug;McAdaptor:enable" + + In tcsh shell + +>setenv SC_LOG "outfile:sc_log_file;verbosity_level:sc_debug;McAdaptor:enable" + +It also can be set from command line: + +> ./build/bin/aarch64_toplevel -c conf/aarch64_bare_mod.lua -s "outfile:sc_log_file;verbosity_level:sc_debug;McAdaptor:enable" + + In McAdaptor.cpp + We can display some log with: + + SC_REPORT_INFO_VERB("McAdaptor", "mc_socket created", SC_DEBUG); + + And the log will be like: + +> Info: McAdaptor: mc_socket created + + Check the sc_log_file: +> 0 s: Info: McAdaptor: mc_socket created + + If we need to **disable** the log, there are some ways to use. +> 1. McAdaptor:disable -- disable all the log with "McAdaptor" +> 2. McAdaptor:warning -- raise the report level to SC_WARNING, so the SC_INFO will not enable +> 3. verbosity_level:sc_full -- raise the info level to sc_full, so SC_INFO with sc_full level will not enable + + \ No newline at end of file diff --git a/libs/log/include/log/log.h b/libs/log/include/log/log.h new file mode 100644 index 0000000..31dcb03 --- /dev/null +++ b/libs/log/include/log/log.h @@ -0,0 +1,18 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: log.h + +#ifndef __LOG_H_ +#define __LOG_H_ + +#include + +void log_parse(const std::string &s); + +#endif diff --git a/libs/log/src/log.cpp b/libs/log/src/log.cpp new file mode 100644 index 0000000..84536e8 --- /dev/null +++ b/libs/log/src/log.cpp @@ -0,0 +1,214 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: log.cpp + +#include "log/log.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define SC_ACTION_ENABLE (SC_LOG | SC_DISPLAY) +#define SC_ACTION_DISABLE (SC_DO_NOTHING) + +const char PCI_RPT_PROTOCOL_READ_RETRY[] = "PCI Read Retry"; + +using namespace std; +template +static void split(const string& str, Container& cont, char delim) +{ + stringstream ss(str); + string token; + while (getline(ss, token, delim)) { + cont.push_back(token); + } +} + +static string trim(const string &s) +{ + string::const_iterator it = s.begin(); + while (it != s.end() && isspace(*it)) + it++; + + string::const_reverse_iterator rit = s.rbegin(); + while (rit.base() != it && isspace(*rit)) + rit++; + + return string(it, rit.base()); +} + +static void set_sc_report(const string &msg, const string &level, int t) +{ + const char *msg_char = msg.c_str(); + + if (0 == msg.compare("outfile")) + { + if(3 == t) { + const char *file_name = level.c_str(); + sc_report_handler::set_log_file_name(file_name); + cout << "Set SC LOG file to " << file_name << endl; + } else if(1 == t) { + const char file_name[] = "outfile"; + sc_report_handler::set_log_file_name(file_name); + cout << "Set SC LOG file to default " << file_name << endl; + } else { + cout << "Error: Should not come here" << endl; + } + + return; + } + + if (0 == msg.compare("verbosity_level")) + { + int verbosity_lvl = -1; + if (0 == level.compare("sc_none")) + verbosity_lvl = SC_NONE; + if (0 == level.compare("sc_low")) + verbosity_lvl = SC_LOW; + if (0 == level.compare("sc_medium")) + verbosity_lvl = SC_MEDIUM; + if (0 == level.compare("sc_high")) + verbosity_lvl = SC_HIGH; + if (0 == level.compare("sc_full")) + verbosity_lvl = SC_FULL; + if (0 == level.compare("sc_debug")) + verbosity_lvl = SC_DEBUG; + if (-1 == verbosity_lvl) + { + cout << "Invalid debug verbosity " << level << " ...Ignore it" << endl; + return; + } + sc_report_handler::set_verbosity_level(verbosity_lvl); + cout << "Set debug verbosity to " << level << endl; + + return; + } + int report_lvl = -1; + if (0 == level.compare("info")) + report_lvl = SC_INFO; + if (0 == level.compare("warning")) + report_lvl = SC_WARNING; + if (0 == level.compare("error")) + report_lvl = SC_ERROR; + if (0 == level.compare("fatal")) + report_lvl = SC_FATAL; + if (0 == level.compare("enable")) + report_lvl = 4; + if (0 == level.compare("disable")) + report_lvl = 5; + + if (-1 == report_lvl) + { + cout << "Invalid report level " << level << " ...Ignore it" << endl; + return; + } + + int sc_actions[4] = {0}; + sc_actions[0] = (report_lvl <= SC_INFO)?SC_DEFAULT_INFO_ACTIONS:SC_ACTION_DISABLE; + sc_actions[1] = (report_lvl <= SC_WARNING)?SC_DEFAULT_WARNING_ACTIONS:SC_ACTION_DISABLE; + sc_actions[2] = (report_lvl <= SC_ERROR)?SC_DEFAULT_ERROR_ACTIONS:SC_ACTION_DISABLE; + sc_actions[3] = (report_lvl <= SC_FATAL)?SC_DEFAULT_FATAL_ACTIONS:SC_ACTION_DISABLE; + + if (4 == report_lvl) { + sc_actions[0] = SC_DEFAULT_INFO_ACTIONS; + sc_actions[1] = SC_DEFAULT_WARNING_ACTIONS; + sc_actions[2] = SC_DEFAULT_ERROR_ACTIONS; + sc_actions[3] = SC_DEFAULT_FATAL_ACTIONS; + } + if (5 == report_lvl) { + sc_actions[0] = SC_ACTION_DISABLE; + sc_actions[1] = SC_ACTION_DISABLE; + sc_actions[2] = SC_ACTION_DISABLE; + sc_actions[3] = SC_ACTION_DISABLE; + } + + switch(t){ + case 0: + case 1: + cout << "Error: Invalid control string. Should not come here" << endl; + break; + case 2: + sc_report_handler::set_actions(SC_INFO, sc_actions[0]); + sc_report_handler::set_actions(SC_WARNING, sc_actions[1]); + sc_report_handler::set_actions(SC_ERROR, sc_actions[2]); + sc_report_handler::set_actions(SC_FATAL, sc_actions[3]); + break; + case 3: + sc_report_handler::set_actions(msg_char, SC_INFO, sc_actions[0]); + sc_report_handler::set_actions(msg_char, SC_WARNING, sc_actions[1]); + sc_report_handler::set_actions(msg_char, SC_ERROR, sc_actions[2]); + sc_report_handler::set_actions(msg_char, SC_FATAL, sc_actions[3]); + break; + } +} + +void log_parse(const string &s) +{ + if (s.empty()) + { + cout << "Warning: No SC_LOG env Here" << endl; + return; + } + + cout << "sc_log control string: [" << s << "]" << endl; + vector infos; + split(s, infos, ';'); + for (auto val : infos) + { + vector info; + if (val.find(':') == string::npos) + { + cout << "Error SC_LOG format '" << val << "' in " << s; + cout << " ...Ignore it" << endl; + continue; + } + + split(val, info, ':'); + if (info.empty()) + continue; + + if (1 == info.size()) + info.push_back(""); + + if (2 == info.size()) + { + string msg_str = trim(info[0]); + string level_str = trim(info[1]); + int type = 0; + if (0 != msg_str.compare("")) + { + type |= (1<<0); + } + if (0 != level_str.compare("")) + { + type |= (1<<1); + } + set_sc_report(msg_str, level_str, type); + } else { + cout << "Error SC_LOG format '" << val << "' in " << s; + cout << " ...Ignore it" << endl; + continue; + } + } + + if (sc_report_handler::get_log_file_name() == NULL) + { + const char file_name[] = "outfile"; + sc_report_handler::set_log_file_name(file_name); + cout << "Set SC LOG file to default " << file_name << endl; + } +} diff --git a/libs/qbox b/libs/qbox new file mode 160000 index 0000000..b16efd0 --- /dev/null +++ b/libs/qbox @@ -0,0 +1 @@ +Subproject commit b16efd0432341d6052fa48ec25c4c2263e2b51a2 diff --git a/libs/tlm2c b/libs/tlm2c new file mode 160000 index 0000000..c54ade0 --- /dev/null +++ b/libs/tlm2c @@ -0,0 +1 @@ +Subproject commit c54ade009fbf2a2c9a72d99f14466df9133f89b5 diff --git a/models/cpu b/models/cpu new file mode 160000 index 0000000..8d62bd6 --- /dev/null +++ b/models/cpu @@ -0,0 +1 @@ +Subproject commit 8d62bd608773b27fd4bc26df43d67c3b11fc09a7 diff --git a/models/memory b/models/memory new file mode 160000 index 0000000..1018f87 --- /dev/null +++ b/models/memory @@ -0,0 +1 @@ +Subproject commit 1018f8782895afc6524b98597460a2c694c53029 diff --git a/models/nvdla/CMakeLists.txt b/models/nvdla/CMakeLists.txt new file mode 100644 index 0000000..2aabb8d --- /dev/null +++ b/models/nvdla/CMakeLists.txt @@ -0,0 +1,113 @@ +# Copyright (C) 2014, GreenSocs ltd. +# +# CMakeLists.txt +# +# KONRAD Frederic +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# Linking GreenSocs code, statically or dynamically with other modules +# is making a combined work based on GreenSocs code. Thus, the terms and +# conditions of the GNU General Public License cover the whole +# combination. +# +# In addition, as a special exception, the copyright holders, GreenSocs +# Ltd, give you permission to combine GreenSocs code with free software +# programs or libraries that are released under the GNU LGPL, under the +# OSCI license, under the OCP TLM Kit Research License Agreement or +# under the OVP evaluation license.You may copy and distribute such a +# system following the terms of the GNU GPL and the licenses of the +# other code concerned. +# +# Note that people who make modified versions of GreenSocs code are not +# obligated to grant this special exception for their modified versions; +# it is their choice whether to do so. The GNU General Public License +# gives permission to release a modified version without this exception; +# this exception also makes it possible to release a modified version +# which carries forward this exception. + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(NVDLA) + +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +FIND_PACKAGE(SystemC) +if(SystemC_FOUND) + INCLUDE_DIRECTORIES(${SystemC_INCLUDE_DIRS}) +else() + MESSAGE(FATAL_ERROR "SystemC library not found.") +endif() + +FIND_PACKAGE(TLM) +if(TLM_FOUND) + INCLUDE_DIRECTORIES(${TLM_INCLUDE_DIRS}) +else() + MESSAGE( FATAL_ERROR "TLM library not found." ) +endif() + +FIND_PACKAGE(GREENLIB) +if(GREENLIB_FOUND) + INCLUDE_DIRECTORIES(${GREENLIB_INCLUDE_DIRS}) + LINK_DIRECTORIES(${GREENLIB_LIBRARY_DIRS}) +else() + MESSAGE(FATAL_ERROR "GreenLib not found.") +endif() + +FIND_PACKAGE(NvdlaCmod) +if(NVDLA_CMOD_FOUND) + INCLUDE_DIRECTORIES(${NVDLA_CMOD_INCLUDE_DIR}) + LINK_DIRECTORIES(${NVDLA_CMOD_LIBRARY_DIR}) +else() + MESSAGE(FATAL_ERROR "NVDLA CMOD library not found.") +endif() + + +### NVDLA CMOD ### +INSTALL(DIRECTORY ${NVDLA_CMOD_INCLUDE_DIR}/ DESTINATION include) +INSTALL(DIRECTORY ${NVDLA_CMOD_LIBRARY_DIR}/ DESTINATION lib) + +set (INCLUDE_DIRS + ${INCLUDE_DIRS} + include + ) + +INCLUDE_DIRECTORIES(${INCLUDE_DIRS}) + +set(CMAKE_CXX_FLAGS "-Wall -Werror -DSC_INCLUDE_DYNAMIC_PROCESSES -Wp,-w") + +set(NVDLA_ADAPTOR_FILES + src/adaptors/gp2str.cpp + src/adaptors/gsgp2tlm.cpp + src/adaptors/tlm2gsgp.cpp + src/adaptors/irq_adaptor.cpp + ) + +if(MINGW) + add_library(nvdla STATIC src/nvdla_top.cpp + ${NVDLA_ADAPTOR_FILES} + ) +else() + add_library(nvdla SHARED src/nvdla_top.cpp + ${NVDLA_ADAPTOR_FILES} + ) +endif() + +TARGET_LINK_LIBRARIES(nvdla ${GREENLIB_LIBRARIES} ${NVDLA_CMOD_LIBRARY}) + +# Installation paths +INSTALL(DIRECTORY include/nvdla + DESTINATION include +) + +INSTALL(TARGETS nvdla DESTINATION lib) diff --git a/models/nvdla/README.md b/models/nvdla/README.md new file mode 100644 index 0000000..be5c15b --- /dev/null +++ b/models/nvdla/README.md @@ -0,0 +1,21 @@ +# NVDLA + +This is a NVDLA SystemC module + +## How to include this model in a project: + +* Copy the misc/FindNVDLA.cmake in your project repository. +* Add the following lines into your CMakeLists.txt: + ``` cmake + FIND_PACKAGE(NVDLA) + if(NVDLA_FOUND) + INCLUDE_DIRECTORIES(${NVDLA_INCLUDE_DIRS}) + LINK_DIRECTORIES(${NVDLA_LIBRARY_DIRS}) + else() + MESSAGE(FATAL_ERROR "NVDLA not found.") + endif() + ``` + +* Do the same for GreenLib as this module requires GreenLib. + +You're now able to use NVDLA headers and link the toplevel with NVDLA_LIBRARIES. diff --git a/models/nvdla/cmake/FindGREENLIB.cmake b/models/nvdla/cmake/FindGREENLIB.cmake new file mode 100644 index 0000000..6ffd90b --- /dev/null +++ b/models/nvdla/cmake/FindGREENLIB.cmake @@ -0,0 +1,70 @@ +# - Find GreenLib +# This module finds if GreenLib is installed and determines where the +# include files and libraries are. +# + +#============================================================================= +# Copyright 2014 GreenSocs +# +# KONRAD Frederic +#============================================================================= + +MESSAGE(STATUS "Searching for GreenLib") + +# The HINTS option should only be used for values computed from the system. +SET(_GREENLIB_HINTS + ${GREENLIB_PREFIX}/include + ${GREENLIB_PREFIX}/lib + ${GREENLIB_PREFIX}/lib-linux + ${GREENLIB_PREFIX}/lib-linux64 + ${GREENLIB_PREFIX}/lib-macos + $ENV{GREENLIB_PREFIX}/include + $ENV{GREENLIB_PREFIX}/lib + $ENV{GREENLIB_PREFIX}/lib-linux + $ENV{GREENLIB_PREFIX}/lib-linux64 + $ENV{GREENLIB_PREFIX}/lib-macos + ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib-linux + ${CMAKE_INSTALL_PREFIX}/lib-linux64 + ${CMAKE_INSTALL_PREFIX}/lib-macos +) + +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +SET(_GREENLIB_PATHS + /usr/include + /usr/lib + /usr/lib-linux + /usr/lib-linux64 + /usr/lib-macos + /usr/local/lib + /usr/local/lib-linux + /usr/local/lib-linux64 + /usr/local/lib-macos +) + +FIND_PATH(GREENLIB_INCLUDE_DIRS + NAMES greencontrol/config.h + HINTS ${_GREENLIB_HINTS} + PATHS ${_GREENLIB_PATHS} +) + +FIND_PATH(GREENLIB_LIBRARY_DIRS + NAMES libgreenreg.a + HINTS ${_GREENLIB_HINTS} + PATHS ${_GREENLIB_PATHS} +) + +find_package(Boost REQUIRED) +include_directories(${Boost_INCLUDE_DIRS}) + +if("${GREENLIB_INCLUDE_DIRS}" MATCHES "GREENLIB_INCLUDE_DIRS-NOTFOUND") + SET(GREENLIB_FOUND FALSE) +else("${GREENLIB_INCLUDE_DIRS}" MATCHES "GREENLIB_INCLUDE_DIRS-NOTFOUND") + SET(GREENLIB_FOUND TRUE) + MESSAGE(STATUS "GreenLib include directory = ${GREENLIB_INCLUDE_DIRS}") + MESSAGE(STATUS "GreenLib library directory = ${GREENLIB_LIBRARY_DIRS}") + SET(GREENLIB_LIBRARIES greenreg) +endif("${GREENLIB_INCLUDE_DIRS}" MATCHES "GREENLIB_INCLUDE_DIRS-NOTFOUND") + diff --git a/models/nvdla/cmake/FindNvdlaCmod.cmake b/models/nvdla/cmake/FindNvdlaCmod.cmake new file mode 100644 index 0000000..3637ffc --- /dev/null +++ b/models/nvdla/cmake/FindNvdlaCmod.cmake @@ -0,0 +1,75 @@ +# - Find NvdlaCmod +# This module finds if NVDLA CMOD is built and determines where the +# include files and libraries are. +# + +MESSAGE(STATUS "Searching for NVDLA CMOD") + +# The HINTS option should only be used for values computed from the system. +SET(_NVDLA_CMOD_HINTS + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/include + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib-linux + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib-linux64 + ${NVDLA_HW_PREFIX}/outdir/${NVDLA_HW_PROJECT}/cmod/release/lib-macos + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/include + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib-linux + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib-linux64 + $ENV{NVDLA_HW_PREFIX}/outdir/$ENV{NVDLA_HW_PROJECT}/cmod/release/lib-macos + ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib-linux + ${CMAKE_INSTALL_PREFIX}/lib-linux64 + ${CMAKE_INSTALL_PREFIX}/lib-macos +) + +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +SET(_NVDLA_CMOD_PATHS + /usr/include + /usr/lib + /usr/lib-linux + /usr/lib-linux64 + /usr/lib-macos + /usr/local/lib + /usr/local/lib-linux + /usr/local/lib-linux64 + /usr/local/lib-macos +) + +FIND_FILE(NVDLA_HW_VERSION_FILE + NAMES VERSION + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +FILE(READ ${NVDLA_HW_VERSION_FILE} NVDLA_HW_VERSION) + +FIND_PATH(NVDLA_CMOD_INCLUDE_DIR + NAMES NV_nvdla.h + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +find_library(NVDLA_CMOD_LIBRARY + NAMES nvdla_cmod + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +FIND_PATH(NVDLA_CMOD_LIBRARY_DIR + NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}nvdla_cmod${CMAKE_SHARED_LIBRARY_SUFFIX} + HINTS ${_NVDLA_CMOD_HINTS} + PATHS ${_NVDLA_CMOD_PATHS} +) + +if("${NVDLA_CMOD_INCLUDE_DIR}" MATCHES "NVDLA_CMOD_INCLUDE_DIR-NOTFOUND") + SET(NVDLA_CMOD_FOUND FALSE) +else("${NVDLA_CMOD_INCLUDE_DIR}" MATCHES "NVDLA_CMOD_INCLUDE_DIR-NOTFOUND") + SET(NVDLA_CMOD_FOUND TRUE) + MESSAGE(STATUS "NVDLA HW VERSION = ${NVDLA_HW_VERSION}") + MESSAGE(STATUS "NVDLA CMOD include directory = ${NVDLA_CMOD_INCLUDE_DIR}") + MESSAGE(STATUS "NVDLA CMOD library directory = ${NVDLA_CMOD_LIBRARY_DIR}") + MESSAGE(STATUS "NVDLA CMOD library = ${NVDLA_CMOD_LIBRARY}") +endif("${NVDLA_CMOD_INCLUDE_DIR}" MATCHES "NVDLA_CMOD_INCLUDE_DIR-NOTFOUND") diff --git a/models/nvdla/cmake/FindSystemC.cmake b/models/nvdla/cmake/FindSystemC.cmake new file mode 100644 index 0000000..9f05d34 --- /dev/null +++ b/models/nvdla/cmake/FindSystemC.cmake @@ -0,0 +1,179 @@ +# Find SystemC +# This module finds if SystemC is installed and determines where the +# include files and libraries are. This code sets the following +# variables: (from kernel/sc_ver.h) +# +# SystemC_VERSION_MAJOR = The major version of the package found +# SystemC_VERSION_MINOR = The minor version of the package found +# SystemC_VERSION_PATCH = The patch version of the package found +# SystemC_VERSION = The full version string of the package found +# +# For these components the following variables are set: +# +# SystemC_INCLUDE_DIRS - Full paths to all include dirs +# SystemC_LIBRARY_DIRS - Link directories for SystemC libraries +# SystemC::SystemC - Full path to SystemC library +# SystemC::SystemC_STATIC - Full path to SystemC static library +# +# Example Usages: +# find_package(SystemC) + +#============================================================================= +# Copyright 2015 GreenSocs +#============================================================================= + +function(SYSTEMC_APPEND_TARGET var prefix) + set(listVar "") + foreach(f ${ARGN}) + list(APPEND listVar "${prefix}${f}") + endforeach(f) + set(${var} "${listVar}" PARENT_SCOPE) +endfunction(SYSTEMC_APPEND_TARGET) + +set(_SYSTEMC_TARGET_SUFFIXES linux + linux64 + bsd + bsd64 + macosx + macosx64 + macosxppc + macosxppc64 + mingw + mingw64 + gccsparcOS5 + sparcOS5) + +SYSTEMC_APPEND_TARGET(_SYSTEMC_PREFIX_SUFFIXES ${SYSTEMC_PREFIX}/lib- ${_SYSTEMC_TARGET_SUFFIXES}) +SYSTEMC_APPEND_TARGET(_SYSTEMC_HOME_SUFFIXES $ENV{SYSTEMC_HOME}/lib- ${_SYSTEMC_TARGET_SUFFIXES}) +SYSTEMC_APPEND_TARGET(_USR_SUFFIXES /usr/lib- ${_SYSTEMC_TARGET_SUFFIXES}) +SYSTEMC_APPEND_TARGET(_USR_LOCAL_SUFFIXES /usr/local/lib- ${_SYSTEMC_TARGET_SUFFIXES}) + +set(_SYSTEMC_HINTS + ${SYSTEMC_PREFIX}/include + ${SYSTEMC_PREFIX}/lib + ${_SYSTEMC_PREFIX_SUFFIXES} + $ENV{SYSTEMC_HOME}/lib + $ENV{SYSTEMC_HOME}/include + ${_SYSTEMC_HOME_SUFFIXES}) + +set(_SYSTEMC_PATHS + /usr/local/lib + ${_USR_LOCAL_SUFFIXES} + /usr/local/lib64 + /usr/local/include + /usr/local/systemc + /usr/local/systemc/include + /usr/lib + ${_USR_SUFFIXES} + /usr/lib64 + /usr/include + /usr/systemc + /usr/systemc/include) + +find_file(_SYSTEMC_VERSION_FILE + NAMES sc_ver.h + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS} + PATH_SUFFIXES sysc/kernel) + +if(EXISTS ${_SYSTEMC_VERSION_FILE}) + file (READ ${_SYSTEMC_VERSION_FILE} _SYSTEMC_VERSION_FILE_CONTENTS) + string (REGEX MATCH + "SC_API_VERSION_STRING[ \t]+sc_api_version_([0-9]+)_([0-9]+)_([0-9]+)" + SC_API_VERSION_STRING ${_SYSTEMC_VERSION_FILE_CONTENTS}) + + if(NOT "${SC_API_VERSION_STRING}" MATCHES "") + # SystemC < 2.3.1 + string (REGEX MATCHALL "([0-9]+)" _SystemC_VERSION + ${SC_API_VERSION_STRING}) + list(GET _SystemC_VERSION 0 SystemC_VERSION_MAJOR) + list(GET _SystemC_VERSION 1 SystemC_VERSION_MINOR) + list(GET _SystemC_VERSION 2 SystemC_VERSION_PATCH) + else() + # SystemC >= 2.3.1 + string (REGEX MATCH "SC_VERSION_MAJOR[ \t]+([0-9]+)" + SystemC_VERSION_MAJOR ${_SYSTEMC_VERSION_FILE_CONTENTS}) + string (REGEX MATCH "([0-9]+)" SystemC_VERSION_MAJOR + ${SystemC_VERSION_MAJOR}) + string (REGEX MATCH "SC_VERSION_MINOR[ \t]+([0-9]+)" + SystemC_VERSION_MINOR ${_SYSTEMC_VERSION_FILE_CONTENTS}) + string (REGEX MATCH "([0-9]+)" SystemC_VERSION_MINOR + ${SystemC_VERSION_MINOR}) + string (REGEX MATCH "SC_VERSION_PATCH[ \t]+([0-9]+)" + SystemC_VERSION_PATCH ${_SYSTEMC_VERSION_FILE_CONTENTS}) + string (REGEX MATCH "([0-9]+)" SystemC_VERSION_PATCH + ${SystemC_VERSION_PATCH}) + endif() + + set(SystemC_VERSION "${SystemC_VERSION_MAJOR}.${SystemC_VERSION_MINOR}.${SystemC_VERSION_PATCH}") + + # Compatibility variable + set(SystemC_VERSION_STRING ${SystemC_VERSION}) + + find_path(SystemC_INCLUDE_DIRS + NAMES systemc systemc.h + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS}) + + # Static + set(_SystemC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif() + + find_library(SystemC_LIBRARIES_STATIC + NAMES systemc SystemC + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS}) + + # Restore original CMAKE_FIND_LIBRARY_SUFFIXES + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_SystemC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + + # If SystemC_USE_STATIC_LIBS set to ON, force the use of the static libraries + if(SystemC_USE_STATIC_LIBS) + set(SystemC_LIBRARIES SystemC_LIBRARIES_STATIC) + else() + find_library(SystemC_LIBRARIES + NAMES systemc SystemC + HINTS ${_SYSTEMC_HINTS} + PATHS ${_SYSTEMC_PATHS}) + endif() + + # Default + if(NOT TARGET SystemC::SystemC) + add_library(SystemC::SystemC UNKNOWN IMPORTED) + set_target_properties(SystemC::SystemC PROPERTIES + IMPORTED_LOCATION "${SystemC_LIBRARIES}") + endif() + + # Static + if(NOT TARGET SystemC::SystemC_STATIC) + add_library(SystemC::SystemC_STATIC STATIC IMPORTED) + set_target_properties(SystemC::SystemC_STATIC PROPERTIES + IMPORTED_LOCATION "${SystemC_LIBRARIES_STATIC}") + endif() + + if("${CMAKE_VERSION}" VERSION_GREATER 2.8.12) + get_filename_component(SystemC_LIBRARY_DIRS ${SystemC_LIBRARIES} + DIRECTORY) + else("${CMAKE_VERSION}" VERSION_GREATER 2.8.12) + get_filename_component(SystemC_LIBRARY_DIRS ${SystemC_LIBRARIES} + PATH) + endif() +endif() + +include(FindPackageHandleStandardArgs) +if("${CMAKE_VERSION}" VERSION_GREATER 2.8.10) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC + FOUND_VAR SystemC_FOUND + REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS + VERSION_VAR SystemC_VERSION) +else() + FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC + REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS + VERSION_VAR SystemC_VERSION) + set(SystemC_FOUND ${SYSTEMC_FOUND}) +endif() +mark_as_advanced(SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS) diff --git a/models/nvdla/cmake/FindTLM.cmake b/models/nvdla/cmake/FindTLM.cmake new file mode 100644 index 0000000..fdbd708 --- /dev/null +++ b/models/nvdla/cmake/FindTLM.cmake @@ -0,0 +1,75 @@ +# Find TLM +# This module finds if TLM is installed and determines where the +# include files and libraries are. This code sets the following +# variables: (from tlm_version.h) +# +# TLM_VERSION_MAJOR = The major version of the package found. +# TLM_VERSION_MINOR = The minor version of the package found. +# TLM_VERSION_PATCH = The patch version of the package found. +# TLM_VERSION = The full version string of the package found. +# +# The minimum required version of TLM can be specified using the +# standard CMake syntax, e.g. FIND_PACKAGE(TLM 2.2) +# +# For these components the following variables are set: +# +# TLM_FOUND - TRUE if all components are found. +# TLM_INCLUDE_DIRS - Full paths to all include dirs. +# +# Example Usages: +# FIND_PACKAGE(TLM) + +#============================================================================= +# Copyright 2015 GreenSocs +#============================================================================= + +set(_TLM_HINTS + ${TLM_PREFIX} + ${SYSTEMC_PREFIX}/include + $ENV{TLM_HOME} + $ENV{SYSTEMC_HOME}/include) + +set(_TLM_PATHS + /usr/local/include/tlm + /usr/local/include/systemc + /usr/include/tlm + /usr/include/systemc) + +find_file(_TLM_VERSION_FILE + NAMES tlm_version.h + HINTS ${_TLM_HINTS} + PATHS ${_TLM_PATHS} + PATH_SUFFIXES tlm_h + tlm/tlm_h + tlm_core/tlm_2) + +if(EXISTS ${_TLM_VERSION_FILE}) + file (READ ${_TLM_VERSION_FILE} _TLM_VERSION_FILE_CONTENTS) + + string (REGEX MATCH "TLM_VERSION_MAJOR[ \t]+([0-9]+)" + TLM_VERSION_MAJOR ${_TLM_VERSION_FILE_CONTENTS}) + string (REGEX MATCH "([0-9]+)" TLM_VERSION_MAJOR + ${TLM_VERSION_MAJOR}) + string (REGEX MATCH "TLM_VERSION_MINOR[ \t]+([0-9]+)" + TLM_VERSION_MINOR ${_TLM_VERSION_FILE_CONTENTS}) + string (REGEX MATCH "([0-9]+)" TLM_VERSION_MINOR + ${TLM_VERSION_MINOR}) + string (REGEX MATCH "TLM_VERSION_PATCH[ \t]+([0-9]+)" + TLM_VERSION_PATCH ${_TLM_VERSION_FILE_CONTENTS}) + string (REGEX MATCH "([0-9]+)" TLM_VERSION_PATCH + ${TLM_VERSION_PATCH}) + + set(TLM_VERSION "${TLM_VERSION_MAJOR}.${TLM_VERSION_MINOR}.${TLM_VERSION_PATCH}") + + find_path(TLM_INCLUDE_DIRS + NAMES tlm tlm.h + HINTS ${_TLM_HINTS} + PATHS ${_TLM_PATHS} + PATH_SUFFIXES tlm) + +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TLM + REQUIRED_VARS TLM_INCLUDE_DIRS + VERSION_VAR TLM_VERSION) \ No newline at end of file diff --git a/models/nvdla/include/adaptors/gp2str.h b/models/nvdla/include/adaptors/gp2str.h new file mode 100644 index 0000000..49a655c --- /dev/null +++ b/models/nvdla/include/adaptors/gp2str.h @@ -0,0 +1,21 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: gp2str.h + +#ifndef GP2STR_H +#define GP2STR_H + +#include +#include + +std::string gp2str(const tlm::tlm_generic_payload &gp); +inline bool getBe(uint8_t* ptr, uint32_t len, uint32_t idx); +inline std::string getByte(uint8_t *ptr, bool valid, bool is_first_byte_of_word); + +#endif /* !GP2STR_H */ diff --git a/models/nvdla/include/adaptors/gsgp2tlm.h b/models/nvdla/include/adaptors/gsgp2tlm.h new file mode 100644 index 0000000..af2da63 --- /dev/null +++ b/models/nvdla/include/adaptors/gsgp2tlm.h @@ -0,0 +1,45 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: gsgp2tlm.h + +#ifndef GSGP2TLM_H +#define GSGP2TLM_H + +#ifndef SC_INCLUDE_DYNAMIC_PROCESSES +#define SC_INCLUDE_DYNAMIC_PROCESSES +#endif + +#include +#include +#include "tlm_utils/multi_passthrough_initiator_socket.h" + +#include "gsgpsocket/transport/GSGPSlaveSocket.h" + +class Gsgp2tlm + : public sc_core::sc_module + , public gs::tlm_b_if +{ + public: + Gsgp2tlm(sc_core::sc_module_name name); + ~Gsgp2tlm(); + + SC_HAS_PROCESS(Gsgp2tlm); + + gs::gp::GenericSlavePort<32> gsgp_slave_port; + void b_transact(gs::gp::GenericSlaveAccessHandle ah); + + tlm_utils::multi_passthrough_initiator_socket tlm_master_port; + +private: + void end_of_elaboration(); + + tlm::tlm_generic_payload m_tlm_gp; +}; + +#endif /* !GSGP2TLM_H */ diff --git a/models/nvdla/include/adaptors/irq_adaptor.h b/models/nvdla/include/adaptors/irq_adaptor.h new file mode 100644 index 0000000..6bd357a --- /dev/null +++ b/models/nvdla/include/adaptors/irq_adaptor.h @@ -0,0 +1,44 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: irq_adaptor.h + +#ifndef _IRQ_ADAPTOR_H_ +#define _IRQ_ADAPTOR_H_ + +#ifndef SC_INCLUDE_DYNAMIC_PROCESSES +#define SC_INCLUDE_DYNAMIC_PROCESSES +#endif + +#include + +#include "greensignalsocket/green_signal.h" + +#include "nvdla/IRQ.h" + +class IrqAdaptor : + public sc_core::sc_module +{ +public: + IrqAdaptor( sc_core::sc_module_name name , uint32_t irq); + SC_HAS_PROCESS(IrqAdaptor); + + sc_core::sc_in< bool > m_signal; + gs_generic_signal::initiator_signal_socket m_socket; + + void transport(void); + +private: + gs_generic_signal::gs_generic_signal_payload payload; + sc_core::sc_time m_delay; + IRQ_ext_data data; + uint32_t irq_number; + bool ack_requirement; +}; + +#endif diff --git a/models/nvdla/include/adaptors/tlm2gsgp.h b/models/nvdla/include/adaptors/tlm2gsgp.h new file mode 100644 index 0000000..8942723 --- /dev/null +++ b/models/nvdla/include/adaptors/tlm2gsgp.h @@ -0,0 +1,48 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: tlm2gsgp.h + +#ifndef TLM2GSGP_H +#define TLM2GSGP_H + +#ifndef SC_INCLUDE_DYNAMIC_PROCESSES +#define SC_INCLUDE_DYNAMIC_PROCESSES +#endif + +#include +#include +#include "tlm_utils/simple_target_socket.h" + +#include "gsgpsocket/transport/GSGPMasterBlockingSocket.h" + +class Tlm2gsgp + : public sc_core::sc_module + , public gs::payload_event_queue_output_if +{ +public: + Tlm2gsgp(sc_core::sc_module_name name); + ~Tlm2gsgp(); + + SC_HAS_PROCESS(Tlm2gsgp); + + typedef gs::gp::GenericMasterBlockingPort<32>::accessHandle transactionHandle; + + gs::gp::GenericMasterBlockingPort<32> gsgp_master_port; + + tlm_utils::simple_target_socket tlm_slave_port; + +private: + void notify(gs::gp::master_atom& tc) {}; + void end_of_elaboration(); + void b_transport(tlm::tlm_generic_payload& tlm_gp, sc_time& delay); + + transactionHandle transaction; /* + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Linking GreenSocs code, statically or dynamically with other modules + * is making a combined work based on GreenSocs code. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * In addition, as a special exception, the copyright holders, GreenSocs + * Ltd, give you permission to combine GreenSocs code with free software + * programs or libraries that are released under the GNU LGPL, under the + * OSCI license, under the OCP TLM Kit Research License Agreement or + * under the OVP evaluation license.You may copy and distribute such a + * system following the terms of the GNU GPL and the licenses of the + * other code concerned. + * + * Note that people who make modified versions of GreenSocs code are not + * obligated to grant this special exception for their modified versions; + * it is their choice whether to do so. The GNU General Public License + * gives permission to release a modified version without this exception; + * this exception also makes it possible to release a modified version + * which carries forward this exception. + * + */ + +#ifndef IRQ_H +#define IRQ_H + +/* + * This just defines an IRQ extension for GreenSignal to pass the IRQ number and + * the value. + */ +GS_GUARD_ONLY_EXTENSION(IRQ_LINE_EXTENSION); + +typedef struct IRQ_ext_data +{ + uint32_t value; + uint32_t irq_line; +} IRQ_ext_data; + + + +#endif /* !IRQ_H */ diff --git a/models/nvdla/include/nvdla/nvdla_top.h b/models/nvdla/include/nvdla/nvdla_top.h new file mode 100644 index 0000000..f31b8e7 --- /dev/null +++ b/models/nvdla/include/nvdla/nvdla_top.h @@ -0,0 +1,70 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: nvdla_top.h + +#ifndef NVDLA_TOP_H +#define NVDLA_TOP_H + +#include +#include +#include "tlm_utils/multi_passthrough_initiator_socket.h" +#include "tlm_utils/multi_passthrough_target_socket.h" + +#include "greensignalsocket/green_signal.h" + +#include "gsgpsocket/transport/GSGPSlaveSocket.h" +#include "gsgpsocket/transport/GSGPMasterBlockingSocket.h" + +class IrqAdaptor; +class Gsgp2tlm; +class Tlm2gsgp; +// FIXME get rid of it... +namespace scsim { + namespace cmod { + class NV_nvdla; + } +} + +class NVDLA_top + : public sc_module + , public gs::tlm_b_if + , public gs::payload_event_queue_output_if +{ +public: + NVDLA_top(sc_core::sc_module_name name); + ~NVDLA_top(); + + typedef gs_generic_signal::gs_generic_signal_payload irqPayload; + gs::gp::GenericSlavePort<32> target_port; + gs::gp::GenericMasterBlockingPort<32> m_mc_port; + gs::gp::GenericMasterBlockingPort<32> m_cv_port; + gs_generic_signal::initiator_signal_socket irq_socket; + + void b_transact(gs::gp::GenericSlaveAccessHandle ah) {}; + +private: + /* + * Parameter for the irq line. + */ + gs::gs_param irqNumber; + gs::gs_param m_size; + + IrqAdaptor *m_irq_adaptor; + Gsgp2tlm * m_gsgp2tlm; + Tlm2gsgp * m_tlm2gsgp_mc; + Tlm2gsgp * m_tlm2gsgp_cv; + + scsim::cmod::NV_nvdla *m_nvdla; + sc_buffer m_coreIrq; + + void notify(gs::gp::master_atom& tc) {}; + void end_of_elaboration(void); +}; + +#endif /* !NVDLA_TOP_H */ diff --git a/models/nvdla/misc/FindNVDLA.cmake b/models/nvdla/misc/FindNVDLA.cmake new file mode 100644 index 0000000..438b2ff --- /dev/null +++ b/models/nvdla/misc/FindNVDLA.cmake @@ -0,0 +1,48 @@ +# This module looks for NVDLA module and determines where the header files and +# libraries are. + +MESSAGE(STATUS "Searching for NVDLA model.") + +# The HINTS option should only be used for values computed from the system. +SET(_NVDLA_HINTS + ${NVDLA_PREFIX}/include + ${NVDLA_PREFIX}/lib + ${NVDLA_PREFIX}/lib64 + $ENV{NVDLA_PREFIX}/include + $ENV{NVDLA_PREFIX}/lib + $ENV{NVDLA_PREFIX}/lib64 + ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib64 + ) +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +SET(_NVDLA_PATHS + /usr/include + /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + ) + +FIND_PATH(NVDLA_INCLUDE_DIRS + NAMES NVDLA/NVDLA.h + HINTS ${_NVDLA_HINTS} + PATHS ${_NVDLA_PATHS} +) + +FIND_PATH(NVDLA_LIBRARY_DIRS + NAMES libnvdla.so + HINTS ${_NVDLA_HINTS} + PATHS ${_NVDLA_PATHS} +) + +if("${NVDLA_INCLUDE_DIRS}" MATCHES "NVDLA_INCLUDE_DIRS-NOTFOUND") + SET(NVDLA_FOUND FALSE) +else("${NVDLA_INCLUDE_DIRS}" MATCHES "NVDLA_INCLUDE_DIRS-NOTFOUND") + SET(NVDLA_FOUND TRUE) + MESSAGE(STATUS "NVDLA include directory = ${NVDLA_INCLUDE_DIRS}") + MESSAGE(STATUS "NVDLA library directory = ${NVDLA_LIBRARY_DIRS}") + SET(NVDLA_LIBRARIES nvdla) +endif("${NVDLA_INCLUDE_DIRS}" MATCHES "NVDLA_INCLUDE_DIRS-NOTFOUND") + diff --git a/models/nvdla/src/adaptors/gp2str.cpp b/models/nvdla/src/adaptors/gp2str.cpp new file mode 100644 index 0000000..14c4112 --- /dev/null +++ b/models/nvdla/src/adaptors/gp2str.cpp @@ -0,0 +1,100 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: gp2str.cpp + +#include "adaptors/gp2str.h" +#include +#include + +using namespace std; + +std::string gp2str(const tlm::tlm_generic_payload &gp) +{ + uint32_t const bytes_in_word = sizeof(uint32_t); + + uint64_t address = gp.get_address(); + uint8_t* data_ptr = gp.get_data_ptr(); + uint32_t data_len = gp.get_data_length(); + uint8_t* be_ptr = gp.get_byte_enable_ptr(); + uint32_t be_len = gp.get_byte_enable_length(); + + if (be_ptr && be_len == 0) return "ERROR GENERIC PAYLOAD: byte_enable_length == 0!"; + if (be_ptr == NULL && be_len>0) return "ERROR GENERIC PAYLOAD: byte_enable_ptr == NULL!"; + if (data_ptr == NULL && data_len>0) return "ERROR GENERIC PAYLOAD: data_ptr == NULL!"; + + std::ostringstream data_oss; + data_oss << "0x"; + + uint32_t remain_len = data_len; + uint32_t idx = 0; + + if (address % bytes_in_word != 0) { + data_oss << " "; + int bytes = (bytes_in_word - address%bytes_in_word) > remain_len ? + remain_len : (bytes_in_word- address%bytes_in_word); + for (int i=0; i 0) { + data_oss << " "; + if ( remain_len >= bytes_in_word) { + bool word_enable = true; + for (uint32_t i=0;i(data_ptr+idx); + idx += bytes_in_word; + } else { + for (int i=0;igsgp_slave_port.bind_b_if(*this); +} + +Gsgp2tlm::~Gsgp2tlm() +{ +} + +void Gsgp2tlm::end_of_elaboration() +{ +} + +void Gsgp2tlm::b_transact(gs::gp::GenericSlaveAccessHandle ah) +{ + // Fix delay to 0 + sc_time delay = SC_ZERO_TIME; + + // Get slave access handle + gs::gp::GenericSlavePort<32>::accessHandle t = _getSlaveAccessHandle(ah); + + // Get data and size + gs::GSDataType data; + data.set(t->getMData()); + + // Fill the transaction + m_tlm_gp.set_command(t->getMCmd()==gs::Generic_MCMD_WR?TLM_WRITE_COMMAND:TLM_READ_COMMAND); + m_tlm_gp.set_address(t->getMAddr() - gsgp_slave_port.base_addr); + m_tlm_gp.set_data_ptr(data.getDataPtr()->getData()); + m_tlm_gp.set_data_length(data.getSize()); + m_tlm_gp.set_byte_enable_length(0); + m_tlm_gp.set_response_status(TLM_INCOMPLETE_RESPONSE); + + // Issue b_transport + tlm_master_port->b_transport(m_tlm_gp, delay); + + // Send response + t->get_tlm_transaction()->set_response_status(m_tlm_gp.get_response_status()); + + if (m_tlm_gp.get_response_status() != TLM_OK_RESPONSE) { + SC_REPORT_ERROR(name(), gp2str(m_tlm_gp).c_str()); + } + +#if DEBUG_LOG + SC_REPORT_INFO_VERB(name(), gp2str(m_tlm_gp).c_str(), verb); +#endif +} diff --git a/models/nvdla/src/adaptors/irq_adaptor.cpp b/models/nvdla/src/adaptors/irq_adaptor.cpp new file mode 100644 index 0000000..8a5c531 --- /dev/null +++ b/models/nvdla/src/adaptors/irq_adaptor.cpp @@ -0,0 +1,55 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: IrqAdaptor.h + +#include "adaptors/irq_adaptor.h" + +using namespace tlm; +using namespace sc_core; + +#ifndef DEBUG_LOG +#define DEBUG_LOG 0 +#endif + +#if DEBUG_LOG +#include +static int const verb = SC_HIGH; +#endif + +IrqAdaptor::IrqAdaptor( sc_core::sc_module_name name , uint32_t irq) + : m_delay(sc_core::SC_ZERO_TIME), + ack_requirement(false), + m_socket("m_socket"), + irq_number(irq) +{ + payload.set_data_ptr( reinterpret_cast( &data ) ); + + gs::socket::config cnf; + cnf.use_mandatory_extension(); + m_socket.set_config(cnf); + + SC_THREAD( transport ); + sensitive << m_signal; +} + +void IrqAdaptor::transport(void) +{ + while(1) { + wait(); + data.value = m_signal.read(); + data.irq_line = irq_number; + m_socket.validate_extension(payload); + m_socket->b_transport( payload, m_delay ); +#if DEBUG_LOG + std::ostringstream oss; + oss << "IRQ: irq_line=" << data.irq_line << " value=" << data.value; + SC_REPORT_INFO_VERB(name(), oss.str().c_str(), verb); +#endif + } +} diff --git a/models/nvdla/src/adaptors/tlm2gsgp.cpp b/models/nvdla/src/adaptors/tlm2gsgp.cpp new file mode 100644 index 0000000..adbf34f --- /dev/null +++ b/models/nvdla/src/adaptors/tlm2gsgp.cpp @@ -0,0 +1,72 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: tlm2gsgp.cpp + +#include "adaptors/tlm2gsgp.h" +#include "adaptors/gp2str.h" + +using namespace std; +using namespace tlm; +using namespace sc_core; + +#ifndef DEBUG_LOG +#define DEBUG_LOG 0 +#endif + +#if DEBUG_LOG +static int const verb = SC_HIGH; +#endif + +Tlm2gsgp::Tlm2gsgp(sc_core::sc_module_name name) + : sc_module(name) + , gsgp_master_port("gsgp_master_port") + , tlm_slave_port("tlm_slave_port") +{ + tlm_slave_port.register_b_transport(this, &Tlm2gsgp::b_transport); + gsgp_master_port.out_port(*this); +} + +Tlm2gsgp::~Tlm2gsgp() +{ +} + +void Tlm2gsgp::end_of_elaboration() +{ + // Create transaction + transaction = gsgp_master_port.create_transaction(); +} + +void Tlm2gsgp::b_transport(tlm_generic_payload& tlm_gp, sc_time& delay) +{ + unsigned char *value = tlm_gp.get_data_ptr(); + uint64_t size = tlm_gp.get_data_length(); + gs::GSDataType::dtype data = gs::GSDataType::dtype(value, size); + + // Fill the transaction + this->transaction->setMBurstLength(size); + this->transaction->setMAddr(tlm_gp.get_address()); + this->transaction->setMData(data); + this->transaction->setMCmd(tlm_gp.is_write()?gs::Generic_MCMD_WR:gs::Generic_MCMD_RD); + this->transaction->get_tlm_transaction()->set_byte_enable_ptr(tlm_gp.get_byte_enable_ptr()); + this->transaction->get_tlm_transaction()->set_byte_enable_length(tlm_gp.get_byte_enable_length()); + + // Issue b_transport + gsgp_master_port.Transact(this->transaction); + + // Send response + tlm_gp.set_response_status(transaction->get_tlm_transaction()->get_response_status()); + + if (tlm_gp.get_response_status() != TLM_OK_RESPONSE) { + SC_REPORT_ERROR(name(), gp2str(tlm_gp).c_str()); + } + +#if DEBUG_LOG + SC_REPORT_INFO_VERB(name(), gp2str(tlm_gp).c_str(), verb); +#endif +} diff --git a/models/nvdla/src/nvdla_top.cpp b/models/nvdla/src/nvdla_top.cpp new file mode 100644 index 0000000..371e089 --- /dev/null +++ b/models/nvdla/src/nvdla_top.cpp @@ -0,0 +1,92 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: nvdla_top.cpp + +#include "nvdla/nvdla_top.h" +#include "nvdla/IRQ.h" + +#include "adaptors/gsgp2tlm.h" +#include "adaptors/tlm2gsgp.h" +#include "adaptors/irq_adaptor.h" + +#include "NV_nvdla.h" + +USING_SCSIM_NAMESPACE(cmod) + +using namespace sc_core; +using namespace tlm; + +/** + * NVDLA SystemC module + * + * @param name Instance name + * @param irq_number IRQ number + * @param + */ +NVDLA_top::NVDLA_top(sc_module_name name): + target_port("csb_port"), + m_mc_port("m_mc_port"), + m_cv_port("m_cv_port"), + irq_socket("irq_socket"), + irqNumber("irq_number", 0), + m_size("size", 0x100) +{ + gs::socket::config cnf; + cnf.use_mandatory_extension(); + irq_socket.set_config(cnf); + + // Create nvdla and adaptors + m_nvdla = new NV_nvdla("nvdla_core"); + m_gsgp2tlm = new Gsgp2tlm("csb_adaptor"); + m_tlm2gsgp_mc = new Tlm2gsgp("dbb_adaptor"); + m_tlm2gsgp_cv = new Tlm2gsgp("sram_adaptor"); + m_irq_adaptor = new IrqAdaptor("irq_adaptor", (uint32_t)irqNumber); + + // Bind CSB port + this->target_port.bind( m_gsgp2tlm->gsgp_slave_port ); + m_gsgp2tlm->tlm_master_port.bind( m_nvdla->nvdla_host_master_if ); + + // Bind Memory port + m_nvdla->nvdla_core2dbb_axi4.bind(m_tlm2gsgp_mc->tlm_slave_port); + m_nvdla->nvdla_core2cvsram_axi4.bind(m_tlm2gsgp_cv->tlm_slave_port); + m_tlm2gsgp_mc->gsgp_master_port.bind(this->m_mc_port); + m_tlm2gsgp_cv->gsgp_master_port.bind(this->m_cv_port); + this->m_mc_port.out_port(*this); + this->m_cv_port.out_port(*this); + + // Bind IRQ port + m_nvdla->nvdla_intr( m_coreIrq ); + m_irq_adaptor->m_signal( m_coreIrq ); + m_irq_adaptor->m_socket.bind( irq_socket ); +} + +/** + * Destructor + */ +NVDLA_top::~NVDLA_top() +{ + if (m_nvdla) + delete m_nvdla; + if (m_gsgp2tlm) + delete m_gsgp2tlm; + if (m_tlm2gsgp_mc) + delete m_tlm2gsgp_mc; + if (m_tlm2gsgp_cv) + delete m_tlm2gsgp_cv; + if (m_irq_adaptor) + delete m_irq_adaptor; +} + +/* + * + * End of elaboration + */ +void NVDLA_top::end_of_elaboration() +{ +} diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..764217f --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,5 @@ +#! /bin/bash + +cmake -DCMAKE_INSTALL_PREFIX=build -DSYSTEMC_PREFIX=/usr/local/systemc-2.3.0/ -DNVDLA_HW_PREFIX=$PWD/../hw -DNVDLA_HW_PROJECT=nv_full -DCMAKE_BUILD_TYPE=Debug +make | tee make.log +make install diff --git a/scripts/dump_dts.sh b/scripts/dump_dts.sh new file mode 100755 index 0000000..806f5fa --- /dev/null +++ b/scripts/dump_dts.sh @@ -0,0 +1,5 @@ +#! /bin/bash + +export SC_SIGNAL_WRITE_CHECK=DISABLE +./aarch64_toplevel -c conf/aarch64_nvdla_dump_dts.lua +dtc virt.dtb -o virt.dts -I dtb -O dts diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 0000000..1cd7a99 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +export SC_SIGNAL_WRITE_CHECK=DISABLE +./build/bin/aarch64_toplevel -c conf/aarch64_nvdla.lua diff --git a/src/aarch64_toplevel.cpp b/src/aarch64_toplevel.cpp new file mode 100644 index 0000000..908da18 --- /dev/null +++ b/src/aarch64_toplevel.cpp @@ -0,0 +1,189 @@ +/* + * toplevel.cpp + * + * Copyright (C) 2015, GreenSocs Ltd. + * + * Developed by Frederic Konrad + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Linking GreenSocs code, statically or dynamically with other modules + * is making a combined work based on GreenSocs code. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * In addition, as a special exception, the copyright holders, GreenSocs + * Ltd, give you permission to combine GreenSocs code with free software + * programs or libraries that are released under the GNU LGPL, under the + * OSCI license, under the OCP TLM Kit Research License Agreement or + * under the OVP evaluation license.You may copy and distribute such a + * system following the terms of the GNU GPL and the licenses of the + * other code concerned. + * + * Note that people who make modified versions of GreenSocs code are not + * obligated to grant this special exception for their modified versions; + * it is their choice whether to do so. The GNU General Public License + * gives permission to release a modified version without this exception; + * this exception also makes it possible to release a modified version + * which carries forward this exception. + * + */ + +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +#include "SimpleCPU/simpleCPU.h" +#include "SimpleMemory/simpleMemory.h" +#include "nvdla/nvdla_top.h" +#include "log/log.h" + +#include "greenrouter/genericRouter.h" +#include "greenrouter/protocol/SimpleBus/simpleBusProtocol.h" +#include "greenrouter/scheduler/fixedPriorityScheduler.h" +#include "greencontrol/config.h" +#include "greencontrol/config_api_lua_file_parser.h" + +static void showUsage(std::string name) +{ + std::cerr << "Usage: " << name << " \n" + << "Options:\n" + << "\t-h,--help\t\t\tShow this help message\n" + << "\t-c,--conf CONFIGURATION_FILE\tSpecify the configuration file path" + << std::endl; +} + +std::string parseArgs(int argc, char **argv) { + std::string configurationFilePath; + for (int i = 1; i < argc; ++i) { + std::string arg = argv[i]; + if ((arg == "-h") || (arg == "--help")) { + showUsage(argv[0]); + exit(EXIT_SUCCESS); + } else if ((arg == "-c") || (arg == "--conf")) { + if (i + 1 < argc) { + configurationFilePath = argv[++i]; + } else { + std::cerr << "--conf option requires one argument." << std::endl; + exit(EXIT_FAILURE); + } + } + } + return configurationFilePath; +} + +std::string getSCLog(int argc, char **argv) { + std::string sc_log_str; + for (int i = 1; i < argc; ++i) { + std::string arg = argv[i]; + if ((arg == "-s") || (arg == "--sc_log")) { + if (i + 1 < argc) { + sc_log_str = argv[++i]; + } else { + std::cerr << "--sc_log option requires one argument." << std::endl; + exit(EXIT_FAILURE); + } + } + } + return sc_log_str; +} + +int sc_main(int argc, char **argv) +{ + /* GSPARAMS */ + std::string configurationFilePath = parseArgs(argc, argv); + gs::cnf::LuaFile_Tool luareader("luareader"); + bool openResult; + if(configurationFilePath.empty()) { + openResult = luareader.config("config.lua"); + } else { + openResult = luareader.config(configurationFilePath.c_str()); + } + + if(openResult != 0) { + showUsage(argv[0]); + exit(EXIT_FAILURE); + } + + char *SC_LOG = getenv("SC_LOG"); + if (SC_LOG != NULL) { + string sc_log_str(SC_LOG); + log_parse(sc_log_str); + } else { + std::string str_from_c = getSCLog(argc, argv); + if (!str_from_c.empty()) { + log_parse(str_from_c); + } else { + cout << "No sc_log specified, will use the default setting" << endl; + cout << "verbosity_level = SC_MEDIUM" << endl; + } + } + + /* + * CPU. + */ + SimpleCPU *cpu = new SimpleCPU("CPU"); + + /* + * Memories. + */ + Memory<32> *ram = new Memory<32>("ram"); + + /* + * Peripherals. + */ + NVDLA_top *nvdla; + nvdla = new NVDLA_top("nvdla"); + + /* + * Memory router. + */ + gs::gp::SimpleBusProtocol<32> *protocol = + new gs::gp::SimpleBusProtocol<32>("protocol", 10); + gs::gp::fixedPriorityScheduler *scheduler = + new gs::gp::fixedPriorityScheduler("scheduler"); + gs::gp::GenericRouter<32> *router = + new gs::gp::GenericRouter<32>("router"); + + protocol->router_port(*router); + protocol->scheduler_port(*scheduler); + router->protocol_port(*protocol); + + /* + * Bind the CPU. + */ + cpu->master_socket(router->target_socket); + + /* + * Bind the memories. + */ + router->init_socket(ram->target_port); + + /* + * Bind the nvdla. + */ + router->init_socket(nvdla->target_port); + nvdla->m_mc_port(router->target_socket); + nvdla->m_cv_port(router->target_socket); + nvdla->irq_socket(cpu->irq_socket); + + sc_core::sc_start(); + + return 0; +} + diff --git a/tests/hello/Makefile b/tests/hello/Makefile new file mode 100644 index 0000000..bd35a46 --- /dev/null +++ b/tests/hello/Makefile @@ -0,0 +1,10 @@ +GCC=aarch64-linux-gnu-gcc + +all: hello + +hello: + $(GCC) -o aarch64_hello hello.c -Wall + +clean: + rm -f aarch64_hello + diff --git a/tests/hello/aarch64_hello b/tests/hello/aarch64_hello new file mode 100755 index 0000000000000000000000000000000000000000..f4ccfe8771cff422602d2b90ecf5a50d42a8ae1e GIT binary patch literal 9646 zcmeHNZ)_CD6@PbUi1}|5{a$HcE`$Bv7u3#Vl(t_{?5I0g`DM9FyhQ|ds^212 zwLt8vAG$Ff0&9FasbcYdv?CvLjjxLH5XxyoeKOHspN!Qd6RF&2o#SMpLtC37*>t2) z=TH7gw`0$fDiWQyhg46?S7Dzpk{>>N=k&|NuLk~frmN@dp&w5)fBuKJNJgQ_haMMl z`@*$^$sDL2`_c2?{-koWC>y`@#w3td{WAr@O=iphVcdi2dqPs z#=R9ra&8u!{&dC#+a}n~x=zNmhn++Uk-_0~iV+(+x;tCj>@AVTZ7O;Y$Eph*z!B4! z<@}tScol~q1g!_~{)!f55x|p1dWBY{@g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I@N4&xi-YMn&;KwUL)_p&|2xL9?J4fSdUuqI+Lgq;y{C z>#wxVT7MZ#R#-k)8ZWJLA8M70EB=3O_<0lcgRl$)m;12RFP$eEFFo(S{?xcj;9kf= zjbal&&+~muBpa}BPvbIisb`h(ek*=z47{8Dn7H`qGxRmS z7B=zvEaMXY=6kix{!Kim##@|k$f~COmtGeyD*aOYC+uI|>m?t_|J}0rmtK!=DF3Cn z_EXGL{9i%+a_3R&uYhsmyi0xL|2g94uXFej{b?irx#o|KTe|*ytj1M}YyHysHm&qa zamu&cc=dB-b;&xm8gGVyGV9f&>LyuQ=SHPpx{m2OEQJPR{&%4MN}T`l|1fzTd4$LAGeT)$=i z=KB0+#LJEAW5lb2rPt$K_P@{YzX+crs_{uz?q5>38pO-}ANg^GFDv~2ag+zP9dW9g zS)Z@4{)iE`eGdH|#?AUa&3@#1*~D?5MZ8=cGKfBcQV%9dilSuPteYDch(z&AfUdUvc6aB2UfYIPJQE*GWO0kic8Bd~GM$QNp$uf( zv9vvyO!qrUJLaY{S=-5t0`3BhB;#&87TMOcwE;bsQLf&M$!k+WY_+do_4!^&rTeG9*y*U4q{;Me0onyPiGry zc_iwq2(UZ4_qMil+k1EII?�_qMclx05^d;Y2i>Q+b2k+1q0mi`3iGMkVTX`jc^> z?J)g81)AZmSmEOe#l%xFN-wT9&Dfb&V1A)tS)Ok)u##TqzE3w$mQCA3PAY~usLwt8 zrk#5+kys*S=d$sb`Y6ONFOHCEf*Gc;P+SvYR8b4V0sZwz*CBg9Pn5Q#lg;8Rv2Cn| PoCPYAOdDU3RN>)2mc7 + +int main(int argc, char* argv[]) +{ + printf("Hello World!\n"); + + return 0; +} diff --git a/tests/nvdla_bdma_mmio/Makefile b/tests/nvdla_bdma_mmio/Makefile new file mode 100644 index 0000000..f8fb117 --- /dev/null +++ b/tests/nvdla_bdma_mmio/Makefile @@ -0,0 +1,11 @@ +GCC=aarch64-linux-gnu-gcc +NVDLA_CMOD_INCLUDE = ../../models/nvdla_hw_cmod/cmod/include + +all: bdma + +bdma: + $(GCC) -o aarch64_nvdla_bdma_mmio nvdla_bdma_mmio.c -I$(NVDLA_CMOD_INCLUDE) -Wall + +clean: + rm -f aarch64_nvdla_bdma_mmio + diff --git a/tests/nvdla_bdma_mmio/aarch64_nvdla_bdma_mmio b/tests/nvdla_bdma_mmio/aarch64_nvdla_bdma_mmio new file mode 100755 index 0000000000000000000000000000000000000000..5863cb94aa483b01078efc2bc933238d6832fe0b GIT binary patch literal 14463 zcmeHOeQ;FQbw9f+gAB-$Ft(_T(G!pwf3Ol%Hp1ZYg!r&L0y{!(XdLHhwY#7-`yuZK z78PTwlunywCc_3#%sBmH#kezu&U8q|sjYs*IBuPc-5IOcrOY&K1mn1F?M~&mIH*CW zzjNd++((^L5X?_q?a~?t6Ae*Un%dKyn1>6=G_5fvq6@OVqYX zkp^p{YO?7Lx{Ve9xdErGTDa6TDbE?zQdS$j5Xvg92MrLkb;XpoYl@^454mJ}<-;~r zUEW)(NhwM7M*p&}6L;wLi96a=Wu`QKTor$e9Fr_py;93nuheoTww_*`N1 ztq9tnn6|l~?drE&s#pN~;!pE2w)a0h>I`Ey4*Or#5g z>mreCwEzCra4r*Gul;BJ%)4vPW6Bbb+d@^-?aNSSjN4xby!lb$M-6X(aQt_F@3lAY z%0Kk_d;iRBY?^g&zpSc7YpMJ62xIK;BAj(Ye|Y4n@4Rs2*Pr>;k?S8HTXyL0zkTG( zFKn(o@^AIEqxT%VCA{as&rW>z#hbu7=h2N8YnIjqU`uh@3v5s8T?T*Dhc7nx*bQEO zjsxo%_u-ojKH97XyvSs>X&I=`P%smK7O3TZB)$xJRznSpqk9ETM+xqKv>cT$lABL`BMv_Tx& z)z!JJ!`TpCzY!kr*jD~yJfQwzY?;9EeDPZt{vbs(N#l*}surlybHl(GM2!c5`HbpN0y~;%|0=>;e-vqkPMK1+?)J5M4`jm^l4fGFO^h(f|UGyr@!9dym zuYz9XqVER1P1ASK@cETExvxJB(V0sjd-C#XDt-XE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=Pb!zc{P^mFw{p zrN0u_ddhx^{tMurZ5%a!EnW4EyTk|kXGDc6KU8)bsNckM(6nkjWn6@=%wbpb%RWZo zpKHEp{gwGDfQwiFyKMb=O!HUH&sxP_iL?FL;&Z#YNY+>6y?d3O%KUbp;g|b4>DNPw zzcTOXI4q$t-+KHi_?Ke6$o@{boTe3y4NgA(XAM5?!@mjK5+_{cpD4UCuZ{w*qssa7 zL#4llUR`V}Eys+m_YD7szV-DJg*Q~>=MRjYuiU8htik-?W5VFWi)=;9{r4{vUYXwl zxcOi|{dQ}BFJ*ncIIJ`{`SQ{hrKd6uorb^8$NxBROL^%1c@lViurkj)ZS=JG^n8u^ zaR)Eg2Doy%Nt5XtpU#Q^xJKjga2WrpJ-r#?a}sx!eLkP zn3-=0g;!orskxBLs*gerM5F7X*-S3iY`zLH--zIORWqKTHHX9H|CJp4SqV6}h-UNa z!x>r=qcww{kNO1EMr}UTE6c-M)K=vt!S8^hK?r@a<>2Gp7!0H9pG}cs82`8+12&Pw)QUP zk)1pD?&xuP+P8J>V0G&2l4!1=x}!c(v2E8UCHiv}59D~_lW?b+SI(d~)!VgDdM znbcpVKs6pv&U~ekkLU7^=_9F@csj=YiK~a1s<~W?_Q#_KNxP)=Xl~vF>Gj3`b&Rjo z<&XNN#@FomkOrfi%Q$8ur1~_+%iZ}1dJ{{eokA`iQy=hn+smQk;H&R>ybS0A%>>7E zzZ@h|ANS}FfIM; +#include + +#include +#include +#include +#include +#include + +#include "arnvdla.uh" +#include "arnvdla.h" + +#define LOW32(addr) ((uint32_t)((addr) & 0xffffffff)) +#define HIGH32(addr) ((uint32_t)( ((addr)>>32) & 0xffffffff )) + +/* + * Platform Specific Params + */ +#define MEMORY_BASE 0xC0000000 +#define MEMORY_SIZE (0x800 * 4) + +#define NVDLA_MMIO_BASE 0x10200000 +#define NVDLA_MMIO_SIZE (0x10220000 - 0x10200000) + +typedef enum { + eDEVICE_MEM = 0, + eDEVICE_DLA, + eDEVICE_NUM +} nv_device; + +void* mmap_device(nv_device dev) +{ + size_t size = 0; + off_t offset = 0; + switch(dev) { + case eDEVICE_DLA: + size = NVDLA_MMIO_SIZE; + offset = NVDLA_MMIO_BASE; + break; + case eDEVICE_MEM: + size = MEMORY_SIZE; + offset = MEMORY_BASE; + break; + default: + printf("Unknown device\n"); + exit(EXIT_FAILURE); + } + + int fd = open("/dev/mem", O_RDWR); + if (fd < 0) { + perror("open /dev/mem failed!"); + exit(EXIT_FAILURE); + } + + void* device_mm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); + if (close(fd) < 0) { + perror("close failed!"); + } + if (device_mm == MAP_FAILED) { + perror("mmap DLA failed!"); + exit(EXIT_FAILURE); + } + return device_mm; +} + + +void munmap_device(nv_device dev, void* mm) +{ + size_t size = 0; + switch(dev) { + case eDEVICE_DLA: + size = NVDLA_MMIO_SIZE; + break; + case eDEVICE_MEM: + size = MEMORY_SIZE; + break; + default: + printf("Unknown device\n"); + exit(EXIT_FAILURE); + } + + if (munmap(mm, size) < 0) { + perror("mumap failed!"); + } +} + + +struct dla_reg { + int32_t offset; + uint32_t value; +}; + + +/* C x W x H */ +#define TENSOR_MAX_DIMS 3 + +struct tensor { + uint32_t dims; + uint32_t size[TENSOR_MAX_DIMS]; + uint32_t bits_per_element; + + /* Assume continuous memory */ + uint64_t base; +}; + +/* + * Prepare data buffer + */ +void test_data(struct tensor* in, struct tensor* out, void* mem_mm) +{ + if (mem_mm == NULL) { + printf("Invalid memory handle\n"); + exit(EXIT_FAILURE); + } + uint8_t* mm = (uint8_t*)mem_mm; + + in->dims = 2; + in->size[0] = 0x100; + in->size[1] = 8; + in->bits_per_element = 1; + in->base = MEMORY_BASE; + + int i = 0; + uint32_t* mem = (uint32_t*)(mm + in->base - MEMORY_BASE); + for (i = 0; i < 8*0x100/4; ++i) { + mem[i] = 0xABCD0000 + i; + } + + out->dims = 2; + out->size[0] = 0x100; + out->size[1] = 8; + out->bits_per_element = 1; + out->base = MEMORY_BASE + MEMORY_SIZE - 8*0x100 - 64; +} + +int test_check(struct tensor* out, void* mem_mm, uint8_t* dla_mmio) +{ + uint32_t* status = (uint32_t*)(dla_mmio + NVDLA_GLB_S_INTR_STATUS_0); + + int32_t loop = 100000; + volatile uint32_t int_status; + while( 1 ) { + int_status = *status; + if( (int_status >> NVDLA_GLB_S_INTR_STATUS_0_BDMA_DONE_STATUS0_SHIFT) & 1 ) { + printf("Get BDMA interrupt ...\n"); + break; + } + if(loop-- <= 0) { + printf("Polling timeout\n"); + return -1; + } + } + + int i = 0; + uint32_t* mem = (uint32_t*)((uint8_t*)mem_mm + out->base - MEMORY_BASE); + for (i = 0; i < 8*0x100/4; ++i) { + if (mem[i] != 0xABCD0000 + i) { + printf("Result mismatch mem[%d] = 0x%x, expect 0x%x\n", i, mem[i], 0xABCD0000+i); + return -1; + } + } + return 0; +} + +/* + * Fill DLA register configs. (test specific) + */ +const struct dla_reg* test_program(struct tensor* in, struct tensor* out) +{ + static struct dla_reg program[] = { + {NVDLA_BDMA_CFG_SRC_ADDR_HIGH_0, 0 }, /* set later */ + {NVDLA_BDMA_CFG_SRC_ADDR_LOW_0 , 0 }, /* set later */ + {NVDLA_BDMA_CFG_DST_ADDR_HIGH_0, 0 }, /* set later */ + {NVDLA_BDMA_CFG_DST_ADDR_LOW_0 , 0 }, /* set later */ + + {NVDLA_BDMA_CFG_DST_SURF_0 , 0x800}, /* DST SURF STRIDE */ + {NVDLA_BDMA_CFG_DST_LINE_0 , 0x100}, /* DST LINE STRIDE */ + {NVDLA_BDMA_CFG_SRC_SURF_0 , 0x800}, /* SRC SURF STRIDE */ + {NVDLA_BDMA_CFG_SRC_LINE_0 , 0x100}, /* SRC LINE STRIDE */ + {NVDLA_BDMA_CFG_SURF_REPEAT_0 , 0 }, /* SURF REPEAT NUM: 0 + 1 = 1*/ + {NVDLA_BDMA_CFG_LINE_REPEAT_0 , 7 }, /* LINE REPEAT NUM: 7 + 1 = 8*/ + {NVDLA_BDMA_CFG_LINE_0 , 7 }, /* LINE SIZE: (7+1)*32 = 256B*/ + {NVDLA_BDMA_CFG_CMD_0 , 3 }, /* DST=MC, SRC=MC */ + {NVDLA_BDMA_CFG_OP_0 , 1 }, + {NVDLA_BDMA_CFG_LAUNCH0_0 , 1 }, + {-1, 0} + }; + + program[0].value = HIGH32( in->base ); + program[1].value = LOW32 ( in->base ); + program[2].value = HIGH32( out->base ); + program[3].value = LOW32 ( out->base ); + return program; +} + + +int main(int argc, char* argv[]) +{ + void* mem_mm = mmap_device(eDEVICE_MEM); + void* dla_mm = mmap_device(eDEVICE_DLA); + + struct tensor in, out; + test_data(&in, &out, mem_mm); + const struct dla_reg* test = test_program(&in, &out); + + uint8_t* const dla_mmio = (uint8_t*)dla_mm; + uint32_t* reg = NULL; + + /* Program DLA hardware by MMIO */ + printf("Start programming...\n"); + const struct dla_reg* progs = test; + while (progs->offset != -1) { + reg = (uint32_t*)(dla_mmio + progs->offset); + *reg = progs->value; + printf("Write reg 0x%08x, value 0x%08x\n", progs->offset, progs->value); + ++progs; + } + printf("Finish programming...\n\n"); + + /* + Check regs + printf("Start checking...\n"); + progs = test; + while (progs->offset != -1) { + reg = (uint32_t*)(dla_mmio + progs->offset); + printf("Read reg 0x%08x, value 0x%08x\n", progs->offset, *reg); + if (progs->value != *reg) { + printf("data mismatch: expected 0x%08x\n", progs->value); + break; + } + ++progs; + } + printf("Finish checking...\n"); + */ + + /* Check result */ + /* + int result = 1; + */ + int result = test_check(&out, mem_mm, dla_mmio); + + munmap_device(eDEVICE_MEM, mem_mm); + munmap_device(eDEVICE_DLA, dla_mm); + + if (result < 0) { + return EXIT_FAILURE; + } + return 0; +} diff --git a/tests/socket/Makefile b/tests/socket/Makefile new file mode 100644 index 0000000..2341950 --- /dev/null +++ b/tests/socket/Makefile @@ -0,0 +1,13 @@ +ARMGCC=aarch64-linux-gnu-g++ +X64GCC=gcc + +all: server client + +server: + $(ARMGCC) -o server server.c -Wall + +client: + $(X64GCC) -o client client.c -Wall + +clean: + rm -f server client diff --git a/tests/socket/client b/tests/socket/client new file mode 100755 index 0000000000000000000000000000000000000000..cd46f4f92848d60a7f82b9abb3ee7e3a6b490eff GIT binary patch literal 9154 zcmeHMZERcB89ui2)wDP%D=bjfT8yyJsU}TB7s_DQN!{L5X(??2>?7Q`@lE34*pcrw zq)b4xP=r+q(Kexu?MEj~tdlkgZ5j#)(UewAC8iN7n5x1ygeZy&Xx#`^#s=Q=o_k*B z`qtLar2X5meBbjt=Y7xj_jx$lv(@kO33h&Qn;9>>{!mJjIreMQQ7F1xvQO19p_p&+8hM;%=2*rFyxb%EwYcabq&EcT@X~$@uzY zB9$FqKi;uv{igP?l@7Pba#Q@IyKQHmOo{8U35fE%3V-SY6mFe)=BndI=YILu&8zP{ z`B@V8XpzgU6qtiV%yluLJ81>UH@rz-Fh;6wO( z-8vBE(j~4O|D_7NS%If+SS}uc_8+9?-XyH_;Jv0T%<+URM(lLT5`*bf${e)CSk|^g zB4ygf7?!@_^b&&`pBPyR3;5P-{GomfUXPdZR6 zHVjA~jj4LYk!Wfhkf;`4ci#-Tcs1muUW<#T{?4w|#q$`ZunrgRp64_d?;hv6i>ExX z+vVbUPNJ~8T|5e0bOSElUEUEFucjnvGv?yelq>mh7k^nXb|EHQyqZd7=wmLv!KJTH zeo&_$sP0=968iobyL$e&2-GJ})E##z!CSbg6Doz~E%-L9)!-vMLQ46!3vkVw2~$($ z=Ok_;Oih%Zk$4?pYMT7B5?@Q0nk0W%;;RW$Q{<;4zML>ML4HEwdcsuo`7w$8gzE?o zNc>41FjaMam&AW3OjVrMBtB1=sy5#$@jHa6O7kI!&l0Ap%r{DWnlM#iUI1_SusiqK zJ$mjPee&H4yL!84XD-xhLZ3Z0A;s*k>ohSx48?_^hP7LSnEnMSyiZ?$7($<14C=Xa z_xt;gPa{5A(F^@YDX8#v!`cbrrU|kBvBd!N_1w$)vGd>1eRKM2i&+@IK#KbQ)AmBY zo;&H-zoYCYZoL`#71@=2u$+Gg8R#>`m|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 diff --git a/tests/socket/client.c b/tests/socket/client.c new file mode 100644 index 0000000..4a136ce --- /dev/null +++ b/tests/socket/client.c @@ -0,0 +1,60 @@ +// ================================================================ +// NVDLA Open Source Project +// +// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the +// NVDLA Open Hardware License; Check "LICENSE" which comes with +// this distribution for more information. +// ================================================================ + +// File Name: client.c + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXLINE 4096 + +int main(int argc, char** argv) +{ + int sockfd; + struct sockaddr_in servaddr; + + if( argc != 2){ + printf("usage: ./client \n"); + exit(0); + } + + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ + printf("create socket error: %s(errno: %d)\n", strerror(errno),errno); + exit(0); + } + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(6666); + if( inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){ + printf("inet_pton error for %s\n",argv[1]); + exit(0); + } + + if( connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0){ + printf("connect error: %s(errno: %d)\n",strerror(errno),errno); + exit(0); + } + + printf("Sent msg to server.\n"); + const char* sendline = "Hello QEMU"; + if( send(sockfd, sendline, strlen(sendline), 0) < 0) + { + printf("send msg error: %s(errno: %d)\n", strerror(errno), errno); + exit(0); + } + + close(sockfd); + exit(0); +} diff --git a/tests/socket/server b/tests/socket/server new file mode 100755 index 0000000000000000000000000000000000000000..0f4dd36415bb9e88e470efe1892acef3345d5048 GIT binary patch literal 14603 zcmeHOdvH`&8UOZfN*BT-p*%u)EN{E03vqA)&^=3MQ7+BZK6Q@zH`pEx%X^R zI?h!8$xZJ4&i6atpfMi27f5)vhUgNLP(lGaU-EK?A* zkyk2f?@XEBJF`M0m>yH*IH4%(5leb~O0Q4pG3`|aW6JfTy3tvu?9~|-a>QFiV5PVY zQj(=(^LwcfrF+K<7O5o?OeaYgn6lnos7K}exJRB6tYLq{#KlzQXUgq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TjS9tL}qrOyb$`uSbEQ{IdNn%}zJU8@Q5_ z@kz>ol+W%z63^}ruYIK7T$rJL7b)|=cJkEyjqySZ+)(A8kGKcFGVATm_3F{;wHW28 zUOLY4gfSMo6qN1wG`w2b(Q&r3S(BG|0qj-tHalVa`g;Rg+1K$_QQv9Msq7#t4rxDo zTs$h|v+*A*`~2R5%fsbAHe~s;$Ky-Fel{-c43?AapGEnh+EL0+08?vsj!(~!<;jP! z6D&3@=sUyMXFI&!iB}j}35z9+4JZ3m7NxC9(WP)JjeQBHub8KPiyjLlzf*qzTOddL1rB?+qod@WY1TBAI46f zkjI5*n%^n-P(tf%J2iZs!jEY9a)tM3_(sI@hKSErC4W+rZ&7%!hCin8%NqWi!aFPaxp>ujmKk~@;x1KYInUIO(kEi z+5hw~^2G}0=VY$hGG&M76S4LPGcAEARRB>=Ny@+&)Cc_DQcZr1#N4G7YTz|Y4byn9@Y*=Nl z+PD&HAgjY^mj&FLu=2|rD>kgFLMca%*yI5An(9rJ71j2p)vIe))!B6wmDQ`roY)5u zOty-Gi(MF&<=E69H(j_OdtKcIdoYr98>%Rdb%BOx80f91+#4bHa<~<3d>xwEIYCPp z-Px2Ij)ka}Ve$G@mdO@sDnsA5;j$oigSa5Mu+at4CX=KK!Im5>H}4VAB;1=(T$y5v zi3_1+k}g2oHIlWhL=z4r<91UZ7Q%>%?Jn-@b(=7Vp-9YbO@?VhN~Q^^(J^+o^+mM- z?u(J}9E?1O-7a#0soU)O`|TPv6sn?uWD +#include +#include +#include +#include +#include +#include +#include + +#define MAXLINE 4096 + +int main(int argc, char** argv) +{ + int listenfd, connfd; + struct sockaddr_in servaddr; + char buff[4096]; + int n; + + if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ + printf("create socket error: %s(errno: %d)\n", strerror(errno), errno); + exit(-1); + } + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(6666); + + if( bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1){ + printf("bind socket error: %s(errno: %d)\n",strerror(errno),errno); + exit(0); + } + + if( listen(listenfd, 10) == -1){ + printf("listen socket error: %s(errno: %d)\n",strerror(errno),errno); + exit(0); + } + + while(1){ + if( (connfd = accept(listenfd, (struct sockaddr*)NULL, NULL)) == -1){ + printf("accept socket error: %s(errno: %d)",strerror(errno),errno); + continue; + } + n = recv(connfd, buff, MAXLINE, 0); + buff[n] = '\0'; + printf("recv msg from client: %s\n", buff); + break; + } + + close(listenfd); +}