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 0000000..f4ccfe8 Binary files /dev/null and b/tests/hello/aarch64_hello differ diff --git a/tests/hello/hello.c b/tests/hello/hello.c new file mode 100644 index 0000000..6ac6723 --- /dev/null +++ b/tests/hello/hello.c @@ -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: hello.c + +#include + +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 0000000..5863cb9 Binary files /dev/null and b/tests/nvdla_bdma_mmio/aarch64_nvdla_bdma_mmio differ diff --git a/tests/nvdla_bdma_mmio/nvdla_bdma_mmio.c b/tests/nvdla_bdma_mmio/nvdla_bdma_mmio.c new file mode 100644 index 0000000..dea5857 --- /dev/null +++ b/tests/nvdla_bdma_mmio/nvdla_bdma_mmio.c @@ -0,0 +1,260 @@ +// ================================================================ +// 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_bdma_mmio.c + + +#include +#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 0000000..cd46f4f Binary files /dev/null and b/tests/socket/client differ 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 0000000..0f4dd36 Binary files /dev/null and b/tests/socket/server differ diff --git a/tests/socket/server.c b/tests/socket/server.c new file mode 100644 index 0000000..7b2d527 --- /dev/null +++ b/tests/socket/server.c @@ -0,0 +1,61 @@ +// ================================================================ +// 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: server.c + +#include +#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); +}