diff --git a/CMakeLists.txt b/CMakeLists.txt index a44492eb..0a08a0ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,17 @@ cmake_minimum_required(VERSION 3.2) project(cvm C CXX) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_C_COMPILER "/usr/bin/mips-linux-gnu-gcc") +set(CMAKE_CXX_COMPILER "/usr/bin/mips-linux-gnu-g++") +#set(CMAKE_EXE_LINKER_FLAGS "-static -march=mips64r2") +set(CMAKE_EXE_LINKER_FLAGS "-static -march=R4000") + +## Add architecture +add_compile_options(-Wall -static -march=R4000) + +## Assign specific system type +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR mips) # Utility functions include(cmake/util/Util.cmake) @@ -119,9 +130,11 @@ file(GLOB CVM_TOP_SRCS src/top/*.cc src/top/tensor/*.cc) list(APPEND RUNTIME_SRCS ${CVM_TOP_SRCS}) -add_library(${EXECUTE_NAME} SHARED ${RUNTIME_SRCS}) +#add_library(${EXECUTE_NAME} SHARED ${RUNTIME_SRCS}) +add_library(${EXECUTE_NAME} STATIC ${RUNTIME_SRCS}) target_link_libraries(${EXECUTE_NAME} ${CVM_RUNTIME_LINKER_LIBS}) list(APPEND CVM_SRCS ${RUNTIME_SRCS}) -add_library(${LIBRARY_NAME} SHARED ${CVM_SRCS}) +#add_library(${LIBRARY_NAME} SHARED ${CVM_SRCS}) +add_library(${LIBRARY_NAME} STATIC ${CVM_SRCS}) target_link_libraries(${LIBRARY_NAME} ${CVM_RUNTIME_LINKER_LIBS}) diff --git a/docs/cvm/install.md b/docs/cvm/install.md index 8d6a8695..29417eee 100644 --- a/docs/cvm/install.md +++ b/docs/cvm/install.md @@ -127,10 +127,10 @@ ability of importing cvm and mrt. Use the command to install CVM python requirements: ``` bash -pip install -r install/requirements.txt +pip install -r conf/requirements.txt ``` -More dependency details refer to `install/requirements.txt` please. +More dependency details refer to `conf/requirements.txt` please. #### MRT requirements diff --git a/docs/mrt/mnist_tutorial.md b/docs/mrt/mnist_tutorial.md index 0dd6844e..557a40e2 100644 --- a/docs/mrt/mnist_tutorial.md +++ b/docs/mrt/mnist_tutorial.md @@ -26,5 +26,6 @@ python3 python/mrt/main2.py python/mrt/model_zoo/mnist.ini ``` `main2.py` does the convert job and `mnist.ini` provides necessary config information, including full path to the model, input shape, dataset, etc. The converted model is defaultly stored in the same directory as input model directory, as specified by `Model_dir` in `DEFAULT` section of the `ini` file. +If run in gpu mode, you should change device settings as `Device_type=gpu` and set `Device_ids=0` in `mnist.ini` All the pre-quantized model configuration file is stored in `python/mrt/model_zoo`, and the file `config.example.ini` expositions all the key meanings and value. diff --git a/tests/Makefile b/tests/Makefile index c23b5b80..5591857d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,17 +1,16 @@ - -all: test_model_cpu test_model_gpu test_model_formal test_op +all: test_model_cpu test_model_formal test_model_gpu test_model_formal test_op test_model_cpu: test_model.cc - g++ -o test_model_cpu test_model.cc -I../include -L../build/cpu/ -lcvm_runtime_cpu --std=c++11 -pthread -fopenmp -I../ -ldl -g -DUSE_GPU=0 -DCVM_PROFILING -fsigned-char + mips-linux-gnu-g++ --march=R4000 -static -o test_model_cpu test_model.cc -I../include -L../build/cpu/ -lcvm_runtime_cpu --std=c++11 -pthread -fopenmp -I../ -ldl -g -DUSE_GPU=0 -DCVM_PROFILING -fsigned-char test_model_formal: test_model.cc - g++ -o test_model_formal test_model.cc -I../include -L../build/formal/ -lcvm_runtime_formal --std=c++11 -pthread -fopenmp -I../ -ldl -g -DUSE_GPU=0 -fsigned-char + mips-linux-gnu-g++ --march=R4000 -static -o test_model_formal test_model.cc -I../include -L../build/formal/ -lcvm_runtime_formal --std=c++11 -pthread -fopenmp -I../ -ldl -g -DUSE_GPU=0 -fsigned-char test_model_gpu: test_model.cc - g++ -o test_model_gpu test_model.cc -I../include -L../build/cpu/ -L../build/gpu/ -lcvm_runtime_cuda -lcudart -lcuda --std=c++11 -pthread -fopenmp -I./ -ldl -g -DUSE_GPU=1 -DCVM_PROFILING -fsigned-char + mips-linux-gnu-g++ --march=R4000 -static -o test_model_gpu test_model.cc -I../include -L../build/cpu/ -L../build/gpu/ -lcvm_runtime_cuda -lcudart -lcuda --std=c++11 -pthread -fopenmp -I./ -ldl -g -DUSE_GPU=1 -DCVM_PROFILING -fsigned-char test_op: - g++ -o test_op test_op.cc -I../include -L../build/gpu -lcvm_runtime_cuda -lcuda -lcudart --std=c++11 -pthread -fopenmp -I../ -ldl -DCVM_PROFILING -fsigned-char -DUSE_GPU + mips-linux-gnu-g++ --march=R4000 -static -o test_op test_op.cc -I../include -L../build/gpu -lcvm_runtime_cuda -lcuda -lcudart --std=c++11 -pthread -fopenmp -I../ -ldl -DCVM_PROFILING -fsigned-char -DUSE_GPU clean: rm -f test_model_cpu test_model_formal test_model_gpu test_op diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..eb507480 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,53 @@ +# cvm-runtime test_model +CVM-Runtime Test_Model + +## prerequisite +1. prepare models files under data1 +``` +/data1 +`-- lz_model_storage + `-- animal10 + `── data + |── params + |── result_0.txt + `── symbol + `── result_0.txt +`-- std_out + `-- yolo_tfm + |-- data.npy + |-- params + |-- result_0.txt + `-- symbol + ... +``` + +2. prepare qemu envs + - for qemu mips gcc cross compile build + - using qemu-mips docker containers can be: `docker run -it -v $PATH_TO_PROJECT:/project asmimproved/qemu-mips` + - `apt install gcc-mips-linux-gnu g++-mips-linux-gnu` + - `apt install qemu-system qemu-system-mips qemu-system-mipsel` + - `apt install qemu-user-static` + - using mipsel for little-endian + + +## build process +- build libcvm_runtime.so / libcvm_runtime.a +- rename libcvm_runtime.so / libcvm_runtime.a with '_cpu' '_formal' suffix +- append the path to LD_LIBRARY_PATH +- build test_model.cc + +## execute bin +- check binary/elf: `file ./test_model_formal` +- LD_LIBRARY_PATH="/path_to_libcvm_runtime_library":${LD_LIBRARY_PATH} qemu-mips ./test_model_arch0 +- LD_LIBRARY_PATH="/path_to_libcvm_runtime_library":${LD_LIBRARY_PATH} qemu-mips ./test_model_arch1 +After running 2 Architectures, the result file can be compared. + +- static run: `LD_LIBRARY_PATH="/path_to_libcvm_runtime_library":${LD_LIBRARY_PATH} qemu-mips-static ./test_model_arch0` + + +# To execute under dynamic library (so: shared library) +- using mips32 big endian +- debian-mips-qemu, install img and start kernel. has ld.so.1 (single core mips cpu) +- scp -R cvm-runtime -P 2222 debian@127.0.0.1:/home/debian +- ssh -p 2222 debian@127.0.0.1 # with password debian +- build libso, build test_model, and execute binary. diff --git a/tests/cpp_mips_demo/.gitignore b/tests/cpp_mips_demo/.gitignore new file mode 100644 index 00000000..3360b719 --- /dev/null +++ b/tests/cpp_mips_demo/.gitignore @@ -0,0 +1,3 @@ +build/ +build_cpu/ +demo2 diff --git a/tests/cpp_mips_demo/CMakeLists.txt b/tests/cpp_mips_demo/CMakeLists.txt new file mode 100644 index 00000000..0a272448 --- /dev/null +++ b/tests/cpp_mips_demo/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.2) +project(cvm C CXX) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_C_COMPILER "/usr/bin/mips-linux-gnu-gcc") +set(CMAKE_CXX_COMPILER "/usr/bin/mips-linux-gnu-g++") +#add_compile_options(-Wall -Werror -static -mips32r5 -O3) +add_compile_options(-Wall -Werror -static -mfp32 -march=R2000) +# 指定目标系统的类型 +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR mips) +set(CMAKE_EXE_LINKER_FLAGS "-static -mfp32 -march=R2000") + +# Utility functions +include(conf.cmake) + +include_directories("include") + +#file(GLOB CVM_TOP_SRCS src/*.cc) + +#add_library(demo SHARED src/main.cc) +#target_link_libraries(demo atomic) + +add_executable(main src/main.cc) +target_compile_options(main + PUBLIC -Wall -static -mfp32 -march=R2000) +target_link_libraries(main atomic) diff --git a/tests/cpp_mips_demo/CMakeLists.x86.txt b/tests/cpp_mips_demo/CMakeLists.x86.txt new file mode 100644 index 00000000..ed984862 --- /dev/null +++ b/tests/cpp_mips_demo/CMakeLists.x86.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.2) +project(cvm C CXX) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Utility functions +include(conf.cmake) + +include_directories("include") + +file(GLOB CVM_TOP_SRCS src/*.cc) + +add_library(demo SHARED src/main.cc) +target_link_libraries(demo atomic) + +add_executable(main src/main.cc) +target_link_libraries(main atomic) diff --git a/tests/cpp_mips_demo/conf.cmake b/tests/cpp_mips_demo/conf.cmake new file mode 100644 index 00000000..e69de29b diff --git a/tests/cpp_mips_demo/include/cool.h b/tests/cpp_mips_demo/include/cool.h new file mode 100644 index 00000000..43faac53 --- /dev/null +++ b/tests/cpp_mips_demo/include/cool.h @@ -0,0 +1,6 @@ +#include + +int print_cool_(int input){ + printf("cool mips\n"); + return input; +} diff --git a/tests/cpp_mips_demo/src/main.cc b/tests/cpp_mips_demo/src/main.cc new file mode 100644 index 00000000..9c6473a2 --- /dev/null +++ b/tests/cpp_mips_demo/src/main.cc @@ -0,0 +1,8 @@ +#include +#include + +int main(){ + printf("hello cpp_mips_demo\n"); + print_cool_(30); + return 0; +} diff --git a/tests/test_model.cc b/tests/test_model.cc index 9a565f89..321c97b1 100644 --- a/tests/test_model.cc +++ b/tests/test_model.cc @@ -33,9 +33,9 @@ void read_data(const char *filename, vector &shape, vector args; std::vector arg_values; std::vector arg_tcodes; - std::vector shape_data; + std::vector shape_data; }; int run_LIF(string model_root, int device_type = 0) { @@ -181,11 +181,11 @@ int run_LIF(string model_root, int device_type = 0) { CHECK_STATUS(status, "free model failed"); if (json_path.find("yolo") != string::npos || json_path.find("ssd") != string::npos) { - uint64_t n_bytes = 4; - uint64_t ns = output.size() / n_bytes; + uint32_t n_bytes = 4; + uint32_t ns = output.size() / n_bytes; std::cout << "yolo output size = " << ns << " n_bytes = " << n_bytes << "\n"; int32_t* int32_output = static_cast((void*)output.data()); - for (auto i = 0; i < std::min(60UL, ns); i++) { + for (auto i = 0; i < std::min(60UL, ns); i++) { std::cout << (int32_t)int32_output[i] << " "; if ((i + 1) % 6 == 0) std::cout << "\n"; @@ -201,7 +201,7 @@ int run_LIF(string model_root, int device_type = 0) { std::cout << "\n"; } else { std::cout << "output size = " << output.size() << "\n"; - for (auto i = 0; i < std::min(6UL * 10, output.size()); i++) { + for (auto i = 0; i < std::min(6UL * 10, output.size()); i++) { std::cout << (int32_t)output[i] << " "; } std::cout << "\n"; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy