From 272cfc14f2e719e2379575f0b32d4ec537acdd64 Mon Sep 17 00:00:00 2001 From: iotwins Date: Tue, 19 Sep 2023 20:03:12 +0800 Subject: [PATCH 1/2] add devkit example --- .../examples/helloworld/CMakeLists.txt | 39 ++ .../hpc-sdk/examples/helloworld/README.md | 52 ++ .../hpc-sdk/examples/helloworld/README_en.md | 52 ++ .../examples/helloworld/src/hello_world.c | 29 + .../examples/hmpi/bcast/CMakeLists.txt | 39 ++ .../hpc-sdk/examples/hmpi/bcast/README.md | 64 +++ .../hpc-sdk/examples/hmpi/bcast/README_en.md | 68 +++ .../examples/hmpi/bcast/src/bcast_demo.c | 100 ++++ .../hpc-sdk/examples/kml/blas/CMakeLists.txt | 77 +++ .../hpc-sdk/examples/kml/blas/README.md | 71 +++ .../hpc-sdk/examples/kml/blas/README_en.md | 72 +++ .../hpc-sdk/examples/kml/blas/src/blas_demo.c | 113 ++++ .../hpc-sdk/examples/kml/fft/CMakeLists.txt | 65 +++ .../hpc-sdk/examples/kml/fft/README.md | 61 ++ .../hpc-sdk/examples/kml/fft/README_en.md | 61 ++ .../hpc-sdk/examples/kml/fft/src/fft_demo.c | 138 +++++ .../examples/kml/lapack/CMakeLists.txt | 53 ++ .../hpc-sdk/examples/kml/lapack/README.md | 52 ++ .../hpc-sdk/examples/kml/lapack/README_en.md | 53 ++ .../examples/kml/lapack/src/lapack_demo.c | 154 +++++ .../hpc-sdk/examples/kml/math/CMakeLists.txt | 64 +++ .../hpc-sdk/examples/kml/math/README.md | 61 ++ .../hpc-sdk/examples/kml/math/README_en.md | 61 ++ .../hpc-sdk/examples/kml/math/src/math_demo.c | 39 ++ .../examples/kml/spblas/CMakeLists.txt | 65 +++ .../hpc-sdk/examples/kml/spblas/README.md | 61 ++ .../hpc-sdk/examples/kml/spblas/README_en.md | 63 ++ .../examples/kml/spblas/src/spblas_demo.c | 142 +++++ .../hpc-sdk/module/bisheng_modulefiles | 23 + .../hpc-sdk/module/gcc_modulefiles | 24 + .../hpc-sdk/module/hmpi_modulefiles | 24 + .../hpc-sdk/script/README.md | 113 ++++ .../hpc-sdk/script/README_en.md | 110 ++++ .../hpc-sdk/script/common_fun.sh | 527 +++++++++++++++++ .../hpc-sdk/script/configure_environment.sh | 70 +++ .../hpc-sdk/script/const.conf | 41 ++ .../hpc-sdk/script/const.sh | 69 +++ .../hpc-sdk/script/install.sh | 544 ++++++++++++++++++ .../mpi/devkitdemo-main/Hyper_tuner/README.md | 19 + .../cpu_branch_prediction_after.cpp" | 29 + .../cpu_branch_prediction_before.cpp" | 29 + .../testdemo/Know-how/core_bound.c | 40 ++ .../testdemo/Know-how/memory_bound.c | 60 ++ .../testdemo/Know-how/omp_utilization.c | 48 ++ .../Hyper_tuner/testdemo/Know-how/send_recv | Bin 0 -> 71632 bytes .../testdemo/Know-how/send_recv.cpp | 31 + .../Hyper_tuner/testdemo/Know-how/serial_time | Bin 0 -> 71904 bytes .../testdemo/Know-how/serial_time.c | 45 ++ .../testdemo/Know-how/socket_bandwidth | Bin 0 -> 71824 bytes .../testdemo/Know-how/socket_bandwidth.c | 39 ++ .../Hyper_tuner/testdemo/Know-how/utils.h | 105 ++++ .../concatenate_string.py" | 34 ++ .../testdemo/cache/cache_hit/cache_hit.c | 58 ++ .../testdemo/cache/cache_miss/cache_miss.c | 37 ++ .../testdemo/cache/cache_miss/miss_start.sh | 20 + .../testdemo/falsesharing/falsesharing.c | 169 ++++++ .../testdemo/falsesharing/falsesharing_mod.c | 170 ++++++ .../falsesharing/falsesharing_start.sh | 20 + .../Hyper_tuner/testdemo/io/io_continuum.c | 113 ++++ .../Hyper_tuner/testdemo/io/io_wait.c | 167 ++++++ .../testdemo/java_perf_test/README.md | 24 + .../testdemo/java_perf_test/pom.xml | 62 ++ .../example/demo_test/DemoApplication.java | 13 + .../demo_test/demo/GcTestController.java | 78 +++ .../example/demo_test/demo/HotMethodDemo.java | 40 ++ .../example/demo_test/demo/MetaspaceTest.java | 43 ++ .../example/demo_test/demo/MethodDemoOne.java | 41 ++ .../demo_test/demo/TestController.java | 45 ++ .../src/main/resources/application.yml | 11 + .../testdemo/lock/pthread_atomic.c | 54 ++ .../Hyper_tuner/testdemo/lock/pthread_mutex.c | 61 ++ .../testdemo/lock/pthread_mutex_long.c | 69 +++ .../testdemo/lock/pthread_mutex_long_mod.c | 68 +++ .../Hyper_tuner/testdemo/lock/readme.txt | 10 + .../Hyper_tuner/testdemo/mem-leak/mem_leak.c | 37 ++ .../testdemo/mem-leak/mem_leak_fix.c | 39 ++ .../Hyper_tuner/testdemo/miss/cache_hit.c | 35 ++ .../Hyper_tuner/testdemo/miss/cache_miss.c | 30 + .../Hyper_tuner/testdemo/miss/llc_miss.c | 36 ++ .../testdemo/miss/llc_miss_clean.c | 50 ++ .../Hyper_tuner/testdemo/multiply/multiply.c | 87 +++ .../testdemo/multiply/multiply_simd.c | 105 ++++ .../testdemo/multiply/multiply_start.sh | 20 + .../testdemo/multiply/multiplysimd_start.sh | 20 + .../testdemo/omp-mpi/memory_bound.c | 41 ++ .../testdemo/omp-mpi/memory_bound_mod.c | 44 ++ .../Hyper_tuner/testdemo/omp-mpi/ring.c | 42 ++ .../Hyper_tuner/testdemo/omp-mpi/utils.h | 105 ++++ .../Hyper_tuner/testdemo/omp/cal_pi.cpp | 22 + .../Hyper_tuner/testdemo/omp/omp_test.cpp | 47 ++ .../Hyper_tuner/testdemo/omp/omp_test1.cpp | 34 ++ .../Hyper_tuner/testdemo/omp/omp_test2.cpp | 34 ++ .../Hyper_tuner/testdemo/omp/omp_test3.cpp | 47 ++ .../testdemo/pthread_bind/pthreadbind.c | 63 ++ .../testdemo/pthread_bind/pthreadnobind.c | 59 ++ .../Hyper_tuner/testdemo/test_swap.c | 124 ++++ .../README.md" | 13 + .../README.md" | 1 + .../TestMemoryLeakKo.java" | 32 ++ .../DeadLock.java" | 37 ++ .../README.md" | 3 + .../README.md" | 7 + .../Lock.java" | 29 + .../README.md" | 1 + .../pthread_atomic.c" | 54 ++ .../pthread_mutex.c" | 61 ++ .../readme.txt" | 14 + examples/mpi/devkitdemo-main/LICENSE | 176 ++++++ .../devkitdemo-main/Porting_advisor/README.md | 17 + .../testdemo/asm_trans/all_asm/Makefile | 24 + .../testdemo/asm_trans/all_asm/main.c | 26 + .../testdemo/asm_trans/all_asm/test.s | 40 ++ .../testdemo/asm_trans/mult_inline_asm/gcd.c | 52 ++ .../asm_trans/single_inline_asm/swap.c | 38 ++ .../testdemo/byte_check/Makefile | 28 + .../testdemo/byte_check/bytecheck.cpp | 146 +++++ .../testdemo/byte_check/bytecheck.hpp | 50 ++ .../testdemo/code_migration/code/Makefile | 35 ++ .../testdemo/code_migration/code/file_lock.c | 146 +++++ .../testdemo/code_migration/code/file_lock.h | 68 +++ .../testdemo/code_migration/code/interface.s | 42 ++ .../testdemo/code_migration/code/ksw.c | 35 ++ .../testdemo/code_migration/code/ksw.h | 23 + .../testdemo/code_migration/code_mod/Makefile | 35 ++ .../code_migration/code_mod/file_lock.c | 186 ++++++ .../code_migration/code_mod/file_lock.h | 69 +++ .../code_migration/code_mod/interface.s | 105 ++++ .../testdemo/code_migration/code_mod/ksw.c | 39 ++ .../testdemo/code_migration/code_mod/ksw.h | 28 + .../testdemo/precheck/Makefile | 36 ++ .../testdemo/precheck/func001.c | 36 ++ .../testdemo/precheck/func002.c | 34 ++ .../testdemo/precheck/func003.c | 31 + .../testdemo/precheck/func004.c | 38 ++ .../testdemo/weak_consistency/atomic/Makefile | 15 + .../weak_consistency/atomic/atomic.cpp | 50 ++ .../testdemo/weak_consistency/common/Makefile | 15 + .../testdemo/weak_consistency/common/common.c | 50 ++ .../testdemo/weak_consistency/lock/Makefile | 16 + .../testdemo/weak_consistency/lock/lock.c | 56 ++ examples/mpi/devkitdemo-main/README.md | 2 + .../examples/hmpi/bcast/CMakeLists.txt | 31 + .../hpc-sdk/examples/hmpi/bcast/README.md | 64 +++ .../hpc-sdk/examples/hmpi/bcast/README_en.md | 68 +++ .../examples/hmpi/bcast/src/bcast_demo | Bin 0 -> 71856 bytes .../examples/hmpi/bcast/src/bcast_demo.c | 92 +++ .../hpc-sdk/examples/kml/blas/CMakeLists.txt | 42 ++ .../hpc-sdk/examples/kml/blas/README.md | 60 ++ .../hpc-sdk/examples/kml/blas/README_en.md | 61 ++ .../hpc-sdk/examples/kml/blas/src/blas_demo.c | 111 ++++ .../hpc-sdk/examples/kml/fft/CMakeLists.txt | 42 ++ .../hpc-sdk/examples/kml/fft/README.md | 56 ++ .../hpc-sdk/examples/kml/fft/README_en.md | 56 ++ .../hpc-sdk/examples/kml/fft/src/fft_demo.c | 112 ++++ .../examples/kml/lapack/CMakeLists.txt | 42 ++ .../hpc-sdk/examples/kml/lapack/README.md | 52 ++ .../hpc-sdk/examples/kml/lapack/README_en.md | 53 ++ .../examples/kml/lapack/src/lapack_demo.c | 152 +++++ .../hpc-sdk/examples/kml/math/CMakeLists.txt | 43 ++ .../hpc-sdk/examples/kml/math/README.md | 56 ++ .../hpc-sdk/examples/kml/math/README_en.md | 56 ++ .../hpc-sdk/examples/kml/math/src/math_demo.c | 36 ++ .../examples/kml/spblas/CMakeLists.txt | 42 ++ .../hpc-sdk/examples/kml/spblas/README.md | 56 ++ .../hpc-sdk/examples/kml/spblas/README_en.md | 60 ++ .../examples/kml/spblas/src/spblas_demo.c | 140 +++++ .../hpc-sdk/module/bisheng_modulefiles | 23 + .../hpc-sdk/module/gcc_modulefiles | 24 + .../hpc-sdk/module/hmpi_modulefiles | 24 + .../devkitdemo-main/hpc-sdk/script/README.md | 113 ++++ .../hpc-sdk/script/README_en.md | 110 ++++ .../hpc-sdk/script/common_fun.sh | 530 +++++++++++++++++ .../hpc-sdk/script/configure_environment.sh | 70 +++ .../devkitdemo-main/hpc-sdk/script/const.conf | 39 ++ .../devkitdemo-main/hpc-sdk/script/const.sh | 68 +++ .../devkitdemo-main/hpc-sdk/script/install.sh | 497 ++++++++++++++++ examples/python/create-rankfile.py | 22 + examples/shell/get-gdb-trace.sh | 10 + 178 files changed, 11639 insertions(+) create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/src/hello_world.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/src/blas_demo.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/src/fft_demo.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/src/lapack_demo.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/src/math_demo.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/src/spblas_demo.c create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/bisheng_modulefiles create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/gcc_modulefiles create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/hmpi_modulefiles create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README_en.md create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/common_fun.sh create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/configure_environment.sh create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.conf create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.sh create mode 100644 examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/install.sh create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/README.md create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/CPU\345\210\206\346\224\257\351\242\204\346\265\213/cpu_branch_prediction_after.cpp" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/CPU\345\210\206\346\224\257\351\242\204\346\265\213/cpu_branch_prediction_before.cpp" create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/core_bound.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/memory_bound.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/omp_utilization.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/send_recv create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/send_recv.cpp create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/serial_time create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/serial_time.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/socket_bandwidth create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/socket_bandwidth.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/utils.h create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Python\346\213\274\346\216\245\345\255\227\347\254\246\344\270\262\347\232\204\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/concatenate_string.py" create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_hit/cache_hit.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/cache_miss.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/miss_start.sh create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_mod.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_start.sh create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_continuum.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_wait.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/README.md create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/pom.xml create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/DemoApplication.java create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/GcTestController.java create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/HotMethodDemo.java create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MetaspaceTest.java create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MethodDemoOne.java create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/TestController.java create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/resources/application.yml create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_atomic.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long_mod.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/readme.txt create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak_fix.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_hit.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_miss.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss_clean.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_simd.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_start.sh create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiplysimd_start.sh create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound_mod.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/ring.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/utils.h create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/cal_pi.cpp create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/omp_test.cpp create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/omp_test1.cpp create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/omp_test2.cpp create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/omp_test3.cpp create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/pthread_bind/pthreadbind.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/pthread_bind/pthreadnobind.c create mode 100644 examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/test_swap.c create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204GC\346\227\245\345\277\227\350\260\203\344\274\230\345\256\236\350\267\265/README.md" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/README.md" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/TestMemoryLeakKo.java" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/DeadLock.java" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/README.md" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\347\203\255\347\202\271\345\207\275\346\225\260\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/Lock.java" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_atomic.c" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_mutex.c" create mode 100644 "examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/readme.txt" create mode 100644 examples/mpi/devkitdemo-main/LICENSE create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/README.md create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/main.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/test.s create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/mult_inline_asm/gcd.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/single_inline_asm/swap.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.cpp create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.hpp create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.h create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/interface.s create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.h create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.h create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/interface.s create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.h create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func001.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func002.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func003.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func004.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/atomic.cpp create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/common.c create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/Makefile create mode 100644 examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/lock.c create mode 100644 examples/mpi/devkitdemo-main/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/src/blas_demo.c create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/src/fft_demo.c create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/src/lapack_demo.c create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/src/math_demo.c create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/CMakeLists.txt create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/src/spblas_demo.c create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/module/bisheng_modulefiles create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/module/gcc_modulefiles create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/module/hmpi_modulefiles create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/README.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/README_en.md create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/common_fun.sh create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/configure_environment.sh create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/const.conf create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/const.sh create mode 100644 examples/mpi/devkitdemo-main/hpc-sdk/script/install.sh create mode 100644 examples/python/create-rankfile.py create mode 100644 examples/shell/get-gdb-trace.sh diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/CMakeLists.txt new file mode 100644 index 0000000..29ac5eb --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) + +project(hello_world C) + +# Add source files +set(SRC src/hello_world.c) + +# Set target file +set(TARGET_FILE hello_world) + +# Set Compiler +set(CMAKE_C_COMPILER mpicc) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README.md new file mode 100644 index 0000000..c8805bd --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README.md @@ -0,0 +1,52 @@ +# **HPC sample demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. 提供HPC场景Hello world工程; +2. 通过鲲鹏开发框架创建该工程,samples目录下会包含所有kml demo工程,供开发者参考。 + +## 使用依赖 + +1. 通过[HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/)安装HMPI库,编译器,数学库。 + +## 使用教程 + + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/examples/helloworld/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + # 单独执行 + ./hello_world + # mpirun 执行 + mpirun -n rank数 hello_world + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README_en.md new file mode 100644 index 0000000..e6956d3 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/README_en.md @@ -0,0 +1,52 @@ +# **HPC sample demo** + +English | [简体中文](README.md) + +## Introduction + +1. Provide the Hello World project in the HPC scenario. +2. When a project is created using the Kunpeng Development Framework Plugin, the samples directory provides all kml demo projects for reference. + +## Dependencies + +1. Using the [HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/) to install the HMPI library, compiler, and math library. + +## Guidance + + +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/examples/helloworld/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + # Run the demo independently. + ./hello_world + # Run the demo using the mpirun command. + mpirun -n rank numbers hello_world + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/src/hello_world.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/src/hello_world.c new file mode 100644 index 0000000..ea5831f --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/helloworld/src/hello_world.c @@ -0,0 +1,29 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * A sample demo. Sample directory contains all kml demos. + * Create: 2022-11-21 + */ + #include + #include + #include + + int main() + { + MPI_Init(NULL, NULL); + printf("Hello world.\n"); + MPI_Finalize(); + return EXIT_SUCCESS; + } \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt new file mode 100644 index 0000000..6410d57 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(hmpi_demo C) + +# Add source files +set(SRC src/bcast_demo.c) + +# Set target file +set(TARGET_FILE bcast_demo) + +# Set Compiler +set(CMAKE_C_COMPILER mpicc) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +# Set debug compilation option +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README.md new file mode 100644 index 0000000..dbb641e --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README.md @@ -0,0 +1,64 @@ +# **Hyper MPI broadcast functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [Hyper MPI](https://www.hikunpeng.com/developer/hpc/hypermpi) + 是整个高性能计算解决方案的关键组件,它实现了并行计算的网络通讯功能,可以用来支持制造、气象、超算中心等应用场景,同时该通信库也可扩展应用于AI、大数据等通用领域。Message Passing + Interface(MPI)是支持多编程语言编程的并行计算通讯应用接口,具有高性能、大规模性、可移植性、可扩展性等特点。 +2. [Hyper MPI](https://www.hikunpeng.com/developer/hpc/hypermpi) 是基于Open MPI 4.1.1和Open UCX + 1.10.1,支持MPI-V3.1标准的并行计算API接口,新增了优化的集合通信框架。同时,Hyper MPI对数据密集型和高性能计算提供了网络加速能力,使能了节点间高速通信网络和节点内共享内存机制,以及优化的集合通信算法。Hyper + MPI的COLL UCX通信框架能够支持的最大数据包长度为2^32字节。 +3. **Hyper MPI broadcast functions demo** 用于展示对MPI_Bcast集合通信的优化。 + +## 使用依赖 + +1. 确保已安装 **Hyper MPI 1.1.1** +2. 确保已安装 **HMPI** 对应版本的编译器:**GCC 9.3.0** 或 **BiSheng 2.1.0** + +## 使用教程 + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/hmpi/bcast/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + # 使用普通用户执行 + mpirun -n 4 bcast_demo + # 使用普通用户执行,并屏蔽掉coll ucx + mpirun -n 4 -mca coll ^ucx bcast_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` + +## 命令参考链接 + +1. [Non-coll模式](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0014.html) +2. [Coll模式](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0015.html) +3. [集合操作算法选择说明](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0016.html) +4. [命令说明及示例](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0031.html) diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README_en.md new file mode 100644 index 0000000..78c0567 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/README_en.md @@ -0,0 +1,68 @@ +# **Hyper MPI broadcast functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [Hyper MPI](https://www.hikunpeng.com/en/developer/hpc/hypermpi) is key to the HPC solution. It implements network + communication for parallel computing and is applicable to manufacturing, meteorology, supercomputing, AI, and big + data. Message Passing Interface (MPI) supports multi-language programming, featuring high performance, large scale, + portability, and scalability. +2. [Hyper MPI](https://www.hikunpeng.com/en/developer/hpc/hypermpi) based on Open MPI 4.1.1 and Open UCX 1.10.1, Hyper + MPI supports the parallel computing API interface of the MPI-V3.1 standard, and optimizes the collection + communication framework. In addition, Hyper MPI accelerates the network for data-intensive and high-performance + computing, and enables a high-speed communication network and shared memory mechanism between nodes, and an optimized + collection communication algorithm. The maximum data packet length supported by the COLL UCX communication framework + of Hyper MPI is 232 bytes. +3. The **Hyper MPI broadcast functions demo** shows a code example of MPI_Bcast. + +## Dependencies + +1. Ensure that **Hyper MPI 1.1.1** has been installed. +2. Ensure that **GCC 9.3.0** or **BiSheng 2.1.0** has been installed. + +## Guidance + +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/hmpi/bcast/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + # Non-root user run demo. + mpirun -n 4 bcast_demo + # non-root user run demo with non-coll mode. + mpirun -n 4 -mca coll ^ucx bcast_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` + +## Command Reference Link + +1. [Non-coll Mode](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0014.html) +2. [Coll Mode](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0015.html) +3. [Algorithm Selection for Set Operations](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0016.html) +4. [Command Description and Example](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0031.html) \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c new file mode 100644 index 0000000..fbf73f1 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c @@ -0,0 +1,100 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: KML blas library demo + * Refrence: www.mpitutorial.com + * Create: 2022-05-17 + */ +#include +#include +#include +#include + +int InputParameterParse(int argc, char** argv) +{ + if (argc == 1) + { + return 0; + } + // Parameter must be 1 + printf("Invalid parameter.\n"); + return -1; +} + +double BcastData(int trialsNum, int elementsNum, int* sendData) +{ + if (trialsNum == 0) + { + return 0; + } + double totalMPIBcastTime = 0.0; + + int i; + for (i = 0; i < trialsNum; i++) + { + // An MPI barrier completes after all group members have entered the barrier. + MPI_Barrier(MPI_COMM_WORLD); + // MPI_Wtime returns a floating-point number of seconds, representing elapsed wall-clock time since some time in the past. + totalMPIBcastTime -= MPI_Wtime(); + // MPI_Bcast broadcasts a message from the process with rank root to all processes of the group, itself included. + MPI_Bcast(sendData, elementsNum, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); + totalMPIBcastTime += MPI_Wtime(); + } + return totalMPIBcastTime; +} + +int main(int argc, char** argv) +{ + if (InputParameterParse(argc, argv) != 0) + { + return -1; + } + // Send data numbers. + int elementsNum = 10000; + int trialsNum = 10; + int rankNum; + int sizeOfInt = sizeof(int); + double totalMPIBcastTime = 0.0; + int* sendData = (int*)malloc(sizeof(int) * elementsNum); + if (sendData == NULL) + { + printf("Out of memory.\n"); + return -1; + } + memset(sendData, 0, elementsNum); + + // Init. + MPI_Init(NULL, NULL); + // This function gives the rank of the process in the particular communicator’s group. + MPI_Comm_rank(MPI_COMM_WORLD, &rankNum); + + // Determine color based on row + int color = rankNum / 2; + + // Split the communicator based on the color and use the original rank for ordering + MPI_Comm row_comm; + MPI_Comm_split(MPI_COMM_WORLD, color, rankNum, &row_comm); + + totalMPIBcastTime = BcastData(trialsNum, elementsNum, sendData); + + if (rankNum == 0) + { + printf("Data size = %d, Trials = %d\n", elementsNum * sizeOfInt, trialsNum); + printf("Average of MPI_Bcast time = %lf seconds\n", totalMPIBcastTime / trialsNum); + } + free(sendData); + MPI_Comm_free(&row_comm); + MPI_Finalize(); +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/CMakeLists.txt new file mode 100644 index 0000000..bdbce0d --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/CMakeLists.txt @@ -0,0 +1,77 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_blas_demo C) + +# Add source files +set(SRC src/blas_demo.c) + +# Set BLAS option +option(BLAS "This is a default BLAS library nolocking." nolocking) + +# Set target file +set(TARGET_FILE blas_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Set compiler +set(CMAKE_C_COMPILER mpicc) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +# Set conditional compilation +if(${BLAS} STREQUAL "omp") + message(STATUS "The BLAS version used by demo is: omp.") + # Find link library + find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/omp) + # Add link library + link_directories(${KML_PATH}/lib/kblas/omp) +elseif(${BLAS} STREQUAL "locking") + message(STATUS "The BLAS version used by demo is: locking.") + # Find link library + find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/locking) + # Add link library + link_directories(${KML_PATH}/lib/kblas/locking) +elseif(${BLAS} STREQUAL "pthread") + message(STATUS "The BLAS version used by demo is: pthread.") + # Find link library + find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/pthread) + # Add link library + link_directories(${KML_PATH}/lib/kblas/pthread) +else() + message(STATUS "The BLAS version used by demo is: nolocking.") + # Find link library + find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/nolocking) + # Add link library + link_directories(${KML_PATH}/lib/kblas/nolocking) +endif() + +# Set debug compilation option +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KBLAS}) + diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README.md new file mode 100644 index 0000000..cfc081b --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README.md @@ -0,0 +1,71 @@ +# **KML_BLAS library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. BLAS(Basic Linear Algebra + Subprograms)提供了一系列基本线性代数运算函数的标准接口,包括矢量线性组合、矩阵乘以矢量、矩阵乘以矩阵等功能。BLAS已被广泛的应用于工业界和科学计算,成为业界标准。[KML_BLAS](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0012.html) + 库提供BLAS函数的C语言接口。 +2. **KML_BLAS library functions demo** 展示使用KML_BLAS库函数的代码示例,演示矩阵乘法、对称矩阵乘法、更新对称矩阵轶等函数的使用流程。 + +## 使用依赖 + +1. 通过[HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/)安装HMPI库,编译器,数学库。 + +## 使用教程 + +KML_BLAS有多个版本: +- 单线程不加锁版本:/usr/local/kml/lib/kblas/nolocking/libkblas.so +- 单线程加锁版本:/usr/local/kml/lib/kblas/locking/libkblas.so +- pthread实现多线程版本:/usr/local/kml/lib/kblas/pthread/libkblas.so +- OpenMP实现多线程版本:/usr/local/kml/lib/kblas/omp/libkblas.so + +**Demo中提供CMake编译选项来链接到不同版本的BLAS库** + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/blas/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + # 默认使用nolocking版本BLAS库 + cmake .. + make + # 使用locking版本BLAS库 + cmake -DBLAS=locking .. + make + # 使用pthread版本BLAS库 + cmake -DBLAS=pthread .. + make + # 使用omp版本BLAS库 + cmake -DBLAS=omp .. + make + ``` + +4. 运行demo + + ```shell + # 单独执行 + ./blas_demo + # mpirun 执行 + mpirun -n rank数 blas_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README_en.md new file mode 100644 index 0000000..fe2cf94 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/README_en.md @@ -0,0 +1,72 @@ +# **KML_BLAS library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. Basic Linear Algebra Subprograms (BLAS) provides a series of standard interfaces for basic linear algebra operation + functions, including vector linear combination, matrix multiplied by vector, and matrix multiplied by matrix. BLAS + has been widely used in industry and scientific computing, and has become an industry standard. + The [KML_BLAS](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0012.html) + library provides the C language interface for BLAS functions. +2. The **KML_BLAS library functions demo** shows a code example for KML_BLAS library functions, demonstrates the use process of matrix multiplication, symmetric matrix multiplication, update the rank of sysmmetric matrix, etc functions. + +## Dependencies + +1. Using the [HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/) to install the HMPI library, compiler, and math library. + +## Guidance + +There are multiple versions of KML_BLAS: +- Single-thread version without locking: /usr/local/kml/lib/kblas/nolocking/libkblas.so +- Single-thread version with locking: /usr/local/kml/lib/kblas/locking/libkblas.so +- Multi-thread version using pthread: /usr/local/kml/lib/kblas/pthread/libkblas.so +- Multi-thread version using OpenMP: /usr/local/kml/lib/kblas/omp/libkblas.so + +**The CMake compilation option is provided in the demo to link to different versions of the BLAS library.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/blas/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + # The BLAS library of the nolocking version is used by default. + cmake .. + make + # Use the BLAS library of the locking version. + cmake -DBLAS=locking .. + make + # Use the BLAS library of the pthread version. + cmake -DBLAS=pthread .. + make + # Use the BLAS library of the omp version. + cmake -DBLAS=omp .. + make + ``` + +4. Run the demo. + + ```shell + # Run the demo independently. + ./blas_demo + # Run the demo using the mpirun command. + mpirun -n rank numbers blas_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/src/blas_demo.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/src/blas_demo.c new file mode 100644 index 0000000..0337d29 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/blas/src/blas_demo.c @@ -0,0 +1,113 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_BLAS library functions demo demonstrates the use process of matrix multiplication, + * symmetric matrix multiplication, update the rank of sysmmetric matrix, etc functions. + * Create: 2022-05-15 + */ + +#include +#include +#include + +#include +#include + +void PrintMatrix(int row, int column, const float* matrix) +{ + int i; + for (i = 0; i < row; i++) + { + int j; + for (j = 0; j < column; j++) + { + printf("%-12.6f", matrix[j * column + i]); + } + printf("\n"); + } + printf("\n"); +} + +int main() +{ + MPI_Init(NULL, NULL); + // Rows of matrices of op(A) and C + int m = 3; + // Columns of matrices of op(B) and C + int n = 3; + // Columns of the matrix op(A) and rows of the matrix op(B) + int k = 3; + // If the matrix is column store and TransA = CblasNoTrans, lda is at least max(1, m); otherwise, lda is at least max(1, k). + // If A is row-store matrix and TransA = CblasNoTrans, lda is at least max(1, k); otherwise, lda is at least max(1, m). + int lda = 3, ldb = 3, ldc = 3; + // Multiplication coefficient + float alpha = 1.0F, beta = 1.0F; + + float a[9] = { 1.0F, 0, 0, + 0, 1.0F, 0, + 0, 0, 1.0F }; + printf("Input matrix A(3*3):\n"); + PrintMatrix(3, 3, a); + + float b[9] = { 0, 0, 2.0F, + 0, 2.0F, 0, + 2.0F, 0, 0 }; + printf("Input matrix B(3*3):\n"); + PrintMatrix(3, 3, b); + + float c[9] = { 3.0F, 0, 4.0F, + 0, 0, 0, + 4.0F, 0, 3.0F }; + printf("Input matrix C(3*3):\n"); + PrintMatrix(3, 3, c); + + float d[9]; + memcpy(d, c, sizeof(d)); + + /* + * Multiply one matrix by another. + * C = alpha * op(A) * op(B) + beta * C + * The value of op(X) may be op(X) = X, op(X) = X', op(X) = conjg(X') + * alpha and beta are multiplication coefficient. + * op(A) is an m*k matrix, op(B) is a k*n matrix, C is an m*n matrix. + */ + cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc); + printf("cblas_sgemm --> Output matrix C(3*3):\n"); + PrintMatrix(m, n, c); + + /* + * Compute the product of matrices in which matrix A is symmetric. + * C = alpha * A * B + beta * C or C = alpha * B * A + beta * C + * alpha and beta are multiplication coefficient. + * A is a symmetric matrix, B and C are m*n general matrices. + */ + cblas_ssymm(CblasColMajor, CblasLeft, CblasLower, m, n, alpha, a, lda, b, ldb, beta, c, ldc); + printf("cblas_ssymm --> Output matrix C(3*3):\n"); + PrintMatrix(m, n, c); + + /* + * Perform a rank-k matrix-matrix operation for a symmetric matrix. + * C = alpha * A * A' + beta * C or C = alpha * A' * A + beta * C + * alpha and beta are multiplication coefficient. + * C is an n*n symmetric matrix. + * In the first case, A is an n*k matrix. + * In the second case, A is a k*n general matrix. + */ + cblas_ssyrk(CblasColMajor, CblasUpper, CblasNoTrans, n, k, alpha, c, lda, beta, d, ldc); + printf("cblas_ssyrk --> Output matrix C(3*3):\n"); + PrintMatrix(m, n, c); + MPI_Finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/CMakeLists.txt new file mode 100644 index 0000000..bab2055 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/CMakeLists.txt @@ -0,0 +1,65 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_fft_demo C) + +# Add source files +set(SRC src/fft_demo.c) + +# Set FFT option +option(FFT "This is a default FFT library nolocking." double) + +# Set target file +set(TARGET_FILE fft_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Set compiler +set(CMAKE_C_COMPILER mpicc) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +# Add link library +link_directories(${KML_PATH}/lib) + +# Set conditional compilation +if(${FFT} STREQUAL "single") + message(STATUS "The FFT version used by demo is: single.") + # Find link library + find_library(KFFT kfftf HINTS ${KML_PATH}/lib) + add_definitions(-DSINGLE) +else() + message(STATUS "The FFT version used by demo is: double.") + # Find link library + find_library(KFFT kfft HINTS ${KML_PATH}/lib) +endif() + +# Set debug compilation option +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KFFT}) + diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README.md new file mode 100644 index 0000000..a3a0b36 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README.md @@ -0,0 +1,61 @@ +# **KML_FFT library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_FFT](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0122.html) + 是一个快速傅里叶变换(FFT)的数学库。 +2. **KML_FFT library functions demo** 展示使用KML_FFT库函数的代码示例,演示C2C变换等函数的使用流程。 + +## 使用依赖 + +1. 通过[HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/)安装HMPI库,编译器,数学库。 + +## 使用教程 + +KML_FFT有多个版本: +- 单精度版本:/usr/local/kml/lib/libkfftf.so +- 双精度版本:/usr/local/kml/lib/libkfft.so + +**Demo中提供CMake编译选项来链接到不同版本的FFT库** +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/fft/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + # 默认使用双精度版本FFT库 + cmake .. + make + # 使用单精度版本FFT + cmake -DFFT=single .. + make + ``` + +4. 运行demo + + ```shell + # 单独执行 + ./fft_demo + # mpirun 执行 + mpirun -n rank数 fft_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README_en.md new file mode 100644 index 0000000..a8f21ba --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/README_en.md @@ -0,0 +1,61 @@ +# **KML_FFT library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [KML_FFT](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0122.html) + is a math library of fast Fourier transform (FFT). +2. The **KML_FFT library functions demo** shows a code example for KML_FFT library functions, demonstrates the use process of C2C transforms, etc functions. + +## Dependencies + +1. Using the [HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/) to install the HMPI library, compiler, and math library. + +## Guidance + +There are multiple versions of KML_FFT: +- Single-precision version: /usr/local/kml/lib/libkfft.so +- Double-precision version: -L /usr/local/kml/lib/libkfftf.so + +**The CMake compilation option is provided in the demo to link to different versions of the FFT library.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/fft/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + # The FFT library of the double-precision is used by default. + cmake .. + make + # Use the FFT library of the single-precision version. + cmake -DFFT=single .. + make + ``` + +4. Run the demo. + + ```shell + # Run the demo independently. + ./fft_demo + # Run the demo using the mpirun command. + mpirun -n rank numbers fft_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/src/fft_demo.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/src/fft_demo.c new file mode 100644 index 0000000..03c5790 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/fft/src/fft_demo.c @@ -0,0 +1,138 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_FFT library functions demo demonstrates the use process of C2C transforms, etc functions. + * Create: 2022-05-15 + */ + +#include +#include + +#include +#include + +#ifdef SINGLE +#define FFT_COMPLEX kml_fftf_complex +#define FFT_PLAN kml_fftf_plan +#define FFT_MALLOC kml_fftf_malloc +#define FFT_PLAN_DFT kml_fftf_plan_dft +#define FFT_PLAN_DFT_1D kml_fftf_plan_dft_1d +#define FFT_PLAN_DFT_2D kml_fftf_plan_dft_2d +#define FFT_PLAN_DFT_3D kml_fftf_plan_dft_3d +#define FFT_DESTROY_PLAN kml_fftf_destroy_plan +#define FFT_FREE kml_fftf_free +#define FFT_EXECUTE_DFT kml_fftf_execute_dft +#else +#define FFT_COMPLEX kml_fft_complex +#define FFT_PLAN kml_fft_plan +#define FFT_MALLOC kml_fft_malloc +#define FFT_PLAN_DFT kml_fft_plan_dft +#define FFT_PLAN_DFT_1D kml_fft_plan_dft_1d +#define FFT_PLAN_DFT_2D kml_fft_plan_dft_2d +#define FFT_PLAN_DFT_3D kml_fft_plan_dft_3d +#define FFT_DESTROY_PLAN kml_fft_destroy_plan +#define FFT_FREE kml_fft_free +#define FFT_EXECUTE_DFT kml_fft_execute_dft +#endif + +void PrintComplex(FFT_COMPLEX* complex, const int length) +{ + printf("{\n"); + int i; + for (i = 0; i < length; i++) + { + printf(" {%.6f, ", complex[i].r); + printf("%.6f}", complex[i].i); + if (i != length - 1) + { + printf(","); + } + printf("\n"); + } + printf("}\n"); +} + +int main() +{ + MPI_Init(NULL, NULL); + // Dimension of FFT. The constraint is 1 ≤ rank ≤ 3. + int rank = 2; + // Indicates an array whose dimension is rank, including the size of each dimension in the FFT sequence. + // The constraint is n[i] ≥ 1, for i in 0 to rank - 1. + int* n; + n = (int*)FFT_MALLOC(sizeof(int) * rank); + n[0] = 2; + n[1] = 3; + double init[6][2] = {{ 120, 0 }, { 8, 8 }, { 0, 0 }, { 0, 16 }, { 0, 16 }, { -8, 8 }}; + + FFT_COMPLEX* in; + in = (FFT_COMPLEX*)FFT_MALLOC(sizeof(FFT_COMPLEX) * n[0] * n[1]); + int i; + for (i = 0; i < n[0] * n[1]; i++) + { + in[i].r = init[i][0]; + in[i].i = init[i][1]; + } + + printf("Input complex:\n"); + PrintComplex(in, n[0] * n[1]); + + FFT_COMPLEX* out; + out = (FFT_COMPLEX*)FFT_MALLOC(sizeof(FFT_COMPLEX) * n[0] * n[1]); + FFT_PLAN plan; + + /* + * Create a plan for the n-dimensional complex-to-complex (C2C) transform of a single contiguous data sequence. + */ + plan = FFT_PLAN_DFT(rank, n, in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + FFT_EXECUTE_DFT(plan, in, out); + + printf("FFT_PLAN_DFT --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + /* + * Create a plan for the one-dimensional C2C transform of a single contiguous data sequence. + */ + plan = FFT_PLAN_DFT_1D(n[0], in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + FFT_EXECUTE_DFT(plan, in, out); + + printf("FFT_PLAN_DFT_1D --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + /* + * Create a plan for the two-dimensional C2C transform of a single contiguous data sequence. + */ + plan = FFT_PLAN_DFT_2D(n[0], n[1], in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + FFT_EXECUTE_DFT(plan, in, out); + + printf("FFT_PLAN_DFT_2D --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + /* + * Create a plan for the there-dimensional C2C transform of a single contiguous data sequence. + */ + plan = FFT_PLAN_DFT_3D(n[0], n[1], 1, in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + FFT_EXECUTE_DFT(plan, in, out); + + printf("FFT_PLAN_DFT_3D --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + FFT_DESTROY_PLAN(plan); + FFT_FREE(n); + FFT_FREE(in); + FFT_FREE(out); + MPI_Finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/CMakeLists.txt new file mode 100644 index 0000000..5be9045 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_lapack_demo C) + +# Add source files +set(SRC src/lapack_demo.c) + +# Set target file +set(TARGET_FILE lapack_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Set compiler +set(CMAKE_C_COMPILER mpicc) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Add link library +find_library(KLAPACK klapack HINTS ${KML_PATH}/lib) +find_library(KSERVICE kservice HINTS ${KML_PATH}/lib) +find_library(LAPACK_ADAPT liblapack_adapt.a HINTS ${KML_PATH}/lib) +find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/omp) + +# Set debug compilation option +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KLAPACK} ${LAPACK_ADAPT} ${KBLAS} gfortran m ${KSERVICE}) + diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README.md new file mode 100644 index 0000000..42a050a --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README.md @@ -0,0 +1,52 @@ +# **KML_LAPACK library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_LAPACK](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0203.html) + 通过分块、求解算法组合、多线程、BLAS接口优化等手段,基于鲲鹏架构对线性代数运算库(Linear Algebra PACKage)的计算效率进行了优化。 +2. **KML_LAPACK library functions demo** 展示使用KML_LAPACK库函数的代码示例,演示矩阵分解、矩阵求逆等函数的使用流程。 + +## 使用依赖 + +1. 通过[HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/)安装HMPI库,编译器,数学库。 + +## 使用教程 + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/lapack/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + # 单独执行 + ./lapack_demo + # mpirun 执行 + mpirun -n rank数 lapack_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README_en.md new file mode 100644 index 0000000..d066f97 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/README_en.md @@ -0,0 +1,53 @@ +# **KML_LAPACK library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [KML_LAPACK](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0203.html) + optimizes the Linear Algebra PACKage (LAPACK) computing efficiency based on the Kunpeng architecture by means of + block division, algorithm combination, multi-thread, and BLAS interface optimization. +2. The **KML_LAPACK library functions demo** shows a code example for KML_LAPACK library functions, demonstrates the use process of matrix factorization, matrix inversion, etc functions. + +## Dependencies + +1. Using the [HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/) to install the HMPI library, compiler, and math library. + +## Guidance + +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/lapack/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + # Run the demo independently. + ./lapack_demo + # Run the demo using the mpirun command. + mpirun -n rank numbers lapack_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/src/lapack_demo.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/src/lapack_demo.c new file mode 100644 index 0000000..5fabe32 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/lapack/src/lapack_demo.c @@ -0,0 +1,154 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_LAPACK library functions demo demonstrates the use process of matrix factorization, + * matrix inversion, etc functions + * Create: 2022-05-15 + */ + +#include +#include + +#include +#include + +void PrintArray(const double* array, const int row, const int column) +{ + int i; + for (i = 0; i < row; i++) + { + int j; + for (j = 0; j < column; j++) + { + printf("%-12.6f", array[j * column + i]); + } + printf("\n"); + } + printf("\n"); +} + +int TestDgetrf(double* a, int* ipiv, const int m, const int n, const int lda) +{ + int info = 0; + /* + * Compute the LU factorization of matrix A. This function uses partial pivoting, allowing row interchanges. + * The operation is defined as A = PLU, where P is a permutation matrix, L is a lower triangular matrix or + * a lower echelon matrix and the diagonal is 1, and U is an upper triangular matrix or an upper echelon matrix. + */ + dgetrf_(&m, &n, a, &lda, ipiv, &info); + if (info != 0) + { + if (info > 0) + { + printf("Error: The value of the -%d-th parameter is invalid.", info); + } + else + { + printf("Error: The %d-th element on the diagonal of matrix U is 0. " + "The matrix factorization is complete, but U is singular. As a result, " + "an error of dividing by zero occurs when a system of linear equations is solved.", info); + } + } + return info; +} + +int TestDgetri(double* a, const int* ipiv, const int n, const int lda) +{ + /* + * Compute the inverse matrix based on the LU factorization result obtained using ?getrf. + */ + int info = 0; + // Temporary storage space. After lwork=-1 is called, work[0] is the optimal lwork value. + double* work = NULL; + double qwork; + // Length of the work array + int lwork = -1; + /* Query optimal work size */ + dgetri_(&n, a, &lda, ipiv, &qwork, &lwork, &info); + if (info != 0) + { + if (info > 0) + { + printf("Error: The value of the -%d-th parameter is invalid.", info); + } + else + { + printf("Error: The %d-th element on the diagonal of U is 0, and the matrix cannot be inverted.", info); + } + return info; + } + lwork = (int)qwork; + work = (double*)malloc(sizeof(double) * lwork); + /* Calculate inversion */ + dgetri_(&n, a, &lda, ipiv, work, &lwork, &info); + free(work); + if (info != 0) + { + if (info > 0) + { + printf("Error: The value of the -%d-th parameter is invalid.", info); + } + else + { + printf("Error: The %d-th element on the diagonal of U is 0, and the matrix cannot be inverted.", info); + } + return info; + } + return info; +} + +int main() +{ + MPI_Init(NULL, NULL); + // Number of rows in matrix A + int m = 4; + // Number of columns in matrix A + int n = 4; + // Leading dimension of the matrix A. lda >= max(1, n). + int lda = 4; + // An array containing pivot indices obtained from ?getrf. Its length is min(m, n). + // For 1 <= ipiv <= min(m, n), row i and row ipiv[i-1] of the matrix are interchanged during factorization. + int ipiv[4]; + + /* + * A (stored in column-major): + * 1.80 2.88 2.05 -0.89 + * 5.25 -2.95 -0.95 -3.08 + * 1.58 -2.69 -2.90 -1.04 + * -1.11 -0.66 -0.59 0.80 + */ + double a[16] = { 1.80, 5.25, 1.58, -1.11, + 2.88, -2.95, -2.69, -0.66, + 2.05, -0.95, -2.90, -0.59, + -0.89, -3.80, -1.04, 0.80 }; + printf("Input matrix A(4*4):\n"); + PrintArray(a, m, n); + + if (TestDgetrf(a, ipiv, m, n, lda) != 0) + { + return EXIT_FAILURE; + } + + printf("dgetrf --> Matrix A:\n"); + PrintArray(a, m, n); + + if (TestDgetri(a, ipiv, n, lda) == 0) + { + printf("dgetri --> Matrix A:\n"); + PrintArray(a, m, n); + } + MPI_Finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/CMakeLists.txt new file mode 100644 index 0000000..68d16db --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/CMakeLists.txt @@ -0,0 +1,64 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_math_demo C) + +# Add source files +set(SRC src/math_demo.c) + +# Set MATH option +option(MATH "This is a default MATH library performance." performance) + +# Set target file +set(TARGET_FILE math_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Set compiler +set(CMAKE_C_COMPILER mpicc) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +# Add link library +link_directories(${KML_PATH}/lib) + +# Find link library +find_library(MATH_L m HINTS ${KML_PATH}/lib) + +if(${MATH} STREQUAL "precision") + message(STATUS "The MATH version used by demo is: precision.") + find_library(KMATH km_l9 HINTS ${KML_PATH}/lib) +else() + message(STATUS "The MATH version used by demo is: performance.") + find_library(KMATH km HINTS ${KML_PATH}/lib) +endif() + +# Set debug compilation option +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${MATH_L} ${KMATH}) + diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README.md new file mode 100644 index 0000000..f59d2c1 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README.md @@ -0,0 +1,61 @@ +# **KML_MATH library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_MATH](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0111.html) + 是C语言实现的基本数学函数库。 +2. **KML_MATH library functions demo** 展示使用KML_MATH库函数的代码示例,演示三角函数的使用流程。 + +## 使用依赖 + +1. 通过[HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/)安装HMPI库,编译器,数学库。 + +## 使用教程 + +KML_MATH有多个版本: +- 高性能版本:/usr/local/kml/lib/libkm.so +- 高精度版本:/usr/local/kml/lib/libkm_l9.so + +**Demo中提供CMake编译选项来链接到不同版本的MATH库** +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/math/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + # 默认使用高性能版本MATH库 + cmake .. + make + # 使用高精度版本MATH库 + cmake -DMATH=precision .. + make + ``` + +4. 运行demo + + ```shell + # 单独执行 + ./math_demo + # mpirun 执行 + mpirun -n rank数 math_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README_en.md new file mode 100644 index 0000000..0ab2178 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/README_en.md @@ -0,0 +1,61 @@ +# **KML_MATH library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [KML_MATH](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0111.html) + is a basic math function library implemented by the C language. +2. The **KML_MATH library functions demo** shows a code example for KML_MATH library functions, demonstrates the use process of trigonometric functions. + +## Dependencies + +1. Using the [HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/) to install the HMPI library, compiler, and math library. + +## Guidance + +There are multiple versions of KML_MATH: +- High-performance version: /usr/local/kml/lib/libkm.so +- High-precision version: /usr/local/kml/lib/libkm_l9.so + +**The CMake compilation option is provided in the demo to link to different versions of the MATH library.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/math/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + # The MATH library of the high-performance version is used by default. + cmake .. + make + # Use the MATH library of the high-precition version. + cmake -DMATH=precision .. + make + ``` + +4. Run the demo. + + ```shell + # Run the demo independently. + ./math_demo + # Run the demo using the mpirun command. + mpirun -n rank numbers math_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/src/math_demo.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/src/math_demo.c new file mode 100644 index 0000000..9a4281b --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/math/src/math_demo.c @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_MATH library functions demo demonstrates the use process of trigonometric functions. + * Create: 2022-05-15 + */ + +#include +#include +#include + +#include +#include + +int main() +{ + MPI_Init(NULL, NULL); + double sinx, cosx; + sincos(M_PI_4, &sinx, &cosx); + printf("Input:\npi/4 = %.14f\n\n", M_PI_4); + printf("Output:\nsincos { sin(pi/4) = %.14f, cos(pi/4) = %.14f }\n\n", sinx, cosx); + printf("Output:\nasin(sin(pi/4)) = %.14f\n\n", asin(sinx)); + printf("Output:\nacos(cos(pi/4)) = %.14f\n\n", acos(cosx)); + MPI_Finalize(); + return EXIT_SUCCESS; +} + diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/CMakeLists.txt b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/CMakeLists.txt new file mode 100644 index 0000000..7b3b3ee --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/CMakeLists.txt @@ -0,0 +1,65 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_spblas_demo C) + +# Add source files +set(SRC src/spblas_demo.c) + +# Set SPBLAS option +option(SPBLAS "This is a default SPBLAS library single." single) + +# Set target file +set(TARGET_FILE spblas_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Set compiler +set(CMAKE_C_COMPILER mpicc) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Default build type is debug +set(CMAKE_BUILD_TYPE "Debug") + +# Set conditional compilation +if(${SPBLAS} STREQUAL "multi") + message(STATUS "The SPBLAS version used by demo is: multi.") + # Add link library + link_directories(${KML_PATH}/lib/kspblas/multi) + # Find link library + find_library(KSPBLAS kspblas HINTS ${KML_PATH}/lib/kspblas/multi) +else() + message(STATUS "The SPBLAS version used by demo is: single.") + # Add link library + link_directories(${KML_PATH}/lib/kspblas/single) + # Find link library + find_library(KSPBLAS kspblas HINTS ${KML_PATH}/lib/kspblas/single) +endif() + +# Set debug compilation option +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_compile_options(-g) +endif() + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KSPBLAS}) + diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README.md new file mode 100644 index 0000000..12f35e8 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README.md @@ -0,0 +1,61 @@ +# **KML_SPBLAS library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_SPBLAS](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0067.html) + 库是稀疏矩阵(Sparse Matrix)的基础代数运算库,稀疏矩阵是指大部分矩阵元素为零的矩阵。 +2. **KML_SPBLAS library functions demo** 展示使用KML_SPBLAS库函数的代码示例,演示系数矩阵与向量计算函数的使用流程。 + +## 使用依赖 + +1. 通过[HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/)安装HMPI库,编译器,数学库。 + +## 使用教程 + +KML_SPBLAS有多个版本: +- 单线程版本:/usr/local/kml/lib/kspblas/single/libkspblas.so +- 多线程版本:/usr/local/kml/lib/kspblas/multi/libkspblas.so + +**Demo中提供CMake编译选项来链接到不同版本的SPBLAS库** +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/Development_framework/hpc-sdk/examples/kml/spblas/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + # 默认使用单线程版本SPBLAS库 + cmake .. + make + # 使用多线程版本SPBLAS库 + cmake -DSPBLAS=multi .. + make + ``` + +4. 运行demo + + ```shell + # 单独执行 + ./spblas_demo + # mpirun 执行 + mpirun -n rank数 spblas_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README_en.md new file mode 100644 index 0000000..7273d37 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/README_en.md @@ -0,0 +1,63 @@ +# **KML_SPBLAS library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. The [KML_SPBLAS](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0067.html) +library is a basic algebraic operation library of a sparse matrix. The majority of the elements in a sparse matrix are +zero. + +2. The **KML_SPBLAS library functions demo** shows a code example for KML_SPBLAS library functions, demonstrates the use process of sparse matrix and vector calculation function. + +## Dependencies + +1. Using the [HPC SDK](https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/) to install the HMPI library, compiler, and math library. + +## Guidance + +There are multiple versions of KML_SPBLAS: +- Single-thread version: /usr/local/kml/lib/kspblas/single/libkspblas.so +- Multi-thread version: /usr/local/kml/lib/kspblas/multi/libkspblas.so + +**The CMake compilation option is provided in the demo to link to different versions of the SPBLAS library.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd /devkitdemo/Development_framework/hpc-sdk/examples/kml/spblas/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + # The SPBLAS library of the single-thread version is used by default. + cmake .. + make + # Use the SPBLAS library of the multi-thread version. + cmake -DSPBLAS=multi .. + make + ``` + +4. Run the demo. + + ```shell + # Run the demo independently. + ./spblas_demo + # Run the demo using the mpirun command. + mpirun -n rank numbers spblas_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/src/spblas_demo.c b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/src/spblas_demo.c new file mode 100644 index 0000000..ed78c49 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/examples/kml/spblas/src/spblas_demo.c @@ -0,0 +1,142 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_SPBLAS library functions demo demonstrates the use process of sparse matrix and vector calculation function. + * Create: 2022-05-15 + */ + +#include +#include +#include + +#include +#include + +void PrintMatrix(int row, int column, const float* matrix) +{ + int i; + for (i = 0; i < row; i++) + { + int j; + for (j = 0; j < column; j++) + { + printf("%-12.6f", matrix[j * column + i]); + } + printf("\n"); + } + printf("\n"); +} + +void Print_CSR_To_Matrix(int m, float* values, int values_length, + KML_INT* row_offsets, int row_offsets_length, + KML_INT* column_indices) +{ + int i; + for (i = 0; i < row_offsets_length; ++i) + { + if (row_offsets[i] >= values_length) + { + break; + } + float x[m]; + // Initialize the matrix row array + memset(x, 0, m * sizeof(float)); + + // Confirm the range of values for each row based on the offset + int j; + for (j = row_offsets[i]; j < row_offsets[i + 1]; ++j) + { + x[column_indices[j]] = values[j]; + } + + // print matrix row array + int y; + for (y = 0; y < m; ++y) + { + printf("%.6f\t", x[y]); + } + + printf("\n"); + } + printf("\n"); +} + +int main() +{ + MPI_Init(NULL, NULL); + // Record sparse matrices using the 'Compressed Sparse Row Formate (CSR)' storage format + // Represents the number of rows and columns of the matrix A(m*m) [Define NNZ (Num-non-zero) as the number of non-zero elements in matrix A] + KML_INT m = 4; + // Mainly used to record the values of non-zero elements (values) from left to right and top to bottom in the matrix A(m*m), the length of the array is NNZ [Values array] + float a[9] = { 2.0F, -3.0F, 7.0F, 1.0F, -6.0F, 8.0F, -4.0F, 5.0F, 9.0F }; + // Indicates the column indices of the non-zero elements in the matrix A(m*m), the length of the array is NNZ [ColumnIndices array] + KML_INT ja[9] = { 1, 2, 4, 3, 4, 1, 3, 4, 1 }; + // Represents the offset (row offsets) of the matrix A(m*m), the first m elements in the array represent the subscripts of the first non-zero element of each row in the matrix A(m*m) in the Values array, The value of the last item is NNZ, the length of the array is m+1 [RowOffsets array] + KML_INT ia[5] = { 1, 4, 6, 9, 10 }; + + // Only used by functions that support 0-based matrix indexing [conforms to C indexing specification] + KML_INT scsrgemv_ja[9]; + KML_INT scsrgemv_ia[5]; + + int ix; + for (ix = 0; ix < 9; ++ix) + { + scsrgemv_ja[ix] = ja[ix] - 1; + } + + int iy; + for (iy = 0; iy < 5; ++iy) + { + scsrgemv_ia[iy] = ia[iy] - 1; + } + + // array of vectors x + float x[4] = { 1.0F, 3.0F, -2.0F, 5.0F }; + // array of vectors y + float y[4] = { -1.0F, 1.0F, 5.0F, 3.0F }; + + printf("Input A(4*4):\n"); + Print_CSR_To_Matrix(m, a, 9, scsrgemv_ia, 5, scsrgemv_ja); + printf("Input x:\n"); + PrintMatrix(1, m, x); + printf("Input y:\n"); + PrintMatrix(1, m, y); + + // [only supports matrix indices starting from 1] + kml_sparse_status_t status_kml_sparse_scsrgemv = kml_sparse_scsrgemv(KML_SPARSE_OPERATION_NON_TRANSPOSE, m, a, ia, ja, x, y); + if (status_kml_sparse_scsrgemv == KML_SPARSE_STATUS_SUCCESS) + { + printf("(kml_sparse_scsrgemv) --> Output y:\n"); + PrintMatrix(1, m, y); + } + + // [only supports matrix indices starting from 1] + kml_sparse_status_t status_kml_sparse_scsrsymv = kml_sparse_scsrsymv(KML_SPARSE_FILL_MODE_LOWER, m, a, ia, ja, x, y); + if (status_kml_sparse_scsrsymv == KML_SPARSE_STATUS_SUCCESS) + { + printf("(kml_sparse_scsrsymv) --> Output y:\n"); + PrintMatrix(1, m, y); + } + + // [only supports matrix indices starting from 0] + kml_sparse_status_t status_kml_csparse_scsrgemv = kml_csparse_scsrgemv(KML_SPARSE_OPERATION_NON_TRANSPOSE, m, a, scsrgemv_ia, scsrgemv_ja, x, y); + if (status_kml_csparse_scsrgemv == KML_SPARSE_STATUS_SUCCESS) + { + printf("(kml_csparse_scsrgemv) --> Output y:\n"); + PrintMatrix(1, m, y); + } + MPI_Finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/bisheng_modulefiles b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/bisheng_modulefiles new file mode 100644 index 0000000..c98fb82 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/bisheng_modulefiles @@ -0,0 +1,23 @@ +#%Module1.0 +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Bisheng module for use with 'environment-modules' package: +set version 2.1.0.B010 +set prefix +setenv BISHENG_DIR $prefix + +prepend-path PATH $prefix/bin +prepend-path LD_LIBRARY_PATH $prefix/lib +prepend-path MODULEPATH $prefix diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/gcc_modulefiles b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/gcc_modulefiles new file mode 100644 index 0000000..799ce4d --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/gcc_modulefiles @@ -0,0 +1,24 @@ +#%Module1.0 +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Gcc module for use with 'environment-module' package: +set version 10.3.1 +set prefix +setenv GCC_DIR $prefix + +prepend-path PATH $prefix/bin +prepend-path INCLUDE $prefix/include +prepend-path LD_LIBRARY_PATH $prefix/lib64 +prepend-path MODULEPATH $prefix diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/hmpi_modulefiles b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/hmpi_modulefiles new file mode 100644 index 0000000..5b37cae --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/module/hmpi_modulefiles @@ -0,0 +1,24 @@ +#%Module1.0 +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# HMPI module for use with 'environment-modules' package: +conflict mpi +set version 1.1.1 +set prefix + +prepend-path OPAL_PREFIX $prefix/ompi +prepend-path PATH $prefix/ompi/bin:$prefix/ucx/bin +prepend-path LD_LIBRARY_PATH $prefix/ompi/lib:$prefix/ucx/lib +prepend-path INCLUDE $prefix/ompi/include: $prefix/ucx/include diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README.md new file mode 100644 index 0000000..1285658 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README.md @@ -0,0 +1,113 @@ +# **鲲鹏HPC SDK一键式安装脚本使用** + +简体中文 | [English](README_en.md) + +## 1、介绍 + +#### 1、自动化安装脚本部署HPC相关软件。包括Hyper-mpi、kml、gcc、毕昇 + +#### 2、支持自定义路径安装 + + +## 2、使用依赖 + +#### 1、服务器兼容性如下 + +| OS | Hyper MPI | 毕昇 | GCC for openEuler | 数学库 | +|----| ---- | ---- | ---- | ---- | +| centos 7 | Y (GCC9.3,毕昇2.1.0) | Y | Y | Y (GCC7.3及以上) | +| openEuler20.03 LTS | Y (毕昇2.1.0) | Y | Y | Y (GCC7.3及以上) | +| openEuler20.03 sp1 |Y (GCC9.3,毕昇2.1.0) | Y | Y | Y (GCC7.3及以上) | +| openEuler20.03 sp2 | N | Y | Y | Y (GCC7.3及以上) | +| openEuler20.03 sp3 | N | Y | Y | Y (GCC7.3及以上) | +| 麒麟V10 SP1 | Y (GCC9.3,毕昇2.1.0) | Y | Y | N | +| 麒麟V10 SP2 | Y (GCC9.3,毕昇2.1.0) | Y | Y | N | +| unbuntu18.04 | N | Y | Y | Y (GCC7.3及以上)| +| unbuntu20.04 | N | Y | Y | Y (GCC7.3及以上) | +| UOS 1020e | N | Y | Y | N | + +说明:以上表中均为aarch64架构;小括号中为GCC、毕昇编译器的版本代表依赖最小版本,表中的Y代表系统支持安装,N代表不支持安装。 + +#### 2、软件依赖列表 + + +| 依赖 | Hyper MPI | 毕昇 | GCC for openEuler | 数学库 | +| ---- | ---- | ---- | ---- | ---- | +| gcc | Y(9.3.0) | Y(GCC4.8.5及以上)| N | N | +| bisheng | Y | N | N | N | +| glibc-devel(libc-dev-bin) | N | N | Y(glibc-devel2.17及以上) | N | +| glibc | N | Y(glibc2.17及以上)| Y(glibc2.17及以上) | N | +| libatomic | N | Y(libatomic1.2.0及以上) | N | N | +| libgomp | N | N | N | Y | + +说明:以上表中内容为Hyper MPI、数学库、GCC for openEuler、毕昇编译器安装所需要的依赖,表中的Y代表系统依赖,N代表不依赖。redhat系安裝毕昇编译的rpm包时需确保系统已经安装libgomp。 + +## 3、使用教程 + +#### 1、获取kunpeng-hpc-xxx-aarc64-linux.tar.gz包 +[https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.1-aarch64-linux.tar.gz] +(https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.1-aarch64-linux.tar.gz) +#### 2、执行如下命令进行安装 +``` +tar -xf kunpeng-hpc-xxx-aarch64-linux.tar.gz +cd kunpeng-hpc-xxx-aarch64-linux/script +bash install.sh +``` +#### 3、在执行安装过程中根据提示做相应的操作完成HPC安装 +#### 4、安装完成后根据提示添加环境变量:如下回显信息这里以gcc为例 + +> 4.1第一种方式执行下面命令添加环境变量到/etc/profile +``` + echo 'export PATH=/opt/gcc/gcc-xxx-aarch64-linux/bin:$PATH' >>/etc/profile + echo 'export INCLUDE=/opt/gcc/gcc-xxx-aarch64-linux/include:$INCLUDE' >>/etc/profile + echo 'export LD_LIBRARY_PATH=/opt/gcc/gcc-xxx-aarch64-linux/lib64:$LD_LIBRARY_PATH' >>/etc/profile + source /etc/profile +``` +> 4.2 第二种使用module加载module_file使环境变量生效 +``` + module load /opt/modules/gcc/gcc_modulefiles +``` +> 4.3 可以通过如下方式使变量永久生效 + +> * 1、打开~/.bashrc 文件 +``` + vim ~/.bashrc +``` +> * 2、把下面命令写入到 ~/.bashrc +``` + module use /opt/modules/gcc/ + module load gcc_modulefiles +``` +> * 3、保存文件 +> * 4、执行如下命令让配置生效 +``` + source ~/.bashrc +``` +4.4 运行脚本配置环境变量 +``` + cd kunpeng-hpc-xxx-aarch64-linux/script + bash configure_environment_xxxx.sh +``` + +## 4、注意事项 + +#### 1、安装剩余磁盘空间应满足大于3GB +#### 2、仅支持在aarch64环境中安装 + +## 5、卸载软件 +#### 以gcc和kml为例进行说明 +#### 1、打开/etc/profile 或者 ~/.bashrc 检查相关软件二进制文件或者lib文件所在路径 。 +``` +vim /etc/profile(~/.bashrc) +export LD_LIBRARY_PATH=/usr/local/kml/lib:$LD_LIBRARY_PATH +... +export LD_LIBRARY_PATH=/usr/local/kml/lib/kspblas/multi:$LD_LIBRARY_PATH +export INCLUDE=/opt/gcc/gcc-xxxx-aarch64-linux/include:$INCLUDE +``` + +说明:执行上述命令打开/etc/profile(~/.bashrc)可以查看到具体的安装路径为‘/usr/local/kml’ 和 ‘/opt/gcc/gcc-xxxx-aarch64-linux/’ +或者执行env / export 查看软件的安装路径。 + +#### 2、把/etc/profile 或者 ~/.bashrc中的gcc和kml环境变量删除。 +#### 3、根据1步骤中获取的安装目录,在确认此目录中无其他要保留的文件后进行删除操作。路径中/opt为默认安装路径,若为其他自定义路径请自行替换。 +#### 4、打开新的终端窗口,使修改的环境变量生效。 diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README_en.md b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README_en.md new file mode 100644 index 0000000..651827a --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/README_en.md @@ -0,0 +1,110 @@ +# **Kunpeng HPC SDK One-Click Installation Script** + +English | [简体中文](README.md) + +## 1、Introduction + +#### 1、Use the automatic installation script to automatically deploy HPC software, including HYPER-MPI, KML, GCC, and BISHENG. + +#### 2、Support installation in a user-defined path. + + +## 2、Dependency + +#### 1、The server compatibility is as follows: + +| OS | Hyper MPI | BISHENG | GCC for openEuler | KML | +| ---- | ---- | ---- | ---- | ---- | +| centos 7 | Y (GCC 9.3,BISHENG 2.1.0) | Y | Y | Y (GCC 7.3 or later) | +| openEuler20.03 LTS | Y (BISHNEG 2.1.0) | Y | Y | Y (GCC 7.3 or later) | +| openEuler20.03 sp1 | Y (GCC 9.3,BISHENG 2.1.0) | Y | Y | Y (GCC 7.3 or later) | +| openEuler20.03 sp2 | N | Y | Y | Y (GCC 7.3 or later) | +| openEuler20.03 sp3 | N | Y | Y | Y (GCC 7.3 or later) | +| kylin V10 SP1 | Y (GCC 9.3,BISHENG 2.1.0) | Y | Y | N | +| kylin V10 SP2 | Y (GCC 9.3,BISHENG 2.1.0) | Y | Y | N | +| unbuntu18.04 | N | Y | Y | Y (GCC 7.3 or later)| +| unbuntu20.04 | N | Y | Y | Y (GCC 7.3 or later) | +| UOS 1020e | N | Y | Y | N | + +Note: The OSs listed in the preceding table use the AArch64 architecture. The versions of the GCC and Bisheng Compiler in parentheses indicate the earliest supported versions. Y indicates supported installation and N indicates the installation is not supported. + +#### 2、Software dependency list + + +| Dependency | Hyper MPI | BISHENG | GCC for openEuler | KML | +| ---- | ---- | ---- | ---- | ---- | +| gcc | Y(GCC 9.3.0) | Y(GCC 4.8.5 or later)| N | N | +| bisheng | Y | N | N | N | +| glibc-devel(libc-dev-bin) | N | N | Y(glibc-devel 2.17 or later) | N | +| glibc | N | Y(glibc 2.17 or later)| Y(glibc 2.17 or later) | N | +| libatomic | N | Y(libatomic 1.2 or later) | N | N | +| libgomp | N | N | N | Y | + +Note: The preceding table lists the dependencies required for installing the Hyper MPI, math library, GCC for openEuler, and Bisheng Compiler. Y indicates required dependency for the software and N indicates the dependency is not required. Before installing the RPM package compiled by Bisheng in the Red Hat system, ensure that libgomp has been installed in the system. + +## 3、Usage Guide + +#### 1、Obtain the kunpeng-hpc-1.0.0-aarc64-linux.tar.gz package. +[https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.0-aarch64-linux.tar.gz] +(https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.0-aarch64-linux.tar.gz) +#### 2、Run the following commands to install the software: +``` +tar -xf kunpeng-hpc-xxx-aarch64-linux.tar.gz +cd kunpeng-hpc-xxx-aarch64-linux/script +bash install.sh +``` +#### 3、Perform operations as prompted to install the HPC software. +#### 4、After the installation is complete, add environment variables ad prompted. The following command output uses GCC as an example: + +> 4.1 Method 1: Add environment variables to /etc/profile. +``` + echo 'export PATH=/opt/gcc/gcc-xxx-aarch64-linux/bin:$PATH' >>/etc/profile + echo 'export INCLUDE=/opt/gcc/gcc-xxx-aarch64-linux/include:$INCLUDE' >>/etc/profile + echo 'export LD_LIBRARY_PATH=/opt/gcc/gcc-xxx-aarch64-linux/lib64:$LD_LIBRARY_PATH' >>/etc/profile + source /etc/profile +``` +> 4.2 Method 2: Use the module command to load module_file for the environment variables to take effect. +``` + module load /opt/modules/gcc/gcc_modulefiles +``` +> 4.3 Method 3: Make the environment variables take effect permanently. + +> * 1、Open the ~/.bashrc. +``` + vim ~/.bashrc +``` +> * 2、Add the following content to the ~/.bashrc file: +``` + module use /opt/modules/gcc + module load gcc_modulefiles +``` +> * 3、Save the file. +> * 4、Make the configuration take effect: +``` + source ~/.bashrc +``` +4.4 Method 4: Run the script to configure environment variables. +``` + cd kunpeng-hpc-xxx-aarch64-linux/script + bash configure_environment_xxxxx.sh +``` +## 4、Precautions + +#### 1、The free drive space for the installation must be greater than 3 GB. +#### 2、The installation can be performed only in the AArch64 environment. + +## 5、Software Uninstallation +#### The following uses gcc and kml as an example. +#### 1、Open /etc/profile or ~/.bashrc to check the directory where the binary or lib files of related software are stored. +``` +vim /etc/profile(~/.bashrc) +export LD_LIBRARY_PATH=/usr/local/kml/lib:$LD_LIBRARY_PATH +... +export LD_LIBRARY_PATH=/usr/local/kml/lib/kspblas/multi:$LD_LIBRARY_PATH +export INCLUDE=/opt/gcc/gcc-xxxx-aarch64-linux/include:$INCLUDE +``` +Note: After you access /etc/profile (~/.bashrc), you can view that the installation paths are /usr/local/kml and /opt/gcc/gcc-xxxx-aarch64-linux/ or Run the 'env / export' command to view the software installation path. + +#### 2、Delete environment variables. +#### 3、In the installation path obtained in step 1, ensure that there are no other files to be stored in the path, and then delete the installation path. In then path, '/opt' is then default installation path. Replace it if it is a user-defined path. +#### 4、Open a new terminal window for the modified environment variables to take effect. diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/common_fun.sh b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/common_fun.sh new file mode 100644 index 0000000..91e1a03 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/common_fun.sh @@ -0,0 +1,527 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# ctrl+c +onCtrlC() { + logger "The Ctrl+C exception is triggered." {TIP_COLOR_FAILED} + exit 0 +} + +# ctrl+z +onCtrlZ() { + logger "The Ctrl+Z exception is triggered." {TIP_COLOR_FAILED} + exit 0 +} + +# SSH disconnection exception +onDisconnect() { + logger "The SSH connection was disconnected exception is triggered." {TIP_COLOR_FAILED} + exit 0 +} + +create_log_file() { + time_stamp=$(date +%s) + # Installation log file name + LOG_FILE_NAME="install_hpc_${time_stamp}.log" + # Absolute path of log files + log_file_of_abspath=${current_dir}/../log/$LOG_FILE_NAME + # Create a log file + mkdir -p ${current_dir}/../log + touch ${log_file_of_abspath} +} + +logger() { + local msg="$1" + local tip_color=$2 + local datetime=$(date "+%Y-%m-%d %H:%M:%S") + if [[ "${tip_color}" ]] && [[ -z $(echo "${tip_color}" | sed "s/[0-9]//g") ]]; then + echo -e "\e[1;${tip_color}m${msg}\e[0m" + if [[ "${tip_color}" == "${TIP_COLOR_FAILED}" ]]; then + level='ERROR' + elif [[ "${tip_color}" == "${TIP_COLOR_WARNING}" ]]; then + level='WARNING' + else + level='INFO' + fi + else + if [[ "${tip_color}" == "ERROR" ]]; then + level='ERROR' + elif [[ "${tip_color}" == "WARNING" ]]; then + level='WARNING' + else + level='INFO' + fi + fi + if [ -f "${log_file_of_abspath}" ]; then + echo "[${datetime}] [${level}] ${msg}" >>${log_file_of_abspath} + fi +} + +get_os_name() { + # Obtain the os name + os_name=$(cat /etc/os-release | grep "PRETTY_NAME" | awk -F '"' '{print $2}') + os_name_del_space=${os_name// /} + if [[ ${os_name_del_space} =~ "KylinLinuxAdvancedServerV10" ]]; then + os_name="KylinLinuxAdvancedServerV10" + elif [[ ${os_name_del_space} =~ "Ubuntu20.04" ]]; then + os_name="Ubuntu20.04" + elif [[ ${os_name_del_space} =~ "Ubuntu18.04" ]]; then + os_name="Ubuntu18.04" + elif [[ ${os_name_del_space} =~ "CentOSLinux" ]]; then + red_os=$(cat /etc/redhat-release) + red_os=${red_os// /} + [[ ${red_os} =~ "CentOSLinuxrelease7.6.1810" ]] && os_name="CentOSLinuxrelease7.6.1810" + else + os_name=${os_name_del_space} + fi +} + +version_ge() { + # Compare the version + if [[ "$#" != 2 ]]; then + return 1 + fi + test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1" + if [[ "$?" == 0 ]]; then + return 0 + else + return 1 + fi +} + +user_customize_path() { + # Enter a user-defined path. + install_name=$1 + flag=1 + while [[ ${flag} == '1' ]]; do + logger "For a non-root user, enter the directory on which the user has permission." ${TIP_COLOR_WARNING} + read -p "Enter the path for installing ${install_name}(default /opt):" you_path + if [[ -z "${you_path}" ]]; then + # Default installation path + customize_path="/opt" + else + customize_path="${you_path}" + fi + check_customize_path "${customize_path}" + if [[ "$?" == 0 ]]; then + break + fi + done + check_space ${customize_path} +} + +get_install_kml_mode() { + # Obtain the dpkg or rpm installation mode of the math library + if [[ "${os_name}" =~ "Ubuntu" ]]; then + install_package_kind='dpkg' + else + install_package_kind='rpm' + fi +} + +check_customize_path() { + # Check whether the entered path is valid [0-9a-zA-Z-_/] + customize_path="$1" + len_path=${#customize_path} + char_max=$(($(getconf SCHAR_MAX) - 59)) + unset new_customize_path + if [[ "${len_path}" -ge "${char_max}" ]]; then + logger "The path length exceeds the limit. Enter another one." ${TIP_COLOR_FAILED} + return 1 + fi + if echo "${customize_path}" | grep -vqE "^/"; then + logger "The path should be an absolute path. Enter another one." ${TIP_COLOR_FAILED} + return 1 + fi + ar=($(echo "${customize_path}" | tr '/' ' ')) + for value in ${ar[*]}; do + str_status=$(echo "$value" | tr -d "[a-zA-Z0-9-_]") + if [[ -n "$str_status" ]]; then + logger "The entered installation path can contain digital alphabets and special characters such as ${ALLOW_STRING} Please enter a correct path and try again." ${TIP_COLOR_FAILED} + return 1 + else + new_customize_path=${new_customize_path}/${value} + fi + done + if [ -f ${customize_path} ]; then + logger "A file with the same name exists. Enter another one." ${TIP_COLOR_FAILED} + return 1 + fi + customize_path=${new_customize_path} + [[ -z ${customize_path} ]] && customize_path="/" + mark_customize_path_status + mkdir -p ${customize_path} + [[ ${customize_path} == "/" ]] || customize_path=$(cd ${customize_path};pwd) +} + +mark_customize_path_status() { + if [[ -d ${customize_path} ]]; then + customize_path_status=1 + else + valid_customize_path=${customize_path} + while [[ ${flag} == 1 ]]; do + valid_customize_path=${valid_customize_path%/*} + if [ -d ${valid_customize_path} ]; then + customize_path_status=2 + break + fi + if [ -z ${valid_customize_path} ]; then + break + fi + done + fi +} + +check_space() { + # Check the drive space + customize_path="$1" + space_flag=1 + while [[ ${space_flag} == 1 ]]; do + if [[ -d ${customize_path} ]]; then + avail_space=$(df -lkP ${customize_path} | awk "NR>1" | awk -F " " '{print $4}') + break + else + customize_path=${customize_path%/*} + if [[ -z ${customize_path} ]]; then + opt_space=$(df -lkP '/' | awk "NR>1" | awk -F " " '{print $4}') + break + fi + fi + done + if [[ ${avail_space} -lt ${low_space} ]]; then + logger "The disk space of the selected installation directory is insufficient." ${TIP_COLOR_FAILED} + logger "Ensure that the available space of the ${customize_path} directory is greater than ${low_space_package_g} GB" ${TIP_COLOR_FAILED} + exit 1 + fi +} + +user_choose() { + while_flag=1 + while [[ ${while_flag} == 1 ]]; do + num=${#software_support_list[@]} + # Install the software according to the sequence selected by the user. + echo -n -e "\e[1;33mEnter the serial number of the software that can be installed. Format: a single digit or 'digits+commas', for example, (1,2,3). To exit the installation, enter no:\e[0m" + read -r choose_install + # If the length of the entered character string exceeds the upper limit, the system prompts you to enter a new character string. + max_length_number=$((2 * ${num} - 1)) + length_number=$(echo ${choose_install} | wc -L) + if [[ ${length_number} -gt ${max_length_number} ]]; then + logger "The character string you entered is too long." ${TIP_COLOR_FAILED} + continue + fi + # Only one Hyper MPI can be installed. + if [[ ${hyper_mpi_install_filter_system} =~ "${os_name}" ]]; then + if [[ ${choose_install} =~ "1" ]] && [[ ${choose_install} =~ "2" ]]; then + logger "Only one hyper-mpi can be installed." ${TIP_COLOR_FAILED} + continue + fi + fi + if [[ ${choose_install} =~ ^[nN]$|^no$ ]]; then + logger "Exit installation." ${TIP_COLOR_FAILED} + exit 1 + fi + if echo ${choose_install} | grep -qE "([1-$num],){1,$num}[1-$num]$|^[1-$num]$"; then + break + else + logger "Select one or multiple sequences and use commas to separate them." ${TIP_COLOR_FAILED} + fi + done + if [[ ${length_number} -eq 1 ]]; then + # Only one is selected by the user. + # Display the item that the user selects to install. + select_result=${software_support_list[((${choose_install} - 1))]} + else + # Display repeated user input. + choose_install=$(echo ${choose_install} | tr ',' ' ' | xargs -n 1 | sort -u) + for i in ${choose_install}; do + select_result="$select_result,${software_support_list[(($i - 1))]}" + done + fi + logger "The software you select to install is ${select_result#,}." ${TIP_COLOR_SUCCESS} +} + +show_software_support_list() { + # Display the software supported by the current system user. + logger "Installation environment check result:" ${TIP_COLOR_CHECKING} + if [[ "${software_support_list}" =~ "HMPI" ]]; then + logger "The hyper-mpi corresponds to a specific compiler. Install the matched compiler for the hyper-mpi. For example, the compiler corresponding to HMPI-BISHENG is BISHENG." ${TIP_COLOR_ECHO} + fi + if [[ "${software_support_list}" =~ "KML" ]]; then + logger "The KML corresponds to a specific compiler. Install the matched compiler for the KML. For example, the compiler corresponding to KML is GCC." ${TIP_COLOR_ECHO} + fi + printf "%-16s %-29s %-14s %-20s\n" "SequenceNumber" "Software" "Support" >>${log_file_of_abspath} + printf "%-16s %-29s %-14s %-20s\n" "SequenceNumber" "Software" "Support" + software_support_list=($(echo ${software_support_list} | tr ' ' ' ')) + for ((i = 0; i < ${#software_support_list[@]}; i++)); do + printf "%-16s %-29s %-20s\n" "$((i + 1))" "${software_support_list[i]}" "${check_result_list[i]}" >>${log_file_of_abspath} + printf "%-16s %-29s \033[1;32m%-20s\033[0m\n" "$((i + 1))" "${software_support_list[i]}" "${check_result_list[i]}" + done +} + +read_answer() { + # Process user interaction operations. + ask_question="$*" + ask_flag=1 + while [[ ${ask_flag} == 1 ]]; do + read -p "${ask_question} [Y/N]:" you_choose + if [[ ${you_choose} =~ ^[Yy]$ ]]; then + return 0 + elif [[ ${you_choose} =~ ^[nN]$ ]]; then + return 1 + else + logger 'input error' ${TIP_COLOR_FAILED} + continue + fi + done +} + + +hand_precondition_mpi() { + # Handle the installation exception caused by insufficient environment dependency. + if [[ ${#miss_package[@]} -gt 0 ]]; then + logger "The $(echo ${miss_package[@]}) dependency is not detected in the environment." ${TIP_COLOR_WARNING} + read_answer "The corresponding ${miss_package[@]} is missing or the version is incorrect. Are you sure you want to continue the installation?" + if [[ $? != 0 ]]; then + logger "Exit the hyper-mpi installation." ${TIP_COLOR_FAILED} + return 1 + fi + fi + install_hyper_mpi +} + +check_precondition_kml() { + # Check the math library dependency. + local install_package_kind=$1 + miss_package_kml=() + libc6="/usr/lib64/libc.so.6" + libgomp="/usr/lib64/libgomp.so.1" + [[ ${install_package_kind} == "dpkg" ]] && libc6="/lib/aarch64-linux-gnu/libc.so.6" + [[ ${install_package_kind} == "dpkg" ]] && libgomp="/usr/lib/aarch64-linux-gnu/libgomp.so.1" + [[ ! -f ${libc6} ]] && miss_package_kml[${#miss_package_kml[*]}]="libc6" + [[ ! -f ${libgomp} ]] && miss_package_kml[${#miss_package_kml[*]}]="libgomp" + result=$(command -v nm) + if [[ -z ${result} ]]; then + miss_package_kml[${#miss_package_kml[*]}]="nm" + fi +} + +hand_precondition_kml() { + if [[ ${#miss_package_kml[@]} -gt 0 ]]; then + logger "The ${miss_package_kml[@]} dependency is not detected in the environment." + read_answer "The system does not have dependencies such as ${miss_package_kml[@]} or the version does not meet the requirements. Are you sure you want to continue the installing the KML?" + if [[ $? != 0 ]]; then + logger "Exit the KML installation." ${TIP_COLOR_FAILED} + return 1 + fi + fi + if [[ ${kml_install_status} == ${SUCCESS} ]]; then + del_math_kml + if [[ $? == 1 ]]; then + return 1 + fi + fi + install_math_kml +} + +check_precondition_compiler() { + # Check the compiler dependency. + local compiler_type=$1 + miss_package_bisheng=() + miss_package_gcc=() + glibc_version=$(ldd --version | grep -Po '\d+.\d+\d+' | head -n 1) + version_ge "${glibc_version}" "2.17" + if [[ "$?" != 0 ]]; then + miss_package_gcc[${#miss_package_gcc[*]}]="GLIBC(>=2.17)" + miss_package_bisheng[${#miss_package_bisheng[*]}]="GLIBC(>=2.17)" + fi + if [[ ${compiler_type} == "gcc" ]]; then + if [[ ${install_package_kind} == "rpm" ]]; then + glibc_devel_version=$(${install_package_kind} -qa | grep -E "^glibc-devel" | head -n 1 | grep -Po "\d+\.\d+\d+") + glibc_devel="glibc-devel(>=2.17)" + else + glibc_devel_version=$(${install_package_kind} -l | grep "libc-dev-bin" | head -n 1 | grep -Po "\d+\.\d+\d+") + glibc_devel="libc-dev-bin(>=2.17)" + fi + version_ge "${glibc_devel_version}" '2.17' + if [[ "$?" != 0 ]]; then + miss_package_gcc[${#miss_package_gcc[*]}]="${glibc_devel}" + fi + fi + if [[ ${compiler_type} == "bisheng" ]]; then + gcc_version=$(gcc --version 2>&1 | head -n 1 | grep -Po "\d+\.\d+\.\d+" | head -n 1) + version_ge "${gcc_version}" '4.8.5' + if [[ "$?" != 0 ]]; then + miss_package_bisheng[${#miss_package_bisheng[*]}]="gcc(>=4.8.5)" + fi + libatomic_version=$(ldconfig -v 2>&1 | grep libatomic | awk -F '->' '{print $2}' | grep -Po "\d+\.\d+\.\d+") + version_ge "${libatomic_version}" '1.2.0' + if [[ "$?" != 0 ]]; then + miss_package_bisheng[${#miss_package_bisheng[*]}]="libatomic(>=1.2.0)" + fi + fi +} + +hand_precondition_compiler() { + local compiler_type=$1 + if [[ ${compiler_type} == "gcc" ]]; then + miss_package_compiler=(${miss_package_gcc[*]}) + compiler_install_status=${gcc_install_status} + else + miss_package_compiler=(${miss_package_bisheng[*]}) + compiler_install_status=${bisheng_install_status} + fi + if [[ ${#miss_package_compiler[@]} -gt 0 ]]; then + logger "The ${miss_package_compiler[@]} dependency is nit detected in the environment." + read_answer "The system does not have dependencies such as ${miss_package_compiler[@]} or the version does not meet the requirements. Are you sure you want to continue the installing the ${compiler_type^^}?" + if [[ $? != 0 ]]; then + logger "Exit the ${compiler_type^^} installation." ${TIP_COLOR_FAILED} + return 1 + fi + fi + install_compiler ${compiler_type} + if [[ $? == 1 ]]; then + logger "Exit the ${compiler_type^^} installation." ${TIP_COLOR_FAILED} + return 1 + fi +} + +check_install_user() { + # Prompt for non-root users + current_user=$(whoami) + if [[ "${current_user}" != "root" ]]; then + logger "The current user is not the root user, run the sudo bash install.sh command." ${TIP_COLOR_WARNING} + exit 1 + fi +} + +check_os_name() { + # Check whether the current system supports the installation. + get_os_name + if [[ ! "${support_os_names}" =~ "${os_name}" ]]; then + logger "The system does not support the HPC software." ${TIP_COLOR_FAILED} + exit 1 + fi +} + +check_os_architecture() { + if [[ $(uname -m) != "aarch64" ]]; then + logger "The system does not support installation. Please select the aarch64 architecture." ${TIP_COLOR_FAILED} + exit 1 + fi +} + +change_directory_owner() { + local directory="$1" + if [ -d "${directory}" ]; then + chown root:root -R ${directory} + fi +} + +change_directory_permissions() { + local directory="$1" + local bin_type="$2" + local flag=1 + local path='' + if [[ ${bin_type} ]]; then + [[ ${bin_type} == "hyper-mpi" ]] && local software_ompi_bin="${directory}/ompi/bin" && local software_ucx_bin="${directory}/ucx/bin" + [[ ${bin_type} == "gcc" ]] && local software_gcc_bin="${directory}/bin" && local software_gcc_gnu_bin="${directory}/aarch64-linux-gnu/bin" + [[ ${bin_type} == "bisheng" ]] && local software_bisheng_bin="${directory}/bin" + fi + if [[ ${customize_path_status} == 1 ]]; then + cd ${customize_path} + elif [[ ${customize_path_status} == 2 ]]; then + if [ -z ${valid_customize_path} ]; then + local customize_path_special=${customize_path} + else + cd ${valid_customize_path} + local split_path=$(echo $directory | awk -F "^${valid_customize_path}/" '{print $2}') + fi + fi + if [[ "${split_path}" ]];then + local valid_customize_path_split=${valid_customize_path} + for path in $(echo ${split_path} | tr '/' ' ');do + valid_customize_path_split=${valid_customize_path_split}/${path} + chmod 755 ${valid_customize_path_split} + done + else + local delete_last_slashes=${customize_path%%/} + for path in $(echo ${directory} | tr '/' ' ');do + local chmod_path=${chmod_path}/${path} + [[ -z "${customize_path_special}" && ${#delete_last_slashes} -ge ${#chmod_path} ]] && continue || chmod 755 ${chmod_path} + done + fi + + [[ $(ls -A "${directory}") ]] && chmod 755 -R ${directory}/* + find ${directory} -type f | xargs chmod 644 + [[ ${software_ompi_bin} ]] && find ${software_ompi_bin} -type f | xargs chmod 755 + [[ ${software_ucx_bin} ]] && find ${software_ucx_bin} -type f | xargs chmod 755 + [[ ${software_gcc_bin} ]] && find ${software_gcc_bin} -type f | xargs chmod 755 + [[ ${software_gcc_gnu_bin} ]] && find ${software_gcc_gnu_bin} -type f | xargs chmod 755 + [[ ${software_bisheng_bin} ]] && find ${software_bisheng_bin} -type f | xargs chmod 755 +} + +del_math_kml() { + # Delete the original kml environment variables + read_answer "Before the installation, the existing software will be uninstalled. Are you sure you want to authorize the script to continue?" + if [[ $? != 0 ]];then + logger "Do not install the kml repeatedly." ${TIP_COLOR_ECHO} + return 1 + fi + logger "Deleting kml" ${TIP_COLOR_ECHO} + if [[ ${install_package_kind} == "rpm" ]]; then + $install_package_kind -e "${boost_math_name}" + else + $install_package_kind -P "${boost_math_name}" + fi + logger "Deleting kml successfull" ${TIP_COLOR_ECHO} +} + +del_hyper_mpi() { + # Delete the original hyper mpi environment variables + local hyper_mpi_type="$1" + install_hyper_mpi_path="${customize_path}hyper_mpi/${hyper_mpi_type}/${hmpi_package_name}" + hyper_mpi_modules_path="${customize_path}modules/${hyper_mpi_type}/hmpi_modulefiles" + if [[ -d "${install_hyper_mpi_path}" ]] || [[ -f "${hyper_mpi_modules_path}" ]];then + [[ -f "${hyper_mpi_modules_path}" ]] && logger "${hyper_mpi_modules_path} file already exists." ${TIP_COLOR_WARNING} + [[ -d "${install_hyper_mpi_path}" ]] && logger "${install_hyper_mpi_path} directory is not empty." ${TIP_COLOR_WARNING} + read_answer "Are you sure you want to continue the instation? if yes, ${install_hyper_mpi_path} the directory or ${hyper_mpi_modules_path} file will be overwritten." + if [[ $? != 0 ]];then + logger 'Do not install the hyper-mpi repeatedly.' ${TIP_COLOR_ECHO} + return 1 + fi + [[ -f "${hyper_mpi_modules_path}" ]] && rm -rf "${hyper_mpi_modules_path}" + [[ -d "${install_hyper_mpi_path}" ]] && rm -rf "${install_hyper_mpi_path}" + logger "Deleting ${hyper_mpi_type}" ${TIP_COLOR_ECHO} + fi +} + +del_compiler() { + local compiler_type=$1 + local compiler_path="${customize_path}${compiler_type}/${compiler_name}" + local compiler_modules_path="${customize_path}modules/${compiler_type}_modulefiles" + if [[ -f "${compiler_modules_path}" ]] || [[ -d "${compiler_path}" ]];then + [[ -f "${compiler_modules_path}" ]] && logger "${compiler_modules_path} file already exists." ${TIP_COLOR_WARNING} + [[ -d "${compiler_path}" ]] && logger "${compiler_path} directory is not empty." ${TIP_COLOR_WARNING} + read_answer "Are you sure you want to continue the instllation? if yes, the ${compiler_path} directory or ${compiler_modules_path} file will be overwritten." + if [[ $? != 0 ]];then + logger "Do not install the ${compiler_type^^} repeatedly." ${TIP_COLOR_ECHO} + return 1 + fi + [[ -d "${compiler_path}" ]] && rm -rf ${compiler_path} + [[ -f "${compiler_modules_path}" ]] && rm -rf ${compiler_modules_path} + logger "Deleting ${compiler_type^^} " ${TIP_COLOR_ECHO} + fi +} diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/configure_environment.sh b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/configure_environment.sh new file mode 100644 index 0000000..0678469 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/configure_environment.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +compiler_gcc='' +compiler_gcc_install='' +compiler_bisheng='' +compiler_bisheng_install='' +hyper_mpi_gcc='' +hyper_mpi_gcc_install='' +hyper_mpi_bisheng='' +hyper_mpi_bisheng_install='' + + +configure_env(){ + # configure env + if [[ "${compiler_gcc}${compiler_bisheng}${hyper_mpi_gcc}${hyper_mpi_bisheng}test" == 'test' ]];then + echo -e "\e[1;33mYou have not installed any software. Please run the installation script before running the script.\e[0m" + exit + fi + [[ ${hyper_mpi_bisheng} ]] && set_hyper_mpi_env ${hyper_mpi_bisheng_install} + [[ ${hyper_mpi_gcc} ]] && set_hyper_mpi_env ${hyper_mpi_gcc_install} + [[ ${compiler_gcc} ]] && set_compiler_gcc_env ${compiler_gcc_install} + [[ ${compiler_bisheng} ]] && set_compiler_bisheng_env ${compiler_bisheng_install} + echo -e "\e[1;33mTo make the related commands take effect, run the following command:\e[0m" + if [[ ${hyper_mpi_bisheng} || ${hyper_mpi_gcc} ]];then + echo "source ~/.bashrc" + fi + + if [[ ${compiler_gcc} || ${compiler_bisheng} ]];then + echo "source /etc/profile" + fi +} + +set_compiler_gcc_env(){ + local install_compiler_path=$1 + echo "export PATH=${install_compiler_path}/${compiler_gcc}/bin:\$PATH" >>/etc/profile + echo "export INCLUDE=${install_compiler_path}/${compiler_gcc}/INCLUDE:\$INCLUDE" >>/etc/profile + echo "export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_gcc}/lib64:\$LD_LIBRARY_PATH" >>/etc/profile +} + +set_compiler_bisheng_env(){ + local install_compiler_path=$1 + echo "export PATH=${install_compiler_path}/${compiler_bisheng}/bin:\$PATH" >>/etc/profile + echo "export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_bisheng}/lib:\$LD_LIBRARY_PATH" >>/etc/profile + +} + +set_hyper_mpi_env(){ + local install_path=$1 + echo "hwmpi=${install_path}" >> ~/.bashrc + echo 'export OPAL_PREFIX=${hwmpi}/ompi' >> ~/.bashrc + echo 'export PATH=${hwmpi}/ompi/bin:${hwmpi}/ucx/bin:$PATH' >> ~/.bashrc + echo 'export INCLUDE=${hwmpi}/ompi/include:${hwmpi}/ucx/include:$INCLUDE' >> ~/.bashrc + echo 'export LD_LIBRARY_PATH=${hwmpi}/ompi/lib:${hwmpi}/ucx/lib:$LD_LIBRARY_PATH' >> ~/.bashrc +} + +configure_env \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.conf b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.conf new file mode 100644 index 0000000..ab49d43 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.conf @@ -0,0 +1,41 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OSs supported by HPC +SUPPORT_OS_NAME=openEuler20.03(LTS);openEuler20.03(LTS-SP1);openEuler20.03(LTS-SP2);openEuler20.03(LTS-SP3);KylinLinuxAdvancedServerV10;UnionTechOSServer20;CentOSLinuxrelease7.6.1810;Ubuntu20.04;Ubuntu18.04; +SOFTWARE_TO_BE_INSTALLED=HMPI-GCC;HMPI-BISHENG;BISHENG;GCC;KML; +KYLINV10_LINUX_HMPI_GCC_NAME=Hyper-MPI_1.1.1_aarch64_KylinV10SP2_gcc9.3.0_MLNX-OFED5.4 +KYLINV10_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_KylinV10SP2_Bisheng2.1.0_MLNX-OFED5.4 +CENTOS7.6_LINUX_HMPI_GCC_NAME=Hyper-MPI_1.1.1_aarch64_CentOS7.6_GCC9.3_MLNX-OFED5.0 +CENTOS7.6_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_CentOS7.6_Bisheng2.1.0_MLNX-OFED5.0 +OPENEULER20.03_LTS_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_OpenEuler20.03-LTS_Bisheng2.1.0_MLNX-OFED5.4 +OPENEULER20.03_SP1_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_OpenEuler20.03SP1_Bisheng2.1.0_MLNX-OFED5.4 +OPENEULER20.03_SP1_LINUX_HMPI_GCC_NAME=Hyper-MPI_1.1.1_aarch64_OpenEuler20.03SP1_gcc9.3.0_MLNX-OFED5.4 +BISHENG_COMPILER_NAME=bisheng-compiler-2.1.0-aarch64-linux +GCC_COMPILER_NAME=gcc-10.3.1-2021.09-aarch64-linux +LIBRARY_MATH_DEB_NAME=boostkit-kml-1.6.0.aarch64 +LIBRARY_MATH_RPM_NAME=boostkit-kml-1.6.0-1.aarch64 +HYPER_MPI_INSTALL_FILTER_SYSTEM=openEuler20.03(LTS-SP1);KylinLinuxAdvancedServerV10;CentOSLinuxrelease7.6.1810 +# Color of the terminal input +TIP_COLOR_FAILED=31 +TIP_COLOR_SUCCESS=32 +TIP_COLOR_WARNING=33 +TIP_COLOR_COMMAND=35 +TIP_COLOR_CHECKING=36 +TIP_COLOR_ECHO=37 +# The maximum drive space is 3GB +LOW_SPACE=3145728 +LOW_SPACE_PACKAGE_G=3 +# User-defined path format +ALLOW_STRING="_-" diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.sh b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.sh new file mode 100644 index 0000000..8c8bc4e --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/const.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Read the configuration file and use it as the global variable of the installation script +current_dir=$( + cd $(dirname $0) + pwd +) +# Supported OSs +support_os_names=$(sed '/^SUPPORT_OS_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) + +declare -A software_support_lists=(["openEuler20.03(LTS)"]="HMPI-BISHENG BISHENG GCC KML" + ["openEuler20.03(LTS-SP1)"]="HMPI-GCC HMPI-BISHENG BISHENG GCC KML" + ["openEuler20.03(LTS-SP2)"]="BISHENG GCC KML" + ["openEuler20.03(LTS-SP3)"]="BISHENG GCC KML" + ["KylinLinuxAdvancedServerV10"]="HMPI-GCC HMPI-BISHENG BISHENG GCC" + ["UnionTechOSServer20"]="BISHENG GCC" + ["CentOSLinuxrelease7.6.1810"]="HMPI-GCC HMPI-BISHENG BISHENG GCC KML" + ["Ubuntu20.04"]="BISHENG GCC KML" + ["Ubuntu18.04"]="BISHENG GCC KML" + ["KylinLinuxAdvancedServerV10_HMPI_GCC"]="${kylinv10_hmpi_gcc_name}" + ["KylinLinuxAdvancedServerV10_HMPI_BISHENG"]="${kylinv10_hmpi_bisheng_name}" + ["CentOSLinuxrelease7.6.1810_HMPI_GCC"]="${centos7_6_linux_hmpi_gcc_name}" + ["CentOSLinuxrelease7.6.1810_HMPI_BISHENG"]="${centos7_6_hmpi_bisheng_name}" +) +# Minimum drive size +low_space=$(sed '/^LOW_SPACE=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +low_space_package_g=$(sed '/^LOW_SPACE_PACKAGE_G=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +# Math library name +boost_math_name="boostkit-kml" +boost_math_rpm_name=$(sed '/^LIBRARY_MATH_RPM_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +boost_math_deb_name=$(sed '/^LIBRARY_MATH_DEB_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +bisheng_compiler_name=$(sed '/^BISHENG_COMPILER_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +gcc_compiler_name=$(sed '/^GCC_COMPILER_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +kylinv10_hmpi_gcc_name=$(sed '/^KYLINV10_LINUX_HMPI_GCC_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +kylinv10_hmpi_bisheng_name=$(sed '/^KYLINV10_LINUX_HMPI_BISHENG_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +centos7_6_linux_hmpi_gcc_name=$(sed '/^CENTOS7.6_LINUX_HMPI_GCC_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +centos7_6_hmpi_bisheng_name=$(sed '/^CENTOS7.6_LINUX_HMPI_BISHENG_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +openeuler20_03_lts_hmpi_bisheng_name=$(sed '/^OPENEULER20.03_LTS_LINUX_HMPI_BISHENG_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +hyper_mpi_install_filter_system=$(sed '/^HYPER_MPI_INSTALL_FILTER_SYSTEM=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +hyper_mpi_gcc_package_names=(${kylinv10_hmpi_gcc_name} ${centos7_6_linux_hmpi_gcc_name}) +hyper_mpi_bisheng_package_names=(${kylinv10_hmpi_bisheng_name} ${centos7_6_hmpi_bisheng_name} ${openeuler20_03_lts_hmpi_bisheng_name}) +# List of software to be installed +software_to_be_installed=$(sed '/^SOFTWARE_TO_BE_INSTALLED=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +# User-defined path rule +ALLOW_STRING=$(sed '/^ALLOW_STRING=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +# Success or failure status +SUCCESS=1 +FAILED=0 +# Color processing for terminal output +TIP_COLOR_FAILED=$(sed '/^TIP_COLOR_FAILED=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # red +TIP_COLOR_SUCCESS=$(sed '/^TIP_COLOR_SUCCESS=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # green +TIP_COLOR_WARNING=$(sed '/^TIP_COLOR_WARNING=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # yellow +TIP_COLOR_COMMAND=$(sed '/^TIP_COLOR_COMMAND=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # purple +TIP_COLOR_CHECKING=$(sed '/^TIP_COLOR_CHECKING=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # blue +TIP_COLOR_ECHO=$(sed '/^TIP_COLOR_ECHO=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # white \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/install.sh b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/install.sh new file mode 100644 index 0000000..23ad579 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Development_framework/hpc-sdk/script/install.sh @@ -0,0 +1,544 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +current_dir=$( + cd $(dirname $0) + pwd +) +source ${current_dir}/const.sh +source ${current_dir}/common_fun.sh +install_package_dir=${current_dir}/../package +module_file_dir=${current_dir}/../module +time_stamp=$(date +%s) +# Press ctrl-c to capture terminal disconnection exceptions. +trap 'onCtrlC' INT +trap 'onCtrlZ' SIGTSTP +trap 'onDisconnect' HUP + +set_software_status() { + # Obtain the installation status of supported software. + check_result_list=() + suggestion_list=() + software_support_list=${software_support_lists["$os_name"]} + for software_support in $(echo $software_support_list | tr ' ' ' '); do + if [[ ${software_support} =~ ^HMPI-GCC$|^HMPI-BISHENG$|^BISHENG$|^GCC$|^KML$ ]]; then + check_result_list[${#check_result_list[*]}]='Y' + fi + done +} + +get_hyper_mpi_package_name() { + # Obtain the HMPI package name. + if [[ "${os_name}" =~ "KylinLinux" ]]; then + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${kylinv10_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${kylinv10_hmpi_bisheng_name} + fi + elif [[ "${os_name}" =~ "CentOSLinux" ]]; then + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${centos7_6_linux_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${centos7_6_hmpi_bisheng_name} + fi + elif [[ "${os_name}" =~ "openEuler20.03" ]]; then + if [[ "${os_name}" == "openEuler20.03(LTS-SP1)" ]]; then + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${openeuler20_03_SP1_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${openeuler20_03_SP1_hmpi_bisheng_name} + fi + else + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${openeuler20_03_lts_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${openeuler20_03_lts_hmpi_bisheng_name} + fi + fi + fi +} + +check_software_installed() { + # Check the installed software + case $1 in + "HMPI-GCC"|"HMPI-BISHENG") + hmpi_gcc_install_status=${FAILED} + hmpi_bisheng_install_status=${FAILED} + hyper_install_status=${FAILED} + which mpirun >/dev/null 2>&1 + if [[ $? == 0 ]]; then + hyper_install_status=${SUCCESS} + hmpi_name_string=$(which mpirun | awk -F "/ompi/bin/mpirun" '{print $1}') + if [[ "${hyper_mpi_gcc_package_names[@]}" =~ "${hmpi_name_string##*/}" ]];then + hmpi_gcc_install_status=${SUCCESS} + fi + if [[ "${hyper_mpi_bisheng_package_names[@]}" =~ "${hmpi_name_string##*/}" ]];then + hmpi_bisheng_install_status=${SUCCESS} + fi + fi + ;; + "GCC") + if gcc -v 2>&1 | grep -q "Kunpeng gcc 10.3.1-2.0.0.b020"; then + gcc_install_status=${SUCCESS} + else + gcc_install_status=${FAILED} + if grep -q "gcc-10.3.1-2021.09-aarch64-linux" /etc/profile; then + gcc_install_status=${SUCCESS} + fi + fi + ;; + "BISHENG") + # clang -v Standard errot output 2>&1 + check_system_bisheng_status + ;; + "KML") + [[ ${install_package_kind} == "rpm" ]] && result=$(${install_package_kind} -qa ${boost_math_name}) || result=$(${install_package_kind} -l ${boost_math_name}) + [[ "${result}" ]] && kml_install_status=${SUCCESS} || kml_install_status=${FAILED} + ;; + esac +} + +check_system_gcc_status() { + # Check whether the GCC version in the system is supported. + install_reply=$1 + [[ ${install_reply} == "kml" ]] && gcc_support_version='7.3.0' || gcc_support_version='9.3.0' + gcc_version=$(gcc --version 2>&1 | head -n 1 | grep -Po "\d+\.\d+\.\d+" | head -n 1) + if [[ ${install_reply} == "kml" ]]; then + version_ge ${gcc_version} ${gcc_support_version} + [[ "$?" == "0" ]] && gcc_kml_check_status=${SUCCESS} || gcc_kml_check_status=${FAILED} + else + [[ ${gcc_support_version} == ${gcc_version} ]] && gcc_hmpi_check_status=${SUCCESS} || gcc_hmpi_check_status=${FAILED} + fi +} + +check_system_bisheng_status() { + # Check whether the Bisheng version in the system is supported. + if clang -v 2>&1 | grep -q "HUAWEI BiSheng Compiler 2.1.0.B010 clang version 12.0.0"; then + bisheng_check_status=${SUCCESS} + else + bisheng_check_status=${FAILED} + if grep -q "bisheng-compiler-2.1.0-aarch64-linux" /etc/profile; then + bisheng_check_status=${SUCCESS} + fi + fi +} + +set_software_choose_status() { + # Set the status of the software selected by the user. + [[ "${select_result}" =~ ^GCC*$|,GCC* ]] && gcc_choose_status=${SUCCESS} || gcc_choose_status=${FAILED} + [[ "${select_result}" =~ ^BISHENG*$|,BISHENG* ]] && bisheng_choose_status=${SUCCESS} || bisheng_choose_status=${FAILED} + [[ "${select_result}" =~ "HMPI-GCC" ]] && hmpi_gcc_choose_status=${SUCCESS} || hmpi_gcc_choose_status=${FAILED} + [[ "${select_result}" =~ "HMPI-BISHENG" ]] && hmpi_bisheng_choose_status=${SUCCESS} || hmpi_bisheng_choose_status=${FAILED} + [[ "${select_result}" =~ "KML" ]] && kml_choose_status=${SUCCESS} || kml_choose_status=${FAILED} +} + +install_hyper_mpi_env_check() { + # Check the hyper mpi installation environment. + hmpi_type=$1 + [[ ${hmpi_type} == "gcc" ]] && hmpi_choose_status=${hmpi_gcc_choose_status} || hmpi_choose_status=${hmpi_bisheng_choose_status} + if [[ ${hmpi_choose_status} == ${FAILED} ]]; then + return 1 + fi + [[ ${hmpi_type} == "gcc" ]] && hmpi_install_status=${hmpi_gcc_install_status} || hmpi_install_status=${hmpi_bisheng_install_status} + [[ ${hmpi_type} == "gcc" ]] && compiler_choose_status=${gcc_choose_status} || compiler_choose_status=${bisheng_choose_status} + [[ ${hmpi_type} == "gcc" ]] && compiler_hmpi_check_status=${gcc_hmpi_check_status} || compiler_hmpi_check_status=${bisheng_check_status} + logger "Start installing the HMPI-${hmpi_type^^}." ${TIP_COLOR_CHECKING} + unset miss_package + if [[ ! -f ${install_package_dir}/hyper_mpi/"${hmpi_package_name}.tar.gz" ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + fi + if [[ ${hyper_install_status} == ${SUCCESS} ]];then + if [[ ${hmpi_gcc_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "gcc" ]];then + answer_msg="The HPMI-${hmpi_type^^} already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + if [[ ${hmpi_gcc_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "bisheng" ]];then + answer_msg="The HPMI-GCC already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + if [[ ${hmpi_bisheng_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "gcc" ]];then + answer_msg="The HPMI-BISHENG already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + if [[ ${hmpi_bisheng_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "bisheng" ]];then + answer_msg="The HPMI-${hmpi_type^^} already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + logger "Hyper-mpi is installed in this system" ${TIP_COLOR_WARNING} + read_answer "${answer_msg}" + if [[ $? != 0 ]]; then + logger "Do not install the hyper-mpi repeatedly." ${TIP_COLOR_ECHO} + return 1 + fi + fi + if [[ ${compiler_hmpi_check_status} == ${SUCCESS} ]]; then + hand_precondition_mpi + return 0 + fi + [[ ${hmpi_type} == "gcc" ]] && logger "The gcc version must be 9.3.0 in the system where the hmpi-gcc is to be installed" ${TIP_COLOR_WARNING} + [[ ${hmpi_type} == "gcc" ]] && miss_package[${#miss_package[*]}]="${hmpi_type}(9.3.0)" + hand_precondition_mpi +} + +install_kml_env_check() { + # Check the math library + if [[ ${kml_choose_status} == ${FAILED} ]]; then + return 1 + fi + logger "Start installing the KML." ${TIP_COLOR_CHECKING} + check_precondition_kml ${install_package_kind} + if [[ ${install_package_kind} == "rpm" ]] && [[ ! -f ${install_package_dir}/kml/${boost_math_rpm_name}.rpm ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + elif [[ ${install_package_kind} == "dpkg" ]] && [[ ! -f ${install_package_dir}/kml/${boost_math_deb_name}.deb ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + fi + if [[ ${kml_install_status} == ${SUCCESS} ]]; then + logger "The KML already exists. Are you sure you want to continue installing the KML?" + read_answer "The KML already exists. Are you sure you want to continue installing the KML?" + if [[ $? != 0 ]]; then + logger "The KML already exists. Are you sure you want to continue installing the KML? N" + logger "Do not install the KML repeatedly." ${TIP_COLOR_FAILED} + return 1 + fi + fi + if [[ ${gcc_kml_check_status} == ${SUCCESS} ]]; then + hand_precondition_kml + return 0 + fi + miss_package_kml[${#miss_package_kml[*]}]='gcc(>=7.3.0)' + hand_precondition_kml +} + +install_compiler_env_check() { + # Check the compiler before installation. + local compiler_type=$1 + [[ ${compiler_type} == "gcc" ]] && compiler_choose_status=${gcc_choose_status} || compiler_choose_status=${bisheng_choose_status} + if [[ ${compiler_choose_status} == ${SUCCESS} ]]; then + [[ ${compiler_type} == "gcc" ]] && compiler_install_status=${gcc_install_status} || compiler_install_status=${bisheng_check_status} + [[ ${compiler_type} == "gcc" ]] && compiler_name=${gcc_compiler_name} || compiler_name=${bisheng_compiler_name} + check_precondition_compiler ${compiler_type} + logger "Start installing the ${compiler_type^^}." ${TIP_COLOR_CHECKING} + if [[ ! -f ${install_package_dir}/${compiler_type}/"${compiler_name}.tar.gz" ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + fi + # Check whether the compiler is installed. + if [[ ${compiler_install_status} == ${SUCCESS} ]]; then + logger "The ${compiler_type^^} already exists. Are you sure you want to continue installing the ${compiler_type^^}?" + read_answer "The ${compiler_type^^} already exists. Are you sure you want to continue installing the ${compiler_type^^}?" + if [[ $? != 0 ]]; then + logger "Do not install the ${compiler_type^^} repeatedly." ${TIP_COLOR_FAILED} + return 1 + fi + fi + if [[ ${compiler_type} == "gcc" ]];then + hand_precondition_compiler "gcc" + else + hand_precondition_compiler "bisheng" + fi + [[ $? == 1 ]] && return 1 + fi + if [[ ${compiler_type} == "gcc" ]]; then + # Check whether the GCC in the systecm meets the requirements. If no, add a mark. + check_system_gcc_status "kml" + check_system_gcc_status "hmpi" + else + check_system_bisheng_status + fi +} + +authorization_configure_env(){ + local software_name=$1 + local configure_type=$2 + [[ $configure_type == 'profile' ]] && configure_file='/etc/profile' || configure_file="${HOME}/.bashrc" + n=1 + while true;do + read -p "The script automatically adds the environment variables of the ${software_name^^} software to the ${configure_file} file. [Y/N]: " Y_N + if [[ ${Y_N} =~ ^y$|^Y$ ]];then + [[ ${software_name} =~ 'HMPI' ]] && add_hyper_mpi_enviroment + [[ ${software_name} =~ gcc|bisheng ]] && add_compiler_enviroment + break + elif [[ ${Y_N} =~ ^n$|^N$ ]];then + echo 'You do not allow scripts to automatically configure environment variables.' + echo '' + break + else + echo 'Incorrect input. Enter y/Y or n/N' + fi + done +} + +add_hyper_mpi_enviroment(){ + cd ${install_hmpi_path}/${hmpi_package_name} + echo "hwmpi=$PWD" >> ~/.bashrc + echo "export OPAL_PREFIX=\${hwmpi}/ompi" >> ~/.bashrc + echo "export PATH=\${hwmpi}/ompi/bin:\${hwmpi}/ucx/bin:\$PATH" >> ~/.bashrc + echo "export INCLUDE=\${hwmpi}/ompi/include:\${hwmpi}/ucx/include:\$INCLUDE" >> ~/.bashrc + echo "export LD_LIBRARY_PATH=\${hwmpi}/ompi/lib:\${hwmpi}/ucx/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc +} + +install_hyper_mpi() { + # Install Hyper MPI + user_customize_path 'hyper-mpi' + logger "You choose to install Hyper MPI in the $(cd ${customize_path};pwd) directory." ${TIP_COLOR_SUCCESS} + cd ${install_package_dir}/hyper_mpi + [[ ${hmpi_gcc_choose_status} == 1 ]] && install_hyper_mpi_name="hyper_mpi_gcc" + [[ ${hmpi_bisheng_choose_status} == 1 ]] && install_hyper_mpi_name="hyper_mpi_bisheng" + del_hyper_mpi "${install_hyper_mpi_name}" + if [[ $? == 1 ]];then + return 1 + fi + cd ${install_package_dir}/hyper_mpi + install_hmpi_path=${customize_path}hyper_mpi/${install_hyper_mpi_name} + if [ ! -d "${install_hmpi_path}" ]; then + mkdir -p ${install_hmpi_path} + fi + tar -xf ${hmpi_package_name}.tar.gz -C ${install_hmpi_path} + cd ${install_hmpi_path}/${hmpi_package_name} + # Suggestions for setting Hyper MPI environment variables + command_pwd=" echo 'hwmpi=$PWD' >> ~/.bashrc" + command_opal_prefix=" echo 'export OPAL_PREFIX=\${hwmpi}/ompi' >> ~/.bashrc" + command_path=" echo 'export PATH=\${hwmpi}/ompi/bin:\${hwmpi}/ucx/bin:\$PATH' >> ~/.bashrc" + command_include=" echo 'export INCLUDE=\${hwmpi}/ompi/include:\${hwmpi}/ucx/include:\$INCLUDE' >> ~/.bashrc" + command_ld_library_path=" echo 'export LD_LIBRARY_PATH=\${hwmpi}/ompi/lib:\${hwmpi}/ucx/lib:\$LD_LIBRARY_PATH' >> ~/.bashrc" + logger "Hyper MPI is installed." + if [[ ${hmpi_gcc_choose_status} == 1 ]]; then + change_modules "HMPI-GCC" + hmpi_gcc_installed=1 + sed -i "s#hyper_mpi_gcc=.*#hyper_mpi_gcc=${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#hyper_mpi_gcc_install=.*#hyper_mpi_gcc_install=${install_hmpi_path}/${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + elif [[ ${hmpi_bisheng_choose_status} == 1 ]]; then + change_modules "HMPI-BISHENG" + hmpi_bisheng_installed=1 + sed -i "s#hyper_mpi_bisheng=.*#hyper_mpi_bisheng=${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#hyper_mpi_bisheng_install=.*#hyper_mpi_bisheng_install=${install_hmpi_path}/${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + fi + change_directory_owner "${install_hmpi_path}/${hmpi_package_name}" + change_directory_permissions "${install_hmpi_path}/${hmpi_package_name}" "hyper-mpi" + [[ "${install_hyper_mpi_name}" == "hyper_mpi_bisheng" ]] && install_hyper_mpi_tip="HMPI-BISHENG" || install_hyper_mpi_tip="HMPI-GCC" + authorization_configure_env ${install_hyper_mpi_tip} 'bashrc' + logger "To make the related commands take effect, run the following command:" ${TIP_COLOR_WARNING} + logger "${command_pwd}" ${TIP_COLOR_COMMAND} + logger "${command_opal_prefix}" ${TIP_COLOR_COMMAND} + logger "${command_path}" ${TIP_COLOR_COMMAND} + logger "${command_include}" ${TIP_COLOR_COMMAND} + logger "${command_ld_library_path}" ${TIP_COLOR_COMMAND} + logger " source ~/.bashrc" ${TIP_COLOR_COMMAND} + logger "Use module set env for ${install_hyper_mpi_tip}" ${TIP_COLOR_SUCCESS} + logger " module load ${show_modulefile_path}" ${TIP_COLOR_COMMAND} + logger "The ${install_hyper_mpi_tip} is installed." ${TIP_COLOR_SUCCESS} +} + + +add_compiler_enviroment(){ + cd ${install_compiler_path}/${compiler_name} + if [[ ${compiler_type} == "gcc" ]]; then + echo "export PATH=${install_compiler_path}/${compiler_name}/bin:\$PATH" >>/etc/profile + echo "export INCLUDE=${install_compiler_path}/${compiler_name}/include:\$INCLUDE" >>/etc/profile + echo "export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_name}/lib64:\$LD_LIBRARY_PATH" >>/etc/profile + fi + if [[ ${compiler_type} == "bisheng" ]]; then + echo "export PATH=${install_compiler_path}/${compiler_name}/bin:\$PATH" >>/etc/profile + echo "export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_name}/lib:\$LD_LIBRARY_PATH" >>/etc/profile + fi +} + +install_compiler() { + # Install compiler + local compiler_type=$1 + user_customize_path "${compiler_type} compiler" + logger "you choose install ${compiler_type} path is $(cd ${customize_path};pwd)" ${TIP_COLOR_SUCCESS} + del_compiler "${compiler_type}" + if [[ $? == 1 ]];then + return 1 + fi + cd ${install_package_dir}/${compiler_type} + install_compiler_path=${customize_path}${compiler_type} + if [ ! -d ${install_compiler_path} ]; then + mkdir -p ${install_compiler_path} + fi + tar -xf ${compiler_name}.tar.gz -C ${install_compiler_path} + cd ${install_compiler_path}/${compiler_name} + if [[ ${compiler_type} == "bisheng" ]]; then + change_modules "BISHENG" + bisheng_installed=1 + sed -i "s#compiler_bisheng=.*#compiler_bisheng=${compiler_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#compiler_bisheng_install=.*#compiler_bisheng_install=${install_compiler_path}#g" ${current_dir}/configure_environment_${time_stamp}.sh + else + change_modules "GCC" + gcc_installed=1 + sed -i "s#compiler_gcc=.*#compiler_gcc=${compiler_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#compiler_gcc_install=.*#compiler_gcc_install=${install_compiler_path}#g" ${current_dir}/configure_environment_${time_stamp}.sh + fi + if [[ ${compiler_type} == "gcc" ]]; then + command_env_path=" echo 'export PATH=${install_compiler_path}/${compiler_name}/bin:\$PATH' >>/etc/profile" + command_env_include=" echo 'export INCLUDE=${install_compiler_path}/${compiler_name}/include:\$INCLUDE' >>/etc/profile" + command_env_ld_library_path=" echo 'export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_name}/lib64:\$LD_LIBRARY_PATH' >>/etc/profile" + command_module=" module load ${show_modulefile_path}" + fi + if [[ ${compiler_type} == "bisheng" ]]; then + command_env_path=" echo 'export PATH=${install_compiler_path}/${compiler_name}/bin:\$PATH' >>/etc/profile" + command_env_ld_library_path=" echo 'export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_name}/lib:\$LD_LIBRARY_PATH' >>/etc/profile" + command_module=" module load ${show_modulefile_path}" + fi + change_directory_owner "${install_compiler_path}/${compiler_name}" + change_directory_permissions "${install_compiler_path}/${compiler_name}" "${compiler_type}" + authorization_configure_env ${compiler_type} 'profile' + logger "To make the related commands take effect, run the following command:" ${TIP_COLOR_WARNING} + [[ ${command_env_path} ]] && logger "${command_env_path}" ${TIP_COLOR_COMMAND} + [[ ${command_env_include} && ${compiler_type} == "gcc" ]] && logger "${command_env_include}" ${TIP_COLOR_COMMAND} + [[ ${command_env_ld_library_path} ]] && logger "${command_env_ld_library_path}" ${TIP_COLOR_COMMAND} + logger " source /etc/profile" ${TIP_COLOR_COMMAND} + logger "use module set env for $compiler_type" ${TIP_COLOR_SUCCESS} + logger "${command_module}" ${TIP_COLOR_COMMAND} + logger "The ${compiler_type} Compiler is installed." ${TIP_COLOR_SUCCESS} +} + +install_math_kml() { + # Install KML + check_space /usr/local + if [[ ${install_package_kind} == "rpm" ]]; then + $install_package_kind -ivh ${install_package_dir}/kml/${boost_math_rpm_name}.rpm + else + $install_package_kind -i ${install_package_dir}/kml/${boost_math_deb_name}.deb + fi + if [[ $? -ne 0 ]];then + logger "Failed to install the math library." ${TIP_COLOR_FAILED} + return 1 + fi + nm_math_kml + if [[ $? -ne 0 ]];then + logger "Failed to install the math library." ${TIP_COLOR_FAILED} + return 1 + fi + logger "To make the related commands take effect, run the following command: source /etc/profile" ${TIP_COLOR_WARNING} + logger "The math library is installed." ${TIP_COLOR_SUCCESS} +} + +nm_math_kml() { + # Add math library symbols + # /usr/local/kml/lib is the default path for installing the math library. + logger "Generating a Complete LAPACK..." ${TIP_COLOR_CHECKING} + cp -rf ${install_package_dir}/kml/liblapack_adapt.a /usr/local/kml/lib + cp -rf ${install_package_dir}/kml/libblas.a /usr/local/kml/lib + cd /usr/local/kml/lib + klapack=/usr/local/kml/lib/libklapack.a + # get symbols defined both in klapack and netlib lapack + nm -g liblapack_adapt.a | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq >netlib.sym + nm -g $klapack | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq >klapack.sym + comm -12 klapack.sym netlib.sym >comm.sym + + # update symbols name of liblapack_adapt.a + while read sym; do + if ! nm liblapack_adapt.a | grep -qe " T ${sym}_\$"; then + continue + fi + ar x liblapack_adapt.a $sym.f.o >/dev/null 2>&1 + mv $sym.f.o ${sym}_netlib.f.o + objcopy --redefine-sym ${sym}_=${sym}_netlib_ ${sym}_netlib.f.o + ar d liblapack_adapt.a ${sym}.f.o >/dev/null 2>&1 + ar ru liblapack_adapt.a ${sym}_netlib.f.o >/dev/null 2>&1 + rm ${sym}_netlib.f.o + done +#include +#include + +int main() +{ + const unsigned arraySize = 32768; + int data[arraySize]; + + for (unsigned c = 0; c < arraySize; ++c) + data[c] = std::rand() % 256; + std::sort(data, data + arraySize); + + clock_t start = clock(); + long long sum = 0; + + for (unsigned i = 0; i < 100000; ++i) + { + for (unsigned c = 0; c < arraySize; ++c) + { + if (data[c] >= 128) + sum += data[c]; + } + } + double elapsedTime = static_cast(clock() - start) / CLOCKS_PER_SEC; + std::cout << elapsedTime << std::endl; + std::cout << "sum = " << sum << std::endl; + return 0; +} diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/CPU\345\210\206\346\224\257\351\242\204\346\265\213/cpu_branch_prediction_before.cpp" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/CPU\345\210\206\346\224\257\351\242\204\346\265\213/cpu_branch_prediction_before.cpp" new file mode 100644 index 0000000..10a5781 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/CPU\345\210\206\346\224\257\351\242\204\346\265\213/cpu_branch_prediction_before.cpp" @@ -0,0 +1,29 @@ +#include +#include +#include + +int main() +{ + const unsigned arraySize = 32768; + int data[arraySize]; + + for (unsigned c = 0; c < arraySize; ++c) + data[c] = std::rand() % 256; + //std::sort(data, data + arraySize); + + clock_t start = clock(); + long long sum = 0; + + for (unsigned i = 0; i < 100000; ++i) + { + for (unsigned c = 0; c < arraySize; ++c) + { + if (data[c] >= 128) + sum += data[c]; + } + } + double elapsedTime = static_cast(clock() - start) / CLOCKS_PER_SEC; + std::cout << elapsedTime << std::endl; + std::cout << "sum = " << sum << std::endl; + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/core_bound.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/core_bound.c new file mode 100644 index 0000000..5e34174 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/core_bound.c @@ -0,0 +1,40 @@ +#include "utils.h" + +#define LOOP_SIZE 1024 +#define INTRA_LOOP_SIZE 20480000 + +void CoreBoundBench() +{ + int i ; + __asm__ volatile(".rept 3 \n\t" + "nop \n\t" + ".endr"); + __asm__ volatile("mov x12, 2"); + for (i = 0; i < INTRA_LOOP_SIZE; i++) { + __asm__ volatile("sdiv x11, x11, x12"); + } +} + +void CoreBoundBench_OPT() +{ + int i ; + __asm__ volatile(".rept 3 \n\t" + "nop \n\t" + ".endr"); + for (i = 0; i < INTRA_LOOP_SIZE; i++) { + __asm__ volatile("lsr x11, x11, #1"); + } +} + +int main() +{ + uint64_t ts_start = GetTime_ns(); + int i; + for (i = 0; i < LOOP_SIZE; i++) { + CoreBoundBench(); + //CoreBoundBench_OPT(); + } + uint64_t ts_end = GetTime_ns(); + printf("Total Cost Time = %f ms\n", (ts_end - ts_start) / 1000000.0); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/memory_bound.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/memory_bound.c new file mode 100644 index 0000000..38012b6 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/memory_bound.c @@ -0,0 +1,60 @@ +#include "utils.h" + +#define MAX_ARRAY_SIZE 409600 +#define LOOP_SIZE 1 +#define BLOCK_SIZE 4096 + +void MemoryBoundBench(Point *pointA, double *ret, int n) +{ + if (pointA == NULL || ret == NULL) { + return; + } + + int i, j; + #pragma omp parallel for + for (i = 0; i < n; i ++) { + ret[i] = 0.0; + for (j = 0; j < n; j++) { + ret[i] += pointA[i].x + pointA[j].y; + } + } +} + +void MemoryBoundBench_OPT(Point *pointA, double *ret, int n) +{ + if (pointA == NULL || ret == NULL) { + return; + } + + int i, j, k; + for (k = 0; k< n; k += BLOCK_SIZE) { + #pragma omp parallel for + for (i = 0; i < n; i ++) { + ret[i] = 0.0; + for (j = 0; j < BLOCK_SIZE; j++) { + ret[i] += pointA[i].x + pointA[j + k].y; + } + } + } +} + +int main() +{ + Point *pointA = InitPointsVector(MAX_ARRAY_SIZE); + + double *ret = (double*)malloc(MAX_ARRAY_SIZE * sizeof(double)); + if (ret == NULL) { + printf("ERROR: Memory Allocate Failed!\n"); + exit(1); + } + + uint64_t ts_start = GetTime_ns(); + int i; + for (i = 0; i < LOOP_SIZE; i++) { + MemoryBoundBench(pointA, ret, MAX_ARRAY_SIZE); + //MemoryBoundBench_OPT(pointA, ret, MAX_ARRAY_SIZE); + } + uint64_t ts_end = GetTime_ns(); + printf("Total Cost Time = %f ms\n", (ts_end - ts_start) / 1000000.0); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/omp_utilization.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/omp_utilization.c new file mode 100644 index 0000000..85b65ab --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/omp_utilization.c @@ -0,0 +1,48 @@ +#include "utils.h" + +#define MAX_ARRAY_SIZE 4096000 +#define LOOP_SIZE 10240 + +void OmpUtilBench(Point *pointA, Point *pointB, double *pointDis, int n) +{ + assert(pointA != NULL && pointB != NULL && pointDis != NULL); + int i; + omp_set_num_threads(48); + #pragma omp parallel for shared (n) private (i) + for (i = 0; i < n; i++) { + pointDis[i] = ComputPointDistance(&pointA[i], &pointB[i]); + } +} + +void OmpUtilBench_OPT(Point *pointA, Point *pointB, double *pointDis, int n) +{ + assert(pointA != NULL && pointB != NULL && pointDis != NULL); + int i; + + #pragma omp parallel for shared (n) private (i) + for (i = 0; i < n; i++) { + pointDis[i] = ComputPointDistance(&pointA[i], &pointB[i]); + } +} + +int main() +{ + int i; + Point *pointA = InitPointsVector(MAX_ARRAY_SIZE); + Point *pointB = InitPointsVector(MAX_ARRAY_SIZE); + + double *pointDis = (double*)malloc(MAX_ARRAY_SIZE * sizeof(double)); + if (pointDis == NULL) { + printf("ERROR: Memory Allocate Failed!\n"); + exit(1); + } + + uint64_t ts_start = GetTime_ns(); + for (i = 0; i < LOOP_SIZE; i++) { + OmpUtilBench(pointA, pointB, pointDis, MAX_ARRAY_SIZE); + //OmpUtilBench_OPT(pointA, pointB, pointDis, MAX_ARRAY_SIZE); + } + uint64_t ts_end = GetTime_ns(); + printf("Total Cost Time = %f ms\n", (ts_end - ts_start) / 1000000.0); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/send_recv b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/send_recv new file mode 100644 index 0000000000000000000000000000000000000000..fdf25f92cd76cc5f16b91adf47e337b8e04f0acd GIT binary patch literal 71632 zcmeI1eQ;FQb->T=6GB1~NPJ0#U@eZ_5@J>o2mwxJyjmfI5(x;%fn-`gKkYtgcUbMp zZ&z4Y{Scuup{+Y371@?Eu>+XNAnMMz6EY<;`M`EF<7sA6uxp%75~C2@l5r-bgkY&- zu|4O#d!)B-SDJR*PX9R*%g*M9W$`xxG!Mb?9i3ZLZVVN?pOWI z$7N8BpQS?upe_;bu1iEWCF03}!A*u?MPf~j!E`Fv;LMxylW*Ie$LyYHy%*ax=ZAFi zq4Cp_mE+|u6iZ!`AFVgdZ7E)qgBUNtix4fti%O{@>=^Q+c$-HEvxK0MY~=ert@+cV zWryx!wP2xTUS6Q(_t6$8U_XksLjGTy$38lbo#qn2%Uhbz5bzpN{}o<^`u)Rs?8oP^ zU!2GO@AKFRT%mpsqrD1hAO>NqVWGvtauzS!?$5OY?w>x|FHNAgcXjGf(=vPG>5OT0 zb+#l@Nwdr7PMDzUy?v>qp3WFnM%NwJf{v7~KTZi7>!EXByWW!O>(kTmr%gy|JxyJbd>%z0Tx@~~r1#xqVOZ6>3xK+5%0%1T7-)?M+Wk)X`jDJI8Gsn(x~S*8)C zA=Hx|ab{<9r>qS0Tk&M32htfUVJ2}_)UIaLXT+1x*3lkr(KiPhwm}_sbU58_M9jMW zf$l^+QkPEkWS%lCvkoUw7o(qsApWcCj;CX0vKOO*^>s8$x+#&jLQnXyu;!nwk=2L) zuA$^};Q7(#@OJUTGP-fFT+TMz(uX%FXCT8*Tz2<)GwHIs@AKLHfO+U1)_7&OP8#*V28!!!CU(>fJ7VIqF|=>8nvcll z{<=%QANA`l{Q=bdzPbK?5A_FJ`bN~lj=m0t-?|^K_cb{G3oSH#{gW{IuQ+dj$+rM5 z-G-7=w}%^!-PTaoP}fk`BFAnQpd~gaM$G<@T^}lYL#@&7)0JT@=^Is3}qxB!PoLv7=^Izh1 z@-_6oj-O5-z_DhJYgcB5N+Fc0NTpD7(Z9f2#8+KTfpqV4nnr%vq`UwC2vm$sbTzY6_U1B|S}>yB2tar}kv zSUa}7Y<>HTZ}jTj;OLj%2#(^JzH&G6Z$A*4n#47@xfrH@^)^h6VIDjKs>t@u<8UQf zKD__Bw(9&ZG0*$hXFs-&6+_iG{@V9sXc2UsJO22^H)pb2&%N>Z#oAJM^3&OD*NH!= zSzEH`#ENY=?^@q|hr9jI#rck5zPX&$cFu#C^OxA)q_!IO#LA7=wd##Yv{B9vv9GMZ zA8k|Sygd3a1Y#hw|V03weZALE$xSY zu=j&A2Imam``?Er-)=LJNCghkvuHi+Nj>sV^x*(L&CK`_Gtg(I(?+iu=&@3Lfrp}x z1RhG;N0V=@_8Gh%?7y9gX0q8sSZ_p`K$$@~jPfkXb12WDyo|Cjo6UZN@&d|6-`sP; z_w;@!8ob}Pw!GGUcGOVpN7?MdD5=o%gzA^j_E|Duc@VDjaTmT*njBJ|H-3YQ~Ek3*QkW$N*`YwvTGGe|9Y9D->38wGtG8wtak2N1`Z4ZRw2V!QjH_(#m z>yIZ)E3i4(5UdY|>l^9=k%WOQM@%anPbC8lo6%k$*kD^X)o*Lu5!t$9bK~av?SUS0 z+!Sr<*=%g-j%;o;wtkBGr!}mk3NA`p^Mk%EMgt6&gvbJyl`Q1LZ7dh^xv@YVzPHXQ z#)b0m{dQK}cMJKjZy_J<Cz-yLkF9*Iqa_tqf`zhDH z6nL$2?aQDLdkuH#jRI?;K^1H$54ls=bq$sSpUdt>4ORf3$GP^EQ0RQnU=_Tn&dXf? z)xhUyuDu!#LD+4w>l)NRte~BrBDowx z{}-&#_`UX@DtnFkJA?flZq@LFXB~f|{Q2(^_AkN(^U=Dib>!!slP7;4uCV>{?T?_H z#>s#GaDFFG{yyJj=gGG_{#Ec<&;8=q=f=tTP0UkhzopR*unb=H+>e8{{XXdD1WNv~ zZLfk;o_@b#+biH159hCfr4{JRA^1LQJ`G1W47s|u_4_Ab8MtTza_2GHqwUbk! zJg4pP=buX#>^%AB#y{Hr%k$2kpDMfey!wruC;wb>IOLzVAEJMi`<(GR)B7gM0OX%b zi_pFt_tm)K$$yWYS9bn8fFZ52?X1noEq4AnoonHF{Fjm4pMMT?%;W#XdF(pc1KgQQ z4xzmY_a{F`cwT=okN;V;R~F#&cW7Vk%FER^Z2$c8{K`E3*U(<&ug*LFKTvk>c`~K) zd(VHsKj3M-c>fQp0ac>C64%}9{|VclM?EJuDu3_usA`@(P4ncriu-F3Z@NS$F=kyumX zrbIkBFu18VIZ$W+v0WDo&i#kJO^tOCE7K56!GlqFaPVW~h+~e3kx1xInZ{wgC;2f_ zB`KAaNoNLndV&#%nwHrcPiIU^&-Ce$L@H^fLD!=xy*H8SHWGR?ld{sfF)#=be0NBg z88aH(wrzWTVJE#Oo{Z~;Wf@0xGnuiDLXTzinR;}fukR>^xHKI-GdZqlGa1z_Gjb#t z>F-Bo!3O%-Og~$YAHL0)iJnaq7EB$$WV`k^ced)Sdv@wNYWUKlx9(QP-8=V#-qx`< z+}xq>-L>mLYnR^D9PVf($DDqnxrTJcuri?U{L-H0&h{3dwQ)=-k(?x6|aD8qL+I;dDT6@9Na&mZGb( zg%+aA=uVi}wilB`<4JuWZQ^jrmDeoSQI8rK!|4!=?v$1BjHf%D&KVBA4EE{i_|w>j zj+tgjM$;)hW+bE3Ij&;V#ydN8!iRQB=Cskw>{OPKJgizAj?}U%o-`8F#~e%Q_NkPW zz{!|2Waziz$xKhqXww-hVderQ!T`ba(Y}n)jWT07GR8GbVp{zWOr|nsusPhmDP#0P z5O2?5%t*%|7(JTAU`J*wr$xQ?<|sP0S!TkZ09ETxWFTnIJeV;Du}=FO+fw%UgJw+a z>{t|IS#u(sE$&2c9TOXU@d);s!d&C-@iCsnc*{7p>JIr&+o_d+@vzB zCQRSUsLJs*)QF`8FML$Y#`E{JK{Y`Bo<_b@y!<|oHu{#u{qy_wTWZ1q3c|wkXFryQ zu#LWrvCi-1Q=WM5`0b?l(~B1kmE-ySy+(Z?98`|nzjyvms`#+-I5$;%|6HhD z<2aT-^ThM_o*`js?fl;GGvyIrN4qtD|5G#XedXc^zY}<=)KTgGceLTf +#include + +int main(int argc, char* argv[]) +{ + int numprocs, myid, source; + MPI_Status status; + MPI_Request request; + char message[100]; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numprocs); + for (int i = 0; i < 100; i++) { + if (myid != 0) { + strcpy(message, "Hello World!"); + //MPI_Send(message, strlen(message) + 1, MPI_CHAR, 0, 99, MPI_COMM_WORLD); + MPI_Isend(message, strlen(message) + 1, MPI_CHAR, 0, 99, MPI_COMM_WORLD, &request); + } else { + for (source = 1; source < numprocs; source++) { + //MPI_Recv(message, 100, MPI_CHAR, source, 99, MPI_COMM_WORLD, &status); + MPI_Irecv(message, 100, MPI_CHAR, source, 99, MPI_COMM_WORLD, &request); + if (i % 10 == 0) { + printf("No:%d, receive message from %d: %s\n", i, source, message); + } + } + } + } + MPI_Finalize(); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/serial_time b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/serial_time new file mode 100644 index 0000000000000000000000000000000000000000..fcf7c94237a2c7d1bf605b43e783c86dfa0623c1 GIT binary patch literal 71904 zcmeI1eQ;FQb->T=Tf`y+h;P{r=m}#Rh*>0zLD)|Hc7>220#tdaY3iA$r`;#**83rL zpIl+=u`uq~t(_@ru<=JA#F?oPji+>i$M#Ip+NnF0aoZtwgUQr!FcT+=lXM8iSZWd5 zbKkp1dix>jHp#SqoGb1-_ndpqz4!g@$9wyDsJU&U*W&?7UU&tBc4Vq%o17~^=j;g| z4H{t@Xs{R-K?QpGFq5AqOC(2R7)d|+ilkr`agAP~38@J&F0ZpS0FuD$2)a+A2!TE|9#(F#}18`+bZPX-=clt+p=}L9Vq5|s$Fs}LKn9<1M_su zRhTJJAGAhjO2oX2dlcpvnQUl z%uIMoQzD%*!$w!a1YPe*rc-*>GBTE~JFaCNvpX}EXfxupY4*o0==#PaE<1*dry7^teU7Rw zyZanj=CZrTS?{vbnI}4FblJrorKGv+v}Z+KtIO^_1KM47aYj%Y+x>TgV+!Q90vs6I z{l?MP75y~T33(pt&!d=qrDe4G+?_eqTYI`zRenIZ+5`J$d$rMOFW7aqUV-`&mtKi_ z$feIjz00M~LH%Kuz5w+XT>7=Bf6t{aM*W;iUxK>VGtvKzs4sEpD^L$P`XU&3XEElF z6gc*wqK%%r9&$g$`v*At4#4Xdz<=Zdd}YrC1$6~=1$E`?doK7;_o41X-S^jfF1(Y^ zAN(Qav&aU1*)pmDocMk|zfkZKY;aNS!xfstSAl(XDDMRL#Swg5eTe>b!!4t@ichFe zdwMeeI)Jz9E;sG3yBvHR^Zqx`{~X4K&bN$qVOhgi(GSIs?fzSP9zU55qjRy(PH$-a z0Klyu;22dH=;-u%*MBly8y(yIJ$sISf@96^^?iSAclF@q$6<6#@#Xw?;F0wcNY{?d z+Id#-y>wQYg1G|o)R$U45cc1pJvnWx>D}cwJox0tiZ}P=czon$Z2Pggq32>A|FPEi z@{x0B_f!vboK&9YGI~V^H=RgKJ>McUTo zyq>i=fkOB-`byaOE#V%&Q@$lEhGIu}MqbY<|;-M+z#+olYTHQ}Cl@JL4$ z`V7p16Z3J+z5IeF_e!@m_$u!A1+cGU8s<-MpPin1B;&{Vcnjsnp@k>EsMMUix#^md zo9Ayn`NaITllOWmPwtvhdGgOaH77SusXF<^>8GFjOsP4x!*k8aKmKUJ^FdGKa3$I{ zf4Jaz4a>`Mt~`70O!{%Y_KfAjVjQn@1NIA}!&mYL@dfCF==&n}{k!b(pjy&OML9zok3(zX<(hIuLWTQ6+End%|m zVI??YQE1r`kfG7?Ny7^ulWvF9P-=t zHE245b+3xLwyH(dhrNeHdm^SC^Bs8K#dTtg3Cw4(ZkZPg_f#!v-|s!(d#d7T|G~;< zs-CSrJm=6n5N%f>lQYO_0LyqU+9Chpsp4J^OnJ)J`m}P;`;2Gf{))}-ZusCwXHLKO zuRjoXC+=ed#;Icy_a?$QF##sP1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XB@c)OvQNLynre8{r99ps5F6~uP z9W|uy_l241mkXI7|rr1}2 zMxSPvDx^N_b@WQ94@o&)${H!>OG!eJh2gw2Ua!>s62LsEPnB|^lt-s%c8TnrQm6ZD zm44Htr2enuo%>Oxe_ra;?|G?%te4@xGjT@F!~e8{Q*!=)+p>5Z^Z)seY{VaJf6kt| zmv5g_D|}j-nr>5!shY6Bc`3{JP#wvu`S|2MEayXe?mLowIUm}GkI4Oa zH6QXV=R&}=+(8QX#?OO7`xF>1+fK#! zc~R((ORLO2Q*fqfe-`>rgU+)4l|bh~q5pKCIV-eR0qvVY`;77RRA`?GG*^Z8Sx}C> zf~)lSOwH|Tmlc=|)w9ak=K!78?jQx`0-e)^_IXh5+)!XX49Rn}(0>8Y`C4dS2si4d=Y8K*`<)K7Z>e8uhxRJj|K+Of%mBYUhsghjSP{o>e5*Qbf?lv{6Ev;)k7eMM(vzinR#u_8VX+V*Rpmj*87!?t}kJXSQG zM{WBI_*N1BC(!PJiT1@AFVaD2@0IwKh2v)iQ$ajU5=v`@C) z$Uj=-|C&9X*-&g3{gfNeKcYXtoRahEjNMM@dG(?6FFyA!+V;}(bE;SHEIr>G4yEV$ zBJ`hw>#$$WyH5-c(@NX!l-<|gL%ZrW$nwu^d+9m(6|`5o_6vo^CTah9>0f+KK5W|; zmYlbLHc2}-3A?xSTzYPj_WyE{c3!jXGoW*tW)J;Uc>`}v;{P+d{ZbAW(XPr^w@~oK zezv#t{HaF!9Jiw^FA@H@Pw9C|^VMMcPwcM~(!Y6w*wLJvnmnqTGbPYtTK#DB(`?V%0xWX*T1qS)wjxi$zK%+ zO#DONwQE*IGFC$%4NIf2wEs6~BaUrEj6_2J6Vtd??@s*&O{GLr87ph`b$16M5H&Mq zPdsax8Qn_ikwiLWW1N8x?1Ju$ku>#aUoyE1LtL7Uo>qZt*387QM=PE*ab!!Qfd+9|EiSi+%Nm4; zKc)I{K(X%iYXkig#a$D{`@u|fuM~|3(syB(8#{tqn)T+b8+0ADf=;8LZ}`Kl!7ZDb z3Tv{Kk+IN(zu)xcR@p-9h7QnM+O~y)ZThy28}Dik>)~Lity#2+lO53`**^RB!R(J) zn%2^`Db%Fn@4I!NZwhbGCrF34GzrdOqbp%za91{~+dbj{aRMUu>OH0ol<%v2;sV|DsV8u3(tH%>fu;*17edy?tY_|UK} zo7Q7SDvF~vy3)nt*t88@qw$p9mo=l1H7(tWWlSTg8{J}2Si7LN&&n2cHx5pCKsFLH zqdJCCNP&0Jt?1j@!#GCg&RrCdLOg{PNSS6`;HPC?0KYdAPg&gsz394;#f50;-9|i7 zPy>PNuB2sjp|moNj8O@jF*CgoNTn?^5DaZvX&F5bz>^^mGqN!VM0cey*pXJosgb|* z3ltseGG@XM0kYJaupnUL30P)7mIY0$OWW%qV8-O8ibXM&G$+E@T}}j*v0)<_k6^E9 zYzr>|y91{&T#69DeV)X<>x`?bFP?}749m*IyZS6V8-6=Ue0Re~3%(0GiGFuCN&|hD zlhw8_m4&<>v-t2r@$~yVEDb8wxf4Av$#yFi#J4(%r{D4Y($FRyg^x(|9!l*rpzRWV z3#0fUuZ9-!9ncm)-wli7omzm~u^_(vQT(u1Lk;lzfGwb1z`-QGABrONUn7i|nlR&| zYCN94H#W)v4hbh$lFf}Ts(gABe?_P#kWGz>3f7K<2Bin7{BnL z@k=xGU_lI(;_16Zr;Klvj>Y`w{&&jwko2SP8%JdTeIFI-0?gDu#qUO&U_#$#={v}A zX`tV~=wc_Dchc{}f;*nRmz*;5iWSA;_-~@k z9Z%nVs%JTYJBs?J`EzOkUc!RtO6&oV=y%f4n4=f_lTPwAbQ4`sJbgzx^*Q7J0b|8f zQ#^fdIwRxH%kk6tqJC*!#P3bvLhr#r}3DiYIv< zE9F+P-RSqpMcKbfjTQxB5UJkoc4hmY#risK+c2e*lJ*x4Q_53?Hsor_Q+Jr>EVOv}QlV z?o%vT=^z}YC8f=JK33;1`30aE1?2@stxMdR4m{ge!_ z0b(8&MI+6NqM?P+NW7zSp{^%`ZI3+UNhLf>toxph?re_hH#`oTqwNnj@4dS2I;`pn zoILVO)1QCzUo3By1M83Zu#5SZm^I7J+QfL={J)Bw=rOf`7h4ue0sFt8t&snB#<3qB z$Nug(b~aCi`j4Sq!Q#B?(NM_$`El&K#<3q7$G#Bl3Kr+J7Y&8R1)S%0qb(WMLu_^z zgSIxXUJHej;nqmX2qy#U{n11`9MGGiVXLiR3-3aEIuVJ3P=eU25oROASl^F;rnSZr zaV=%&Nkh{hwIyk=)}YlI?u;1F-eIIbZ%$xKdomI?S|Al{3x~8+*w9;ABJqgP1u;Du zO#~r`ADgw-uwg`En489W;(f<-Orw6?TAyG0nrF#Uymz)uC0v0L{;{>`Hfxp@Ra}Sc z&swtz$`{iw;C6Gve`1|otTl*|t!V{|)h_3>Z{zJKc)K*(ek$u_W^m!){Kzo%^ESIU zTUf&-o4wrh6dyjbB4Ix)UvZVfn4Rr2aaGvt?7qcSWwYDQTg7I#pEnC^cCm+9UyE&a zd;ZI8_6cH8l&Z~MX0tcg>=SMF$87dVHv1Dc`(&Gar2ANAM20l(r{0n7w_ZIiYiDiE zFo^Ag0E3lx>W3;WuSzRY&Dk17{!o+(7woE()S(Iq%r;XmMt!bLFGJmD(q_5zQp(H#*mY|*44uhlUp(k{rLW7-2hh`a0`=FY)MZ@iOQ*f5A77J7dm4|- zU68&cOZT6h?Am*4RnHHed%ybVrT3Mczmcc+U6yC`xuEBClLR~8#n=NI)i-gQR36v} zZ`RClZTZEWY`}$mT#{Y)-@w>|Xz#&TGv?{0+iw?$DbHpDEGL%FKd}5J)@5YO$B+5o znq@~ImX+z+QhD#T$LdFFVdhB%g8QLLuRf0cw`QwD*Ee}HEdJ(`zRXDXJLbIKhj~_G z`2_FvBUv4~JP*>JA{X3UrvZ*%gVF=n;7-pq8Fd+T8Fl&iHXQTPX*cR_)ZM4HUE7Ic zyo}`%t{eEgenE|cl}`nYR)oW zw#IPN=J?kFoU9%8@2(y8?!>bDE%d*PvA)6jp=PYB7|Y^B{7Cn|nd|%dL>QWeeKpPX zE$;z%_#)<~;Qcqvm6l(hs1A*E|J-EoG3LqQv;GMmjC6w;dr&S-->!k7+sNgBzbL(G z_~A?~a=MKA!Joj8tD@(0&9Ey|Gb~||vAD4mVJS8lANvf3p2G2J+_0o+Is^{+OVTWc z@qdEbkE8wdSug~DdEoR?w7rIF@y*Td%$GREk!djW2ChZ)IeahPLrcYu)82n~rC)jH zC)d_2efL@k#@s}||By;{sw>o?zw%zXHt&?0kpQOOkf-(GA=0m_az9L0`)j9r`|(`v zuXVfno7~WU#0Tk@B8x|iF zova1-$wQ^m&TXZxopV=7C-pydo%BNUeg(@xX;n-g&IVY1ffd&MEPoF&65i7-#&0ql zX8E(6S^jLTnfCxCJ6YZ=XSUb2`KI?P{(H=PS>DTKS3h9BwI#0pe^ep80H*chiQX@b zY#eY6ZyaFvIV6{2&P7*OW4`mSJcs$}X3lQRSw8t3=B#7R($}Svu9dc&!OGc(IlE-F zYZK;uY->?w)$o)p4Ly)KgnRAS*5b^uttD7Wu}r{HhGim_Ntsd?1m>+=Gf+DnrsA49 z?NZ))S?vto#{Bx!&Uv@RTwl0jt%2iiwg%+UHE@pGl_CgKNj;4>W^{E6wX~QmaWo^s|WEMsVadjwJ2Z1y?q4t^_!bl zXWqcQe!GUPZ#9E!I?eXQUL5ZWT<2_!9l^7Xtuwa1fSnr$9!>ug+wndczlXA*kFp~D z3is(jX~y-eNMjCWTsO**?w@90B}{d#RDZzE)_S(2J`;=XH&N?%T;)e&g#1)&%8fX4Cy9Vb@oTnw5zpv ze!qri&W&^4%$L9RWvuym+su{CkN8fue;>PSPeDD~JzjjiQ-bXsig?IVTJ%UX9P)TP zcxQOwV_w0wy2i$hjgKnp!?8rNOYyP?Lwx2`)|kc!b^U0ap*{tEh-)q0iX4_CVP_o|$hf%UGppQ`=Mfo|(_fS4?C!1Y| z{vV_KCzPRVHj8W6d_Kfxa6Q`y?#^o0>`67ItqN^thO*fQSR-B)SXg}!Z7Z1pulZP1 zEOT&-#VEl$S=r~_FMG@H^X`@!E?yYG&hTQfEXVoiC!Xn8uB=p{O=S;&-pQxj-hJQL zzZRo?d;H&eq0Zl1zq`TvviBvQ@A);}7gtL=%gzjV&wl9r)i1s0{1+~s$KJgYeFJAc zJbUh!zw(;iFVvwc3qk+7aa&j}Scb8jAI@gkZzvppm$Yy0{#t+eeNUBLykPc?=7+G% zM@~=N%4R2_M8BqellD*av3o4*o#1=E^o0`Ni^b1gym0Qrvjbh?()}fjO>fcj?uHlS7o|O}HM@(yF|hjLh4W|6o%xW(GFG^bp%dc-D;7={5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01+SpM1Tko0U|&IhyW2F0z`la5CI}U1c(3;AOb{y2oM1xKm>>Y5g-CY zfCvx)B0vO)01^0qO`uFQZ|~FuOS<^YI%Uvd-^TSxTn-kiX04p-+b3K4JzPIA;x%it zxn9cUyRnSdhm6F_mRX04d(MA@jnI@rx%-)So>5vN?rER!ps7KJ|Y8qsoH%4UhkcvefgSXEC#} zIjCS2oWpwWeAk2e5*RL3nFZGIbzaCvvPKa{Xt5I0tj>v!Drlc9U6` zp$c{sw2M?hxD`B%br2RF-}zaRe&`?(uW7-wEiRH*z;EivA_h;FFIR2lbT^YO0(b|8by;7P5&iz}8oC?iL z?Kt)a(OwB--xp$jeWrgoG?c66n1}hu-yEl(R_-tMQ4jZjW*q<5a9y!^cg|P8$szxH z?Ro5{kpDhzcYgn7cs}C%pM>MF>z~oixHm*A)EW#f()DDp?U9ETMkDc#&V{YJ>>v6*^3bAS(pch2!2A%*@B9jV zM6i#b9*t_xg!Ro@OZ+Qz700epiQwk2p*8FA&@+*c(dG$4r)T++#Y>@!iDmFC6Uza! zPZ=F8E!Z9kC&R6glo3v9MobGv6Y+2gG%b|STBC_(J*tI_L^7r69i0$N#M+}_BOLN9 zUAk;>VJEF65|3zlGO2fI;kc3Pf|jHn3u~c{SgZ>}Y?_9iMviMZ+Om)tJ&8@|x~9>) zzD}##uv*hl%W)2Yw)$HeyzAHcb6Zk|o;1*ezpJ#m2Hr!%>PFD&*KPE9*J&Hqtl3l- z&;nlHx;oY?PG(RGraH{DA>0`;RJDHHTAyG0nrF#U(AEalYh#20>-~&RKyQwQF}OLE z(##Pt!S&&oPf!P>7~HJ2h7BVU3+Hwi4(WytsVzyzKxSv*cnG_S;d)2}bHl7et-)e? zB<^Tsom#0tyU~^m>mea2kEV>1oJweIm^I#w2zxr==v;43ICEXQ5&H;5 z;#x;49D)=sI6kJ{!e-y-g7yw0F+*=gX(TP#CTi#$PPT(5o-o25-1DC1jz~1LFcRV>uW#)_ zLvIDMtxZq0fhW`z$Nns7B(0Wjhm)yDBA%mY*p>`Obr!&D?NI|fCIgQV?!-DnhHVLR zVR*uAe2cV&Fji<*gtb?!2vNt5^;jf`qb9H~{P36qSe@Yl1rP4p816(XFZ0$sx?vklydoUAbjGhn` z_@2NN(8j;V*!w|LA~U%YQ9<_TBx zK#{-j6LK@Qvv+$!7w;t&@PH;B&+=z^iu}15p2Z4FRm6+;7dv=-19ueTi+FMW+j+c? z`-%4)r+9$E`7w1S7H9nT(Z*a@e(VzOLk77){0_EStz1Q&$?svY$5)i7%#80(OaYfH zG5Tq~pF>T^UaZ^W#q-M`kM9+U@g79}qQjRR@!~zq_Q{rq7)SW?Wg%2JfHgM0;4j|S z?BVg-Mm?>HbNp8w@#4MCoGF%nz!C2p|8+;ac>mMR<6mXT*)He!$FYs2%GMUU#P6aL zBbM&;7rKz|p&J`Y#EbVyr+&})^B61EHXBjAcRJ7G2YLQt8pXI`UOvJY<|4)y@25^= zS#JP}`8oC>;)VPao9yx8J=PT--#Hd))9C7*g3uqi?|b&5ciJN(W`?00Qt<(=tu{DixrN)HO2D0#}VLA;eP + +#define MAX_ARRAY_SIZE 4096000 +#define LOOP_SIZE 16 +#define NUM_THREADS 8 +#define START_CORE_ID 64 +//gcc socket_bandwidth.c -O3 -o socket_bandwidth -lpthread -lm && ./socket_bandwidth +void MemBandwidth(int *arg) +{ + set_thread_affinity(0); + Point *pointA = InitPointsVector(MAX_ARRAY_SIZE); + Point *pointB = InitPointsVector(MAX_ARRAY_SIZE); + int cpuId = *arg; + set_thread_affinity(cpuId); + int i, j; + double ret = 0.0; + for (i = 0; i < LOOP_SIZE; i++) { + for (j = 0; j < MAX_ARRAY_SIZE; j++) { + ret += ComputPointDistance(&pointA[j], &pointB[j]); + } + } +} + +int main() +{ + int i; + pthread_t *threads = (pthread_t*)malloc(sizeof(pthread_t) * NUM_THREADS); + uint64_t ts_start = GetTime_ns(); + for (i = START_CORE_ID; i < START_CORE_ID + NUM_THREADS; i++) { + pthread_create(threads + i - START_CORE_ID, NULL, (void*)MemBandwidth, &i); + } + for (i = START_CORE_ID; i < START_CORE_ID + NUM_THREADS; i++) { + pthread_join(threads[i - START_CORE_ID], NULL); + } + uint64_t ts_end = GetTime_ns(); + printf("Total Cost Time = %f ms\n", (ts_end - ts_start) / 1000000.0); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/utils.h b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/utils.h new file mode 100644 index 0000000..723522d --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Know-how/utils.h @@ -0,0 +1,105 @@ +#ifndef HPC_UTILS_H +#define HPC_UTILS_H + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SEC2NS 1000000000 + +typedef struct Point_t { + double x; + double y; +}Point; + +static inline uint64_t GetTime_ns() +{ + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return ts.tv_sec * SEC2NS + ts.tv_nsec; +} + +static inline uint64_t xorshf96() +{ + static uint64_t x=123456789; + static uint64_t y=362436069; + static uint64_t z=521288629; + uint64_t t; + + x ^= x << 16; + x ^= x >> 5; + x ^= x << 1; + + t = x; + x = y; + y = z; + + z = t ^ x ^ y; + return z; +} + +static inline uint64_t my_random() +{ + return xorshf96(); +} + +static inline double random_double(uint32_t range) +{ + return (my_random() % range) * (double)(1.0); +} + +static inline Point *InitPointsVector(int len) +{ + Point *pointsVector = (Point*)malloc(len * sizeof(Point)); + if (pointsVector == NULL) { + printf("ERROR: Memory Allocate Failed!\n"); + exit(1); + } + int i; + #pragma omp parallel for + for (i = 0; i < len; i++) { + pointsVector[i].x = random_double(len); + pointsVector[i].y = random_double(len); + } + return pointsVector; +} + +static inline double ComputPointDistance(Point *pointA, Point *pointB) +{ + double horizontal, vertical, pointDis; + horizontal = pointA->x - pointB->x; + vertical = pointA->y - pointB->y; + pointDis = sqrt((horizontal * horizontal) + (vertical + vertical)); + return pointDis; +} + +void set_thread_affinity(uint16_t core_id) +{ + cpu_set_t cpu_mask; + cpu_set_t get; + + CPU_ZERO(&cpu_mask); + CPU_SET(core_id, &cpu_mask); + + if (sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask) == -1) + { + printf("set cpu affinity failed...\n"); + exit(1); + } + + if (sched_setaffinity(0, sizeof(get), &get) == -1) + { + printf("get affinity failed...\n"); + exit(1); + } +} + +#endif \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Python\346\213\274\346\216\245\345\255\227\347\254\246\344\270\262\347\232\204\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/concatenate_string.py" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Python\346\213\274\346\216\245\345\255\227\347\254\246\344\270\262\347\232\204\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/concatenate_string.py" new file mode 100644 index 0000000..f0cb385 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/Python\346\213\274\346\216\245\345\255\227\347\254\246\344\270\262\347\232\204\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/concatenate_string.py" @@ -0,0 +1,34 @@ +import sys + +BASE_STRING = "Hello world" +LOOP_TIMES = 100000000 +STRING_LIST = [BASE_STRING] * LOOP_TIMES + +def string_plus(): + new_string = '' + for string in STRING_LIST: + new_string += string + print(len(new_string)) + + +def string_join(): + new_string = ''.join(STRING_LIST) + print(len(new_string)) + + +def main(): + function_map = { + 'string_plus': string_plus, + 'string_join': string_join, + } + print(sys.argv) + _, function = sys.argv + if function in function_map: + function_map[function]() + else: + print('function {} not exist'.format(function)) + + +if __name__ == "__main__": + main() + \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_hit/cache_hit.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_hit/cache_hit.c new file mode 100644 index 0000000..9acf96b --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_hit/cache_hit.c @@ -0,0 +1,58 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* +数组访问, Cache Hit +gcc -g cache_hit.c -o cache_hit +*/ + +#include +#include +#include + +#define ROW (10 * 1024) +#define COL (10 * 1024) +#define N (ROW * COL) + + +int main(void) +{ + int i, j; + int *p = (int*)malloc(sizeof(int) * N); + if (p == NULL) { + perror("Memory allocation through malloc failed"); + exit(EXIT_FAILURE); + } + double msecs; + struct timeval before, after; + + gettimeofday(&before, NULL); + + for (j = 0; j < ROW; j++) { + for (i = 0; i < COL; i++) { + p[i + j * COL] = 'A'; + } + } + + gettimeofday(&after, NULL); + + // 1000 ia used to convert tv_sec and tv_usec to msec. + msecs = (after.tv_sec - before.tv_sec) * 1000.0 + (after.tv_usec - before.tv_usec) / 1000.0; + printf("Execution time = %2.3lf ms\n", msecs); + + free(p); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/cache_miss.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/cache_miss.c new file mode 100644 index 0000000..0f00d0f --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/cache_miss.c @@ -0,0 +1,37 @@ +/* +数组访问, Cache Miss +gcc -g cache_miss.c -o cache_miss +*/ + +#include +#include +#include + +#define ROW (20 * 1024) +#define COL (20 * 1024) +#define N (ROW * COL) + + +int main(void) +{ + int i, j; + int *p = (int*)malloc(sizeof(int) * N); + double msecs =0; + struct timeval before, after; + + gettimeofday(&before, NULL); + + for (i = 0; i < COL; i++) { + for (j = 0; j < ROW; j++) { + p[i + j * COL]++; + } + } + + gettimeofday(&after, NULL); + + // 1000 ia used to convert tv_sec and tv_usec to msec. + msecs = (after.tv_sec - before.tv_sec) * 1000.0 + (after.tv_usec - before.tv_usec) / 1000.0; + printf("Execution time = %2.3lf ms\n", msecs); + + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/miss_start.sh b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/miss_start.sh new file mode 100644 index 0000000..1f8f43b --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/cache/cache_miss/miss_start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +for i in {1..200}; +do + taskset -c 1 ./cache_miss; +done diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing.c new file mode 100644 index 0000000..80050dd --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing.c @@ -0,0 +1,169 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gcc falsesharing.c -lpthread -D _GNU_SOURCE -o falsesharing -g +#include +#include +#include +#include +#include +#include +#include +#include + +#define TIME_S 2000000000 +#define NUM_THREADS 4 + +struct Foo { + int x; + int y; +}; + +static struct Foo f; +static struct Foo testf; + +void *inc_b1(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("inc_b1 is running in %d\n", get); + } + for (i = 0; i < TIME_S; ++i) { + ++testf.y; + } +} + +void *sum_a1(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("sum_a1 is running in %d\n", get); + } + int s = 0; + for (i = 0; i < TIME_S; ++i) { + s += testf.x; + } +} + +void *sum_a(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("sum_a is running in %d\n", get); + } + int s = 0; + for (i = 0; i < TIME_S; ++i) { + s += f.x; + } +} + +void *inc_b(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("inc_b is running in %d\n", get); + } + for (i = 0; i < TIME_S; ++i) { + ++f.y; + } +} + +int main() +{ + int ret = 0; + int i; + int tid[NUM_THREADS]; + pthread_t tids[NUM_THREADS]; + printf("start the threads\n"); + + for (i = 0; i < NUM_THREADS; i++) { + tid[i] = i; + } + + ret = pthread_create(&tids[0], NULL, sum_a, (void*)&tid[0]); + if (ret != 0) { + printf("pthread_create sum_a error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + ret = pthread_create(&tids[1], NULL, inc_b, (void*)&tid[1]); + if (ret != 0) { + printf("pthread_create inc_b error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + ret = pthread_create(&tids[2], NULL, sum_a1, (void*)&tid[2]); + if (ret != 0) { + printf("pthread_create sum_a1 error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + ret = pthread_create(&tids[3], NULL, inc_b1, (void*)&tid[3]); + if (ret != 0) { + printf("pthread_create inc_b1 error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + for (i = 0; i < NUM_THREADS; i++) { + pthread_join(tids[i], NULL); + } + + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_mod.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_mod.c new file mode 100644 index 0000000..345746a --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_mod.c @@ -0,0 +1,170 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gcc falsesharing_mod.c -lpthread -D _GNU_SOURCE -o falsesharing_mod -g +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TIME_S 2000000000 +#define NUM_THREADS 4 + +struct Foo { + alignas(128) long x; + alignas(128) long y; +}; + +static struct Foo f; +static struct Foo testf; + +void *inc_b1(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("inc_b1 is running in %d\n", get); + } + for (i = 0; i < TIME_S; ++i) { + ++testf.y; + } +} + +void *sum_a1(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("sum_a1 is running in %d\n", get); + } + int s = 0; + for (i = 0; i < TIME_S; ++i) { + s += testf.x; + } +} + +void *sum_a(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("sum_a is running in %d\n", get); + } + int s = 0; + for (i = 0; i < TIME_S; ++i) { + s += f.x; + } +} + +void *inc_b(void *arg) +{ + int i; + cpu_set_t mask; + cpu_set_t get; + int *threadNum = (int *)arg; + CPU_ZERO(&mask); + CPU_SET(*threadNum, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { + printf("warning: could not set CPU affinity, continuing...\n"); + } + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) { + printf("warning: could not get thread affinity, continuing...\n"); + } + if (CPU_ISSET(*threadNum, &get)) { + printf("inc_b is running in %d\n", get); + } + for (i = 0; i < TIME_S; ++i) { + ++f.y; + } +} + +int main() +{ + int ret = 0; + int i; + int tid[NUM_THREADS]; + pthread_t tids[NUM_THREADS]; + printf("start the threads\n"); + + for (i = 0; i < NUM_THREADS; i++) { + tid[i] = i; + } + + ret = pthread_create(&tids[0], NULL, sum_a, (void*)&tid[0]); + if (ret != 0) { + printf("pthread_create sum_a error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + ret = pthread_create(&tids[1], NULL, inc_b, (void*)&tid[1]); + if (ret != 0) { + printf("pthread_create inc_b error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + ret = pthread_create(&tids[2], NULL, sum_a1, (void*)&tid[2]); + if (ret != 0) { + printf("pthread_create sum_a1 error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + ret = pthread_create(&tids[3], NULL, inc_b1, (void*)&tid[3]); + if (ret != 0) { + printf("pthread_create inc_b1 error: error_code = %d\n", ret); + exit(EXIT_FAILURE); + } + for (i = 0; i < NUM_THREADS; i++) { + pthread_join(tids[i], NULL); + } + + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_start.sh b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_start.sh new file mode 100644 index 0000000..fc0cf19 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/falsesharing/falsesharing_start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +for i in {1..100} +do + ./falsesharing +done diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_continuum.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_continuum.c new file mode 100644 index 0000000..519c8ff --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_continuum.c @@ -0,0 +1,113 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * IO写文件, IO writes files + * gcc -g io_continuum.c -o io_continuum + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WRITE_BUF_SIZE 64 +#define WRITE_COUNTS 100*1024*1024 +#define INT int +#define CHAR char +#define VOID void +#define WRITE_LEVEL 0777 +#define IO_CONTINUUM_TEXT "./io_continuum_test.txt" + +enum IO_Operation { + Sync_Write = 0, + Nosync_Write, +}; + +INT remove_test_file() +{ + if (remove(IO_CONTINUUM_TEXT) != 0) { + printf("Failed to remove file: %s, please delete the file.\n", IO_CONTINUUM_TEXT); + } + else { + printf("Success to remove file: %s\n", IO_CONTINUUM_TEXT); + } + return 0; +} + +INT IO_Write_With_Sync() +{ + INT count = 0; + INT fd; + CHAR buf = "test io continuum!\n"; + if ((fd = open(IO_CONTINUUM_TEXT, O_WRONLY | O_TRUNC | O_CREAT, WRITE_LEVEL)) == -1) { + return -1; + } + else { + while (count <= WRITE_COUNTS) { + write(fd, buf, WRITE_COUNTS); + fsync(fd); + count++; + } + } + return 0; +} + +INT IO_Write_Without_Sync() +{ + INT count = 0; + INT fd; + CHAR buf = "test io continuum!\n"; + if ((fd = open(IO_CONTINUUM_TEXT, O_WRONLY | O_TRUNC | O_CREAT, WRITE_LEVEL)) == -1) { + return -1; + } + else { + while (count <= WRITE_COUNTS) { + write(fd, buf, WRITE_COUNTS); + count++; + } + } + return 0; +} + +VOID sighandler(INT signum) +{ + remove_test_file(); + exit(1); +} + +INT main(INT argc, CHAR **argv) +{ + INT val; + val = atoi(argv[1]); + signal(SIGINT, sighandler); + switch (val) { + case Sync_Write: + IO_Write_With_Sync(); + remove_test_file(); + break; + case Nosync_Write: + IO_Write_Without_Sync(); + remove_test_file(); + break; + default: + break; + } + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_wait.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_wait.c new file mode 100644 index 0000000..4d4a74c --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/io/io_wait.c @@ -0,0 +1,167 @@ +#define _GNU_SOURCE +#define BUF_SIZE 64*1024*1024 +#define BUF_COUNT 20 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char *select_disk() +{ + DIR *dirptr = opendir("/dev/"); + if (dirptr == NULL) + { + perror("Failed to open dir"); + return NULL; + } + struct dirent *entry; + char *result = (char *)calloc(512, sizeof(char)); + const char *sd_prefix = "sd"; + const char *xvd_prefix = "xvd"; + while (entry = readdir(dirptr)) + { + if (strncmp(sd_prefix, entry->d_name, 2) == 0 || strncmp(xvd_prefix, entry->d_name, 3) == 0) + { + snprintf(result, 512 * sizeof(char), "/dev/%s", entry->d_name); + return result; + } + } + free(result); + return NULL; +} + +long int get_value(char *str) +{ + char *endptr = NULL; + long int value = strtol(str, &endptr, 10); + if ((errno == ERANGE && (value == LONG_MAX || value == LONG_MIN ))|| (errno != 0 && value == 0)) + { + perror("strtol"); + return -1; + } + + if (endptr == str) + { + perror("not number"); + return -1; + } + if (value <= 0) + { + perror("not positive number"); + return -1; + } + return value; +} + +void sub_process(const char *disk, size_t buffer_size, size_t count) +{ + int fd = open(disk, O_RDONLY | O_DIRECT | O_LARGEFILE, 0755); + if (fd < 0) + { + perror("failed to open disk"); + _exit(1); + } + + unsigned char *buf; + posix_memalign((void **)&buf, 512, buffer_size); + size_t read_bytes = 0; + while (read_bytes < count * buffer_size) + { + size_t ret = read(fd, buf, buffer_size); + if (ret < 0) + { + perror("failed to read contents"); + close(fd); + free(buf); + _exit(1); + } + read_bytes += ret; + } + + close(fd); + free(buf); + _exit(0); +} + +int main(int argc, char **argv) +{ + int status = 0; + int c = 0; + char *disk = NULL; + char *size = NULL; + char *count = NULL; + + while ((c = getopt(argc, argv, "d:s:c:")) != -1) + { + switch (c) + { + case 'd': + disk = optarg; + break; + case 's': + size = optarg; + break; + case 'c': + count = optarg; + break; + case '?': + printf("Illegal option: -%c\n", isprint(optopt) ? optopt: '#'); + _exit(1); + default: + _exit(1); + + } + } + if (disk == NULL) + { + disk = select_disk(); + } + if (disk == NULL) + { + _exit(1); + } + + long int buffer_size = BUF_SIZE; + long int buffer_count = BUF_COUNT; + if (size != NULL) + { + buffer_size = get_value(size); + if (buffer_size < 0) + { + exit(1); + } + } + if (count != NULL) + { + buffer_count = get_value(count); + if (buffer_count < 0) + { + exit(1); + } + } + printf("Reading data from disk %s with buffer size %ld and count %ld\n", disk, buffer_size, buffer_count); + int i = 0; + for (;;) + { + for (i = 0; i < 2; i++) + { + if (fork() == 0) + { + sub_process(disk, buffer_size, buffer_count); + } + } + sleep(5); + } + while (wait(&status) > 0); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/README.md b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/README.md new file mode 100644 index 0000000..ac4bf70 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/README.md @@ -0,0 +1,24 @@ +ָ +1java_perf_testص +2cmd̨У뵽java_perf_testĿ¼ +3ִmvn clean install -DskipTests й(谲װmaven) +4ɹ󣬿ڹ־ҵӦ· +5ɹİϴҪķѡjdk11Ŀ java -Xlog:gc*=info,gc+heap=debug:file=/home/gc-%t.log -jar demo_test-0.0.1-SNAPSHOT.jar Ŀ +6ڶ˿ռ޸application.ymlļ˿ +Ŀɹ + +Ӵ־ +ڴ +http://ip:9118/gctest/testOOM +gc +http://ip:9118/gctest/young +ϵͳgc +http://ip:9118/gctest/systemgc +gc +http://ip:9118/gctest/bigdata +Ԫռgc +http://ip:9118/gctest/metaspace + +ȵ㺯ã +http://ip:9118/test/testHotMethod/20 +http://ip:9118/test/testHotMethodTwo/20 \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/pom.xml b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/pom.xml new file mode 100644 index 0000000..7e711dc --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 1.5.14.RELEASE + + + com.example + java_perf_test + 0.0.1-SNAPSHOT + java_perf_test + Demo project for Spring Boot + + + 8 + + + + + + org.springframework.boot + spring-boot-starter + + + + org.ow2.asm + asm + 9.0 + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-web + + + + ch.qos.logback + logback-classic + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + jar + \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/DemoApplication.java b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/DemoApplication.java new file mode 100644 index 0000000..d8dec06 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/DemoApplication.java @@ -0,0 +1,13 @@ +package com.example.demo_test; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +//@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} + diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/GcTestController.java b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/GcTestController.java new file mode 100644 index 0000000..4633225 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/GcTestController.java @@ -0,0 +1,78 @@ +package com.example.demo_test.demo; + +import org.springframework.web.binf.annotation.GetMapping; +import org.springframework.web.binf.annotation.RequestMapping; +import org.springframework.web.binf.annotation.RestController; + +import java.lang.ref.SoftReference; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +@RestController +@RequestMapping("/gctest") +@Slf4j +public class GcTestController { + + private HashMap> bigData = new HashMap<>(); + + @RequestMapping("/young") + public void youngGcTask(){ + int i = 0; + while (i++ < 33000) { + int[] ints = new int[10000]; + } + } + + @RequestMapping("/memoryUsedRatioSuggestion") + public void youngMemoryRatioSuggestion(){ + int i = 0; + while (i++ < 33000) { + int[] ints = new int[10000]; + } + } + + @RequestMapping("/testOOM") + public void testOOM(){ + new Thread(() -> oom()).start(); + } + + private void oom(){ + List list new ArrayList<>(); + while(true){ + list.add(new byte[1024 * 1024]); + try{ + Thread.sleep(50L); + } catch (InterruptedException e){ + e.printStackTrace(); + } + } + } + + @RequestMapping("/systemgc") + public void fullGcBySystemGC(){ + int i = 0; + while(i++ < 1000000){ + int[] ints = new int[10]; + } + System.gc(); + } + @RequestMapping("/bigdate") + public void fullGcBigData(){ + int i = 0; + while(i++ < 150){ + int[] ints = new int[1024 * 1024 * 3 / 2]; + bigData.put(i + "", new SoftReference<>(ints)); + } + } + @RequestMapping("/stopListenerClassLoad") + public void stopListenerClassLoad(){ + + } + @RequestMapping("/metaspace") + public void fullGcPermanentGenetation(){ + MetaspaceTest test = new MetaspaceTest(); + test.test(); + } +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/HotMethodDemo.java b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/HotMethodDemo.java new file mode 100644 index 0000000..5a1ffa4 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/HotMethodDemo.java @@ -0,0 +1,40 @@ +package com.example.demo_test.demo; + +public class HotMethodDemo{ + public HotMethodDemo() { + + } + + public static void test(int threadNum) throws InterruptedException { + while(threadNum > 0){ + HotMethodDemo demoOne = new HotMethodDemo(); + demoOne.calculate(199999); + Thread.sleep(1000L); + --threadNum; + } + } + + void calculate(int number) { + long start = System.currentTimeMillis(); + + for(int i = 2; i <= number; ++i) { + if (this.doCalculate(i)) { + + } + } + + long cost = System.currentTimeMillis() - start; + System.out.println("cost time: " + cost); + } + + boolean doCalculate(int i){ + boolean k = true; + for(int n = 2; n < i; ++n){ + if(i % n == 0){ + k = false; + break; + } + } + return k; + } +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MetaspaceTest.java b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MetaspaceTest.java new file mode 100644 index 0000000..7f8f49e --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MetaspaceTest.java @@ -0,0 +1,43 @@ +package com.example.demo_test.demo; + +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.MethodVisitor +import org.objectweb.asm.Opcodes; + +import java.util.ArrayList; +import java.util.List; + +public class MetaspaceTest extends ClaseeLoader{ + public void test(){ + // + List> classes = new ArrayList<~>(); + // ѭ1000w1000wͬ + for(int i = 0; i < 100000;++i){ + + ClassWriter cw = new ClassWriter(0); + + // һΪClass{i},ķΪpublic,Ϊjava/lang/Objectʵκνӿ + cw.visit(OpCodes.V1_1, OpCodes.ACC_PUBLIC, "Class" + i, null, "java/lang/Object", null); + // 幹캯 + + MethodVisitor mw = cw.visitMethod(OpCodes.ACC_PUBLIC, "", "{}V", null ,null); + + // һָΪthis + mw.visitVarInsn(OpCodes.ALOAD, 0); + + // ڶָΪøObjectĹ캯 + mw.visitMethodInsn(OpCodes.INVOKESPECIAL, "java/lang/Object", "", "()V", false); + + // ָΪRETURN + mw.visitInsn(OpCodes.RETURN); + mw.visitMaxs(1, 1); + mw.visitEnd(); + + MetaspaceTest test = new MetaspaceTest(); + byte[] code = cw.toByteArray(); + // + Class exampleClass = test.defineClass("Claass" + i, code, 0, code.length); + classes.add(exampleClass) + } + } +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MethodDemoOne.java b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MethodDemoOne.java new file mode 100644 index 0000000..61d035b --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/MethodDemoOne.java @@ -0,0 +1,41 @@ +package com.example.demo_test.demo; + +public class MethodDemoOne{ + + public MethodDemoOne() { + + } + + public static void test(int threadNum) throws InterruptedException { + while(threadNum > 0){ + MethodDemoOne demoOne = new MethodDemoOne(); + demoOne.calculate(199999); + Thread.sleep(1000L); + --threadNum; + } + } + + void factor(int number) { + long start = System.currentTimeMillis(); + + for(int i = 2; i <= number; ++i) { + if (this.faccc(i)) { + + } + } + + long cost = System.currentTimeMillis() - start; + System.out.println("cost time: " + cost); + } + + boolean faccc(int i){ + boolean k = true; + for(int n = 2; n < i; ++n){ + if(i % n == 0){ + k = false; + break; + } + } + return k; + } +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/TestController.java b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/TestController.java new file mode 100644 index 0000000..f27a3ab --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/java/com/example/demo_test/demo/TestController.java @@ -0,0 +1,45 @@ +package com.example.demo_test.demo; + +import org.springframework.web.binf.annotation.GetMapping; +import org.springframework.web.binf.annotation.PathVariable; +import org.springframework.web.binf.annotation.RequestMapping; +import org.springframework.web.binf.annotation.RestController; + + +@RestController +@RequestMapping("/test") +public class TestController { + public TestController(){ + + } + + @GetMapping("/testCal") + public void testCal(){ + for(int i = 0; i < 10; ++i){ + (new Thread(() -> { + for(int j = 0; j < 10 ; j++){ + MethodDemoOne demoOne = new MethodDemoOne(); + demoOne.factor(10000); + } + })).start(); + } + } + + @GetMapping("/testHotMethod/{count}") + public void testHotMethod(@PathVariable("count") int count){ + try{ + MethodDemoOne.test(count); + } catch (InterruptedException e){ + e.printStackTrace(); + } + } + + GetMapping("/testHotMethodTwo/{count}") + public void testHotMethodTwo(@PathVariable("count") int count){ + try{ + MethodDemoOne.test(count); + } catch (InterruptedException e){ + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/resources/application.yml b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/resources/application.yml new file mode 100644 index 0000000..c804375 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/java_perf_test/src/main/resources/application.yml @@ -0,0 +1,11 @@ +server: + port: 9118 +management: + endpoints: + web: + exposure: + include: health,beans,metrics,configprops,httptrace + base-path: /checkgcinfo + endpoints: + health: + show-details: always \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_atomic.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_atomic.c new file mode 100644 index 0000000..50fd001 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_atomic.c @@ -0,0 +1,54 @@ +# include +# include +# include +# include +# include +# include +# include + +static atomic_int num = 0; +static int count = 800000000; + +void Perror(const char *s) +{ + perror(s); + exit(EXIT_FAILURE); +} + +long long getSystemTime() +{ + struct timeb t; + ftime(&t); + return 1000 * t.time + t.millitm; +} + +void* fun2(void *arg){ + pthread_t thread_id = pthread_self(); + printf("the thread2 id is %1d\n",(long)thread_id); + int i = 1; + for (i;i <= count; i++){ + num += 1; + } +} + +int main() +{ + int err; + pthread_t thread1; + pthread_t thread2; + thread1 = pthread_self(); + printf("the thread1 id is %1d\n",(long)thread1); + long long start = getSystemTime(); + err = pthread_create(&thread2, NULL, fun2, NULL); + if(err != 0){ + Perror("cant create thread2\n"); + } + int i = 1; + for (i;i <= count; i++){ + num += 1; + } + pthread_join(thread2, NULL); + long long end = getSystemTime(); + printf("the num is %d,pay %11d ms\n", num, (end-start)); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex.c new file mode 100644 index 0000000..9e201b0 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex.c @@ -0,0 +1,61 @@ +// gcc -g pthread_mutex.c -o pthread_mutex -lpthread +# include +# include +# include +# include +# include +# include + +static int num=0; +static int count = 200000000; +static int millisecond_coefficient = 1000; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +void Perror(const char *s) +{ + perror(s); + exit(EXIT_FAILURE); +} + +long long getSystemTime() +{ + struct timeb t; + ftime(&t); + return millisecond_coefficient * t.time + t.millitm; +} + +void* fun2(void *arg) +{ + pthread_t thread_id = pthread_self(); + printf("the thread2 id is %1d\n",(long)thread_id); + int i = 1; + for (i; i <= count; i++){ + pthread_mutex_lock(&mutex); + num += 1; + pthread_mutex_unlock(&mutex); + } +} + +int main() +{ + int err; + pthread_t thread1; + pthread_t thread2; + thread1 = pthread_self(); + printf("the thread1 id is %1d\n",(long)thread1); + long long start = getSystemTime(); + err = pthread_create(&thread2, NULL, fun2, NULL); + if(err != 0){ + Perror("cant create thread2\n"); + } + int i = 1; + for (i;i <= count;i++){ + pthread_mutex_lock(&mutex); + num += 1; + pthread_mutex_unlock(&mutex); + } + pthread_join(thread2, NULL); + long long end = getSystemTime(); + printf("The num is %d,pay %11d ms\n", num, (end-start)); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long.c new file mode 100644 index 0000000..7f65c8f --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include + +#define N 100000 + +static long g_num = 1; +static long g_count = 100000000; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +long long GetSystemTime() +{ + struct timeb t; + ftime(&t); + return 1000 * t.time + t.millitm; +} + +void* Func(void *arg) +{ + int i = 1; + for (; i <= g_count; ++i) { + pthread_mutex_lock(&mutex); + g_num += 1; + + float s = 0; + int j; + for (j = 0; j < N; j++) { + s += sqrt(j); + } + + printf("tid = %u, num = %d\n", pthread_self(), g_num); + pthread_mutex_unlock(&mutex); + } +} + +int main() +{ + int err; + pthread_t thread1; + pthread_t thread2; + + long long start = GetSystemTime(); + + // create thread + err = pthread_create(&thread1, NULL, Func, NULL); + if (err != 0) { + perror("can't create thread1\n"); + exit(EXIT_FAILURE); + } + + err = pthread_create(&thread2, NULL, Func, NULL); + if (err != 0) { + perror("can't create thread2\n"); + exit(EXIT_FAILURE); + } + + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + + long long end = GetSystemTime(); + + printf("The num is %d, pay %lld ms\n", g_num, (end - start)); + + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long_mod.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long_mod.c new file mode 100644 index 0000000..43c4f68 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/pthread_mutex_long_mod.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include +#include + +#define N 100000 + +static long g_num = 1; +static long g_count = 100000000; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +long long GetSystemTime() +{ + struct timeb t; + ftime(&t); + return 1000 * t.time + t.millitm; +} + +void* Func(void *arg) +{ + int i = 1; + for (; i <= g_count; ++i) { + pthread_mutex_lock(&mutex); + g_num += 1; + printf("tid = %u, num = %d\n", pthread_self(), g_num); + pthread_mutex_unlock(&mutex); + + float s = 0; + int j; + for (j = 0; j < N; j++) { + s += sqrt(j); + } + } +} + +int main() +{ + int err; + pthread_t thread1; + pthread_t thread2; + + long long start = GetSystemTime(); + + //create thread + err = pthread_create(&thread1, NULL, Func, NULL); + if (err != 0) { + perror("can't create thread1\n"); + exit(EXIT_FAILURE); + } + + err = pthread_create(&thread2, NULL, Func, NULL); + if (err != 0) { + perror("can't create thread2\n"); + exit(EXIT_FAILURE); + } + + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + + long long end = GetSystemTime(); + + printf("The num is %d, pay %lld ms\n", g_num, (end - start)); + + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/readme.txt b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/readme.txt new file mode 100644 index 0000000..a62b5bf --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/lock/readme.txt @@ -0,0 +1,10 @@ +针对提供的两demo做以下说明: +1. demo要求gcc版本在7.3以上,底版本的gcc编译pthread_atomic.c会报错 +2.若需要关联源码,建议编译时加上-g参数 +如:gcc -g pthreadd_mutex.c -o pthread_mutex -lpthread +同理,pthread_atomic +3.在使用系统热点函数监测锁热点时,在任务开启的同时,后台运行对应的demo,否则无法采集到锁的热点 +4.提供的demo编译运行时间在20s左右,建议调优时间设置大于30s;用户可通过源码修改循环次数,修改运行时间(不同系统不同gcc版本略有差异) +5.提供的pthread_mutex_long.c为死锁demo,提供学习参考;编译pthead_mutex_long.c时,gcc参数加上- lm +6.pthread_atomic.c是pthread_mutex.c优化后的demo,采用原子锁的方式实现实现累加 +7.建议web页面设置的运行时长大于应用本身运行时长,否则可能出现web页面无数据情况 \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak.c new file mode 100644 index 0000000..051f8bd --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +long long *mem_leak(long long *n0, long long *n1) +{ + + long long *v = (long long *) calloc(1024,sizeof(long long)); + *v = *n0 + *n1; + return v; +} + +void *child(void *arg) +{ + long long n0 = 0; + long long n1 = 1; + long long *v = NULL; + int n = 2; + for (n = 2; n > 0; n++) { + v = mem_leak(&n0, &n1); + n0 = n1; + n1 = *v; + printf("%dth => %11d\n", n, *v); + sleep(1); + } +} + + +int main(void) +{ + pthread_t tid; + pthread_create(&tid, NULL, child, NULL); + pthread_join(tid, NULL); + printf("main thread exit\n"); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak_fix.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak_fix.c new file mode 100644 index 0000000..8a5ff74 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/mem-leak/mem_leak_fix.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +long long *mem_leak(long long *n0, long long *n1) +{ + + long long *v = (long long *) calloc(1024,sizeof(long long)); + *v = *n0 + *n1; + return v; +} + +void *child(void *arg) +{ + long long n0 = 0; + long long n1 = 1; + long long *v = NULL; + int n = 2; + for (n = 2; n > 0; n++) { + v = mem_leak(&n0, &n1); + n0 = n1; + n1 = *v; + free(v); + printf("%dth => %11d\n", n, *v); + sleep(1); + } +} + + +int main(void) +{ + pthread_t tid; + pthread_create(&tid, NULL, child, NULL); + pthread_join(tid, NULL); + printf("main thread exit\n"); + return 0; +} + diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_hit.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_hit.c new file mode 100644 index 0000000..128d2d8 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_hit.c @@ -0,0 +1,35 @@ +/* +数组访问,cache hit +gcc -g cache_hit.c -o cache_hit +*/ +#include +#include +#include + +#define ROW (20*1024) +#define COL (20*1024) +#define N (ROW*COL) +#define M (100*COL) + +int main(void) +{ + int i, j; + int *p = (int*) malloc(sizeof(int) * N); + if (p == NULL){ + perror("Memory allocation through malloc failed"); + exit(EXIT_FAILURE); + } + struct timeval before, after; + gettimeofday(&before, NULL); + for (i = 0; i < ROW; i++) + { + for (j = 0; j < COL; j++) + { + p[i + j * ROW]++; + } + } + for(i = 0; i < M; i++){ + free(p); + } + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_miss.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_miss.c new file mode 100644 index 0000000..9dfee66 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/cache_miss.c @@ -0,0 +1,30 @@ +/* +gcc -g cache_miss.c -o cache_miss +*/ +#include +#include +#include + +#define ROW (20*1024) +#define COL (20*1024) +#define N (ROW*COL) + +int main(void) +{ + int i, j; + int *p = (int*) malloc(sizeof(int) * N); + double msecs = 0; + struct timeval before, after; + gettimeofday(&before, NULL); + for (i = 0; i < COL; i++) + { + for (j = 0; j < ROW; j++) + { + p[i + j * COL]++; + } + } + gettimeofday(&after, NULL); + msecs = (after.tv_sec - before.tv_sec) * 1000.0+(after.tv_sec - before.tv_sec)/1000.0; + printf("execution time = %2.3lf ms\n", msecs); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss.c new file mode 100644 index 0000000..0e29e4e --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss.c @@ -0,0 +1,36 @@ +/* +gcc -g llc_miss.c -o llc_miss +*/ +#include +#include + +void llcMiss3Array(int *** pArr, int x, int y, int z, int m); + +int main(void) +{ + int x, y, z, m; + int *** array = NULL; + x = 1000*1024; + y = 100*1024; + z = 100*1024; + m = 5*1024; + llcMiss3Array(array, x, y, z, m); + array = NULL; + return 0; +} +void llcMiss3Array(int *** pArr, int x, int y, int z, int m){ + int i, j, k; + pArr = (int ***)malloc(m * sizeof(int **)); + for(i = 0;i < x;i++){ + pArr[i] = (int **)malloc(y * sizeof(int **)); + for (j = 0;j < y;j++){ + pArr[i][j] = (int *)malloc(y * sizeof(int)); + for(k = 0; k < z; k++){ + pArr[i][j][k] = 100 * (i + j + k + 1) + 1000*x + 100*y + 10*z + 101*m + 19999999999; + printf("%d ", pArr[i][j][k]); + } + printf("\n"); + } + printf("\n"); + } +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss_clean.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss_clean.c new file mode 100644 index 0000000..7498b48 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/miss/llc_miss_clean.c @@ -0,0 +1,50 @@ +/* +gcc -g llc_miss.c -o llc_miss +*/ +#include +#include + +void Malloc3Array(int *** pArr, int x, int y, int z); +void Free3Array(int *** pArr, int x, int y); + +int main(void) +{ + int x, y, z, m; + int *** array = NULL; + x = 1000 * 1024; + y = 100 * 1024; + z = 100 * 1024; + m = 5 * 1024; + Malloc3Array(array, x, y, z); + Free3Array(array,x,y); + array = NULL; + return 0; +} +void Malloc3Array(int *** pArr, int x, int y, int z){ + int i, j, k; + pArr = (int ***)malloc(y * sizeof(int **)); + for(i = 0;i < x;i++){ + pArr[i] = (int **)malloc(y * sizeof(int **)); + for (j = 0;j < y;j++){ + pArr[i][j] = (int *)malloc(y * sizeof(int)); + for(k = 0; k < z; k++){ + pArr[i][j][k] = i + j + k + 1; + printf("%d ", pArr[i][j][k]); + } + printf("\n"); + } + printf("\n"); + } +} +void Free3Array(int *** pArr, int x, int y){ + int i, j; + for (i = 0; i < x; i++){ + for (j = 0 ;j < y;j++){ + free(pArr[i][j]); + pArr[i][j] = 0; + } + free(pArr[i]); + pArr[i] = 0; + } + free(pArr); +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply.c new file mode 100644 index 0000000..32398f9 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply.c @@ -0,0 +1,87 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* +一维矩阵计算 +gcc -g multiply.c -o multiply +*/ + +#include +#include +#include +#include + +#define N 1000000000 +#define SEED 0x1234 + +float *g_a, *g_b, *g_c; + +void gen_data(void) +{ + unsigned i; + g_a = (float*)malloc(N * sizeof(float)); + g_b = (float*)malloc(N * sizeof(float)); + g_c = (float*)malloc(N * sizeof(float)); + if (g_a == NULL || g_b == NULL || g_c == NULL) { + perror("Memory allocation through malloc failed"); + exit(EXIT_FAILURE); + } + for (i = 0; i < N; i++) { + // SEED * 0.1 is used to get duplicated random number + g_a[i] = (float)(SEED * 0.1); + g_b[i] = (float)(SEED * 0.1); + } +} + +void free_data(void) +{ + free(g_a); + free(g_b); + free(g_c); +} + +void multiply(void) +{ + unsigned i; + for (i = 0; i < N; i++) { + g_c[i] = g_a[i] * g_b[i]; + } +} + +void print_data(void) +{ + // print first 2 and last 2 element. + printf("%f, %f, %f, %f\n", g_c[0], g_c[1], g_c[N - 2], g_c[N - 1]); +} + +int main(void) +{ + double msecs; + struct timeval before, after; + + gen_data(); + gettimeofday(&before, NULL); + multiply(); + gettimeofday(&after, NULL); + + // 1000 is used to convert tv_sec and tv_usec to msec. + msecs = (after.tv_sec - before.tv_sec) * 1000.0 + (after.tv_usec - before.tv_usec) / 1000.0; + print_data(); + printf("Execution time = %2.3lf ms\n", msecs); + + free_data(); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_simd.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_simd.c new file mode 100644 index 0000000..32dcd45 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_simd.c @@ -0,0 +1,105 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* +一维矩阵计算,采用NEON指令优化 +gcc -g multiply_simd.c -o multiply_simd +*/ + +#include +#include +#include +#include +#include + +#define N 1000000000 +#define SEED 0x1234 + +float *g_a, *g_b, *g_c; + +void gen_data(void) +{ + unsigned i; + g_a = (float*)malloc(N * sizeof(float)); + g_b = (float*)malloc(N * sizeof(float)); + g_c = (float*)malloc(N * sizeof(float)); + if (g_a == NULL || g_b == NULL || g_c == NULL) { + perror("Memory allocation through malloc failed"); + exit(EXIT_FAILURE); + } + for (i = 0; i < N; i++) { + // SEED * 0.1 is used to get duplicated random number + g_a[i] = (float)(SEED * 0.1); + g_b[i] = (float)(SEED * 0.1); + } +} + +void free_data(void) +{ + free(g_a); + free(g_b); + free(g_c); +} + +void multiply(void) +{ + unsigned i; + for (i = 0; i < N; i++) { + g_c[i] = g_a[i] * g_b[i]; + } +} + +void multiply_neon(void) +{ + int i; + float32x4_t src1, src2, dst; + + for (i = 0; i < (N & ((~(unsigned)0x3))); i += 4) { + src1 = vld1q_f32(g_a + i); + src2 = vld1q_f32(g_b + i); + dst = vmulq_f32(src1, src2); + vst1q_f32(g_c + i, dst); + } + + for (; i < N; i++) { + g_c[i] = g_a[i] * g_b[i]; + } +} + +void print_data(void) +{ + // print first 2 and last 2 element. + printf("%f, %f, %f, %f\n", g_c[0], g_c[1], g_c[N - 2], g_c[N - 1]); +} + +int main(void) +{ + double msecs; + struct timeval before, after; + + gen_data(); + gettimeofday(&before, NULL); + multiply_neon(); + gettimeofday(&after, NULL); + + // 1000 is used to convert tv_sec and tv_usec to msec. + msecs = (after.tv_sec - before.tv_sec) * 1000.0 + (after.tv_usec - before.tv_usec) / 1000.0; + print_data(); + printf("Execution time = %2.3lf ms\n", msecs); + + free_data(); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_start.sh b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_start.sh new file mode 100644 index 0000000..9840e47 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiply_start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +for i in {1..200} +do + taskset -c 1 ./multiply +done diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiplysimd_start.sh b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiplysimd_start.sh new file mode 100644 index 0000000..6e11422 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/multiply/multiplysimd_start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +for i in {1..200} +do + taskset -c 2 ./multiply_simd +done diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound.c new file mode 100644 index 0000000..13fb4b9 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound.c @@ -0,0 +1,41 @@ +#include "utils.h" + +#define MAX_ARRAY_SIZE 409600 +#define LOOP_SIZE 1 +#define BLOCK_SIZE 4096 + +void MemoryBoundBench(Point *pointA, double *ret, int n) +{ + if (pointA == NULL || ret == NULL) { + return; + } + + int i,j; + #pragma omp parallel for + for (i = 0; i< n; i++) { + ret[i] = 0.0; + for (j = 0; j < n; j++){ + ret[i] += pointA[i].x + pointA[j].y; + } + } +} + +int main() +{ + Point *pointA = InitPointsVector(MAX_ARRAY_SIZE); + + double *ret = (double*)malloc(MAX_ARRAY_SIZE * sizeof(double)); + if (ret == NULL) { + printf("ERROR: Memory Allocate Faild!\n"); + exit(1); + } + + uint64_t ts_start = GetTime_ns(); + int i; + for (i = 0; i < LOOP_SIZE; i++) { + MemoryBoundBench(pointA, ret, MAX_ARRAY_SIZE); + } + uint64_t ts_end = GetTime_ns(); + printf("Total Cost Time = %f ms\n", (ts_end - ts_start) / 1000000.0); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound_mod.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound_mod.c new file mode 100644 index 0000000..86d3d9e --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/memory_bound_mod.c @@ -0,0 +1,44 @@ +#include "utils.h" + +#define MAX_ARRAY_SIZE 409600 +#define LOOP_SIZE 1 +#define BLOCK_SIZE 4096 + + +void MemoryBoundBench_OPT(Point *pointA, double *ret, int n) +{ + if (pointA == NULL || ret == NULL) { + return; + } + + int i,j,k; + for (k = 0; k < n; k += BLOCK_SIZE) { + #pragma omp parallel for + for (i = 0; i< n; i++) { + ret[i] = 0.0; + for (j = 0; j < BLOCK_SIZE; j++){ + ret[i] += pointA[i].x + pointA[j + k].y; + } + } + } +} + +int main() +{ + Point *pointA = InitPointsVector(MAX_ARRAY_SIZE); + + double *ret = (double*)malloc(MAX_ARRAY_SIZE * sizeof(double)); + if (ret == NULL) { + printf("ERROR: Memory Allocate Faild!\n"); + exit(1); + } + + uint64_t ts_start = GetTime_ns(); + int i; + for (i = 0; i < LOOP_SIZE; i++) { + MemoryBoundBench_OPT(pointA, ret, MAX_ARRAY_SIZE); + } + uint64_t ts_end = GetTime_ns(); + printf("Total Cost Time = %f ms\n", (ts_end - ts_start) / 1000000.0); + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/ring.c b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/ring.c new file mode 100644 index 0000000..61864ed --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/ring.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + // Initialize the MPI environment + MPI_Init(NULL, NULL); + // Find out rank, size + int world_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + int world_size; + MPI_Comm_size(MPI_COMM_WORLD, &world_size); + + int token; + // Receive from the lower process and send to the higher process. Take care + // of the special case when you are the first process to prevent deadlock + if (world_rank != 0) { + MPI_Recv(&token, 1, MPI_INT, world_rank - 1, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + printf("Process %d received token %d from process %d\n", world_rank, token, + world_rank - 1); + } else { + // Set the token's value if you are process 0 + token = -1; + } + + // sleep(100); + MPI_Send(&token, 1, MPI_INT, (world_rank + 1) % world_size, 0, + MPI_COMM_WORLD); + // Now process 0 can receive from the last process. This makes sure that at + // least one MPI_Send is initialized before all MPI_Recvs (again, to prevent + // deadlock) + if (world_rank == 0) { + MPI_Recv(&token, 1, MPI_INT, world_size - 1, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + printf("Process %d received token %d from process %d\n", world_rank, token, + world_rank - 1); + } + MPI_Finalize(); +} diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/utils.h b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/utils.h new file mode 100644 index 0000000..453f21f --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp-mpi/utils.h @@ -0,0 +1,105 @@ +#ifndef HPC_UTILS_H +#define HPC_UTILS_H + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SEC2NS 1000000000 + +typedef struct Point_t { + double x; + double y; +}Point; + +static inline uint64_t GetTime_ns() +{ + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return ts.tv_sec * SEC2NS + ts.tv_nsec; +} + +static inline uint64_t xorshf96() +{ + static uint64_t x=123456789; + static uint64_t y=362436069; + static uint64_t z=521288629; + uint64_t t; + + x ^= x << 16; + x ^= x >> 5; + x ^= x << 1; + + t = x; + x = y; + y = z; + + z = t ^ x ^ y; + return z; +} + +static inline uint64_t my_random() +{ + return xorshf96(); +} + +static inline double random_double(uint32_t range) +{ + return (my_random() % range) * (double)(1.0); +} + +static inline Point *InitPointsVector(int len) +{ + Point *pointsVector = (Point*)malloc(len * sizeof(Point)); + if (pointsVector == NULL) { + printf("ERROR: Memory Allocate Failed!\n"); + exit(1); + } + int i; + #pragma omp parallel for + for (i = 0; i < len; i++){ + pointsVector[i].x = random_double(len); + pointsVector[i].y = random_double(len); + } + return pointsVector; +} + +static inline double ComputPointDistance(Point *pointA, Point *pointB) +{ + double horizontal, vertical, pointDis; + horizontal = pointA->x - pointB->x; + vertical = pointA->y - pointB->y; + pointDis = sqrt((horizontal * horizontal) + (vertical * vertical)); + return pointDis; +} + +void set_thread_affinity(uint16_t core_id) +{ + cpu_set_t cpu_mask; + cpu_set_t get; + + CPU_ZERO(&cpu_mask); + CPU_SET(core_id, &cpu_mask); + + if(sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask)==-1) + { + printf("set cpu affinity faild ...\n"); + exit(1); + } + + if(sched_getaffinity(0, sizeof(get), &get)==-1) + { + printf("get affinity faild...\n"); + exit(1); + } +} + +#endif diff --git a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/cal_pi.cpp b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/cal_pi.cpp new file mode 100644 index 0000000..b6f9a78 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/omp/cal_pi.cpp @@ -0,0 +1,22 @@ +#include "stdio.h" +#include "omp.h" +static long num_steps = 6000000000; +double step; + +int main() +{ + long i; + double x, pi, sum = 0.0; + step = 1.0/(double)num_steps; + double start = omp_get_wtime(); + for (i=0; i +#include +#include +#include +#include + +#define __USE_GNU +#include +#include +#include +#include +#define THREAD_MAX_NUM 100 + +int num=0; +void* threadFun(void* arg) +{ + cpu_set_t mask; + cpu_set_t get; + int *a = (int *)arg; + printf("the a is:%d\n",*a); + CPU_ZERO(&mask); + CPU_SET(*a,&mask); + if (sched_setaffinity(0, sizeof(mask), &mask) == -1) + { + printf("warning: could not set CPU affinity, continuing...\n"); + } + while (1) + { + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) + { + printf("warning: cound not get thread affinity, continuing...\n"); + } + int i; + for (i = 0; i < num; i++) + { + if (CPU_ISSET(i, &get)) + { + printf("this thread %d is running processor : %d\n", i,i); + } + } + } + return NULL; +} + +int main(int argc, char* argv[]) +{ + num = sysconf(_SC_NPROCESSORS_CONF); + pthread_t thread[THREAD_MAX_NUM]; + printf("system has %i processor(s). \n", num); + int tid[THREAD_MAX_NUM]; + int i; + for(i=0;i +#include +#include +#include +#include + +#define __USE_GNU +#include +#include +#include +#include +#define THREAD_MAX_NUM 100 + +int num=0; +void* threadFun(void* arg) +{ + cpu_set_t mask; + cpu_set_t get; + int *a = (int *)arg; + printf("the a is:%d\n",*a); + CPU_ZERO(&mask); + CPU_SET(*a,&mask); + while (1) + { + CPU_ZERO(&get); + if (sched_getaffinity(0, sizeof(get), &get) == -1) + { + printf("warning: cound not get thread affinity, continuing...\n"); + } + int i; + for (i = 0; i < num; i++) + { + if (CPU_ISSET(i, &get)) + { + printf("this thread %d is running processor : %d\n", i,i); + } + } + } + return NULL; +} + +int main(int argc, char* argv[]) +{ + num = sysconf(_SC_NPROCESSORS_CONF); + pthread_t thread[THREAD_MAX_NUM]; + printf("system has %i processor(s). \n", num); + int tid[THREAD_MAX_NUM]; + int i; + for(i=0;i +#include +#include +#include +#include + +#define MEM_PART "/proc/meminfo" +#define M 50 + +struct MemInfo { + char memTotal[20]; + char memFree[20]; + char memAvailable[20]; + char swapTotal[20]; + char swapFree[20]; +}; + +typedef struct MemInfo MemInfoRead, *p_MemInfoRead; + +int GetFileLine(char *result, char *fileName, int lineNumber) +{ + FILE *filePointer = NULL; + int i = 0; + const size_t BUFSIZE = 300; + char buffer[BUFSIZE]; + + if ((fileName == NULL) || (result == NULL)) { + return 0; + } + + if (!(filePointer = fopen(fileName, "rb"))) { + return 0; + } + + while ((!feof(filePointer)) && (i < lineNumber)) { + if (!fgets(buffer, BUFSIZE, filePointer)) { + return 0; + } + i++; + } + + strcpy(result, buffer); + + if (fclose(filePointer) != 0) { + return 1; + } + + return 0; +} + +int GetMemInfo(p_MemInfoRead mem) +{ + const size_t BUFSIZE = 300; + char buffer[BUFSIZE]; + if (mem == NULL) { + printf("\nget_mem_info error!\n"); + return 0; + } + memset(mem, 0, sizeof(MemInfoRead)); + if (GetFileLine(buffer, MEM_PART, 1) == 0) { // read 1st line: memTotal + sscanf(buffer, "%*s %s", mem->memTotal); + } + if (GetFileLine(buffer, MEM_PART, 2) == 0) { // read 2nd line: memFree + sscanf(buffer, "%*s %s", mem->memFree); + } + if (GetFileLine(buffer, MEM_PART, 3) == 0) { // read 3rd line: memAvailable + sscanf(buffer, "%*s %s", mem->memAvailable); + } + if (GetFileLine(buffer, MEM_PART, 15) == 0) { // read 15th line: swapTotal + sscanf(buffer, "%*s %s", mem->swapTotal); + } + if (GetFileLine(buffer, MEM_PART, 16) == 0) { // read 16th line: swapFree + sscanf(buffer, "%*s %s", mem->swapFree); + } + return 0; +} + +int main() +{ + MemInfoRead mem; + const int STEP = 4096; + const int MALLOC_SIZE = 900; + int j; + long long i; + + GetMemInfo(&mem); + printf("\n MemTotal: %s, MemFree: %s, MemAvailable: %s, SwapTotal: %s, SwapFree: %s\n", + mem.memTotal, mem.memFree, mem.memAvailable, mem.swapTotal, mem.swapFree); + long long MemFree = strtol(mem.memFree, NULL, 10); // convert string to long int base 10 + long long SwapFree = strtol(mem.swapFree, NULL, 10); // convert string to long int base 10 + const long long N = MALLOC_SIZE * (MemFree + SwapFree); + + for (j = 0; j < M; j++) { + char *p = (char*) malloc(sizeof(char) * N); + if (p == NULL) { + perror("Memory allocation through malloc failed"); + exit(EXIT_FAILURE); + } + for (i = 0; i < N; i += STEP) { + p[i] = 'A'; + } + sleep(1); + free(p); + } + + return 0; +} \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204GC\346\227\245\345\277\227\350\260\203\344\274\230\345\256\236\350\267\265/README.md" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204GC\346\227\245\345\277\227\350\260\203\344\274\230\345\256\236\350\267\265/README.md" new file mode 100644 index 0000000..f902f20 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204GC\346\227\245\345\277\227\350\260\203\344\274\230\345\256\236\350\267\265/README.md" @@ -0,0 +1,13 @@ +1、示例demo请下载java_perf_test工程,按readme指导操作即可 + +2、调用如下链接出发日志: + +http://ip:9118/gctest/testOOM + +http://ip:9118/gctest/young + +http://ip:9118/gctest/systemgc + +http://ip:9118/gctest/bigdata + +http://ip:9118/gctest/metaspace \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/README.md" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/README.md" new file mode 100644 index 0000000..f393f40 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/README.md" @@ -0,0 +1 @@ +javac TestMemoryLeakKo.java编译后,运行java TestMemoryLeakKo。或java9及以后直接调用java TestMemoryLeakKo.java运行 \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/TestMemoryLeakKo.java" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/TestMemoryLeakKo.java" new file mode 100644 index 0000000..d56a3be --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\345\206\205\345\255\230\346\263\204\346\274\217\350\260\203\344\274\230\345\256\236\350\267\265/TestMemoryLeakKo.java" @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +public class TestMemoryLeakKo { + public static HashSet> hashSetPerson = new HashSet<>(); + + public static void main(String[] args) { + boolean flag = true; + Thread thread = new Thread(() -> { + while (flag) { + List list = new ArrayList<>(1000); + for (int i = 0; i < 1000; i++) { + list.add(new Person()); + } + hashSetPerson.add(list); + try { + Thread.sleep(2000L); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + thread.start(); + } + + public static class Person { + String name = "abc"; + int age = 11; + byte[] b = new byte[1024 * 5]; + } +} \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/DeadLock.java" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/DeadLock.java" new file mode 100644 index 0000000..50a5324 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/DeadLock.java" @@ -0,0 +1,37 @@ +public class DeadLock { + private static final Integer lockOne = new Integer(1); + private static final Integer lockTwo = new Integer(2); + + public static void main(String[] args){ + new Thread(()->{ + try{ + System.out.println("thread1 is running"); + sysnchronized (lockOne){ + System.out.println("thread1 get lock obj1"); + Thread.sleep(1000L); + sysnchronized (lockTwo){ + System.out.println("thread12 get lock obj2"); + Thread.sleep(1000L); + } + } + } catch(InterruptedException e){ + e.printStackTrace(); + } + }).start(); + new Thread(()->{ + try{ + System.out.println("thread2 is running"); + sysnchronized (lockTwo){ + System.out.println("thread2 get lock obj2"); + Thread.sleep(1000L); + sysnchronized (lockOne){ + System.out.println("thread2 get lock obj1"); + Thread.sleep(1000L); + } + } + } catch(InterruptedException e){ + e.printStackTrace(); + } + }).start(); + } +} \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/README.md" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/README.md" new file mode 100644 index 0000000..a6d060f --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\346\255\273\351\224\201\350\260\203\344\274\230\345\256\236\350\267\265/README.md" @@ -0,0 +1,3 @@ +1demoϴ +2ִjavac DeadLock.java DeadLock.javaļ +3ִjava DeadLock \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\347\203\255\347\202\271\345\207\275\346\225\260\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\347\203\255\347\202\271\345\207\275\346\225\260\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" new file mode 100644 index 0000000..d1d642b --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\347\203\255\347\202\271\345\207\275\346\225\260\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" @@ -0,0 +1,7 @@ +1、示例demo请下载java_perf_test工程,按readme指导操作即可 + +2、调用接口: + +http://ip:9118/test/testHotMethod/20 + +http://ip:9118/test/testHotMethodTwo/20 \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/Lock.java" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/Lock.java" new file mode 100644 index 0000000..3fd5e90 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/Lock.java" @@ -0,0 +1,29 @@ +public class Lock { + private static Lock lock = new Lock(); + + public static void main(String[] args) throws Exception { + Thread t = new Thread(new Runnable(){ + @Override + public void run(){ + synchronized (lock){ + try{ + Thread.sleep(10000000L); + }catch(Exception e){ + e.printStackTrace(); + } + } + } + }); + t.start(); + for(int i=0;i<50;i++){ + new Thread(new Runnable(){ + @Override + public void run(){ + synchronized (lock){ + System.out.println("等"); + } + } + }).start(); + } + } +} \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" new file mode 100644 index 0000000..1ad5e3a --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\345\237\272\344\272\216java\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267\347\232\204\351\224\201\347\253\236\344\272\211\345\256\232\344\275\215\350\260\203\344\274\230\345\256\236\350\267\265/README.md" @@ -0,0 +1 @@ +javac Lock.java编译后调用java Lock启动项目,JDK9及以后可直接java Lock.java启动 \ No newline at end of file diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_atomic.c" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_atomic.c" new file mode 100644 index 0000000..50fd001 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_atomic.c" @@ -0,0 +1,54 @@ +# include +# include +# include +# include +# include +# include +# include + +static atomic_int num = 0; +static int count = 800000000; + +void Perror(const char *s) +{ + perror(s); + exit(EXIT_FAILURE); +} + +long long getSystemTime() +{ + struct timeb t; + ftime(&t); + return 1000 * t.time + t.millitm; +} + +void* fun2(void *arg){ + pthread_t thread_id = pthread_self(); + printf("the thread2 id is %1d\n",(long)thread_id); + int i = 1; + for (i;i <= count; i++){ + num += 1; + } +} + +int main() +{ + int err; + pthread_t thread1; + pthread_t thread2; + thread1 = pthread_self(); + printf("the thread1 id is %1d\n",(long)thread1); + long long start = getSystemTime(); + err = pthread_create(&thread2, NULL, fun2, NULL); + if(err != 0){ + Perror("cant create thread2\n"); + } + int i = 1; + for (i;i <= count; i++){ + num += 1; + } + pthread_join(thread2, NULL); + long long end = getSystemTime(); + printf("the num is %d,pay %11d ms\n", num, (end-start)); + return 0; +} diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_mutex.c" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_mutex.c" new file mode 100644 index 0000000..579bffb --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/pthread_mutex.c" @@ -0,0 +1,61 @@ +// gcc -g pthread_mutex.c -o pthread_mutex -lpthread +# include +# include +# include +# include +# include +# include + +static int num=0; +static int count = 200000000; +static int millisecond_coefficient = 1000; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +void Perror(const char *s) +{ + perror(s); + exit(EXIT_FAILURE); +} + +long long getSystemTime() +{ + struct timeb t; + ftime(&t); + return millisecond_coefficient * t.time + t.millitm; +} + +void* fun2(void *arg) +{ + pthread_t thread_id = pthread_self(); + printf("the thread2 id is %1d\n",(long)thread_id); + int i = 1; + for (i;i <= count; i++){ + pthread_mutex_lock(&mutex); + num += 1; + pthread_mutex_unlock(&mutex); + } +} + +int main() +{ + int err; + pthread_t thread1; + pthread_t thread2; + thread1 = pthread_self(); + printf("the thread1 id is %1d\n",(long)thread1); + long long start = getSystemTime(); + err = pthread_create(&thread2, NULL, fun2, NULL); + if(err != 0){ + Perror("cant create thread2\n"); + } + int i = 1; + for (i;i <= count;i++){ + pthread_mutex_lock(&mutex); + num += 1; + pthread_mutex_unlock(&mutex); + } + pthread_join(thread2, NULL); + long long end = getSystemTime(); + printf("The num is %d,pay %11d ms\n",num,(end-start)); + return 0; +} diff --git "a/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/readme.txt" "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/readme.txt" new file mode 100644 index 0000000..0dcec33 --- /dev/null +++ "b/examples/mpi/devkitdemo-main/Hyper_tuner/testdemo/\351\224\201\346\200\247\350\203\275\350\260\203\344\274\230\345\256\236\350\267\265/readme.txt" @@ -0,0 +1,14 @@ +针对提供的两demo做以下说明: +1. demo要求gcc版本在7.3以上,低版本的gcc编译pthread_atomic.c会报错 +2.若需要关联源码,建议编译时加上-g参数 +如:gcc -g pthreadd_mutex.c -o pthread_mutex -lpthread +pthread_atomic 同理 +注意:若无法关联源码,可查看编译二进制是否存在buildid。大部分编译器开启 +buildid,小部分不开启。可以使用file命令(如file pthread_mutex)查看编译后的二进制文件是否存在 +buildid。若不存在,建议加上-Wl,--build-id选项 +如:gcc -Wl,--build-id -g pthreadd_mutex.c -o pthread_mutex -lpthread +3.在使用系统热点函数监测锁热点时,在任务开启的同时,后台运行对应的demo,否则无法采集到锁的热点 +4.用户可通过源码修改循环次数,修改运行时间(不同系统不同gcc版本略有差异) +5.pthread_atomic.c是pthread_mutex.c优化后的demo,采用原子锁的方式实现实现累加 +6.建议web页面设置的运行时长大于应用本身运行时长,否则可能出现web页面无数据情况 + diff --git a/examples/mpi/devkitdemo-main/LICENSE b/examples/mpi/devkitdemo-main/LICENSE new file mode 100644 index 0000000..2bb9ad2 --- /dev/null +++ b/examples/mpi/devkitdemo-main/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. 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, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + 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 Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its 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 using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall 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 or out of the use or inability to use the + Work (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), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/README.md b/examples/mpi/devkitdemo-main/Porting_advisor/README.md new file mode 100644 index 0000000..98d23f7 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/README.md @@ -0,0 +1,17 @@ +# Porting Advisor demo +鲲鹏代码迁移工具是一款可以简化客户应用迁移到基于鲲鹏916/920的服务器的过程的工具。工具仅支持Linux到kunpeng Linux的扫描和分析,可使用该工具分析可迁移性和迁移投入,也可使用该工具自动分析出需要修改的代码内容,并指导用户如何进行修改。 +这个demo展示了如何使用鲲鹏代码迁移工具中的各个功能模块进行代码迁移,并指导用户如何修改扫描出的需要修改的代码行并给出修改建议。 +\ +\ +testdemo文件夹包含code_migration,byte_check,asm_trans,weak_consistency文件夹。 +- code_migration \ + 该文件夹中包含code(优化前的示例代码)和code_mod(优化后的示例代码),是对工具“源码迁移”功能的示例。 +- byte_check \ + 该文件夹中包含bytecheck(示例代码),是对工具“增强功能-结构体字节对齐检查”功能的示例。 +- asm_trans \ + 该文件夹中包含all_asm(全汇编示例代码)、mult_inline_asm(嵌入式汇编多指令示例代码)和single_inline_asm(嵌入式汇编单指令示例代码)三个使用内嵌汇编的示例代码,是对工具“源码迁移”功能的示例。 +- weak_consistency \ + 该文件夹中包含atomic(使用c++ atomic的示例代码)、common(普通场景的示例代码)和lock(含锁保护的示例代码),是对工具“增强功能-内存一致性检查”功能的示例。 +\ +\ +具体使用流程说明书详见华为云鲲鹏开发套件-鲲鹏代码迁移工具 https://support.huaweicloud.com/kunpengdevps/kunpengdevps.html diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/Makefile new file mode 100644 index 0000000..70dcc21 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/Makefile @@ -0,0 +1,24 @@ + # Copyright 2020 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +CURDIR = ${shell pwd} + +target:main.o test.o + @gcc -o $(CURDIR)/target $(CURDIR)/main.o $(CURDIR)/test.o +main.o:main.c + @gcc -c $(CURDIR)/main.c +test.o:test.s + @gcc -c $(CURDIR)/test.s +clean: + @rm target main.o test.o \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/main.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/main.c new file mode 100644 index 0000000..6c43b4f --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/main.c @@ -0,0 +1,26 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +extern int caller(int a, int b); +int main() +{ + int a = 10; + int b = 20; + int sum = caller(a, b); + printf("\nThis is a show demo: \n C function call ASM function, we will translate the ASM code from x86_64 to aarch64. \n"); + printf("The result of the program execution is %d \n \n", sum); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/test.s b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/test.s new file mode 100644 index 0000000..ea5f8ae --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/all_asm/test.s @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + .file "test.s" + .text + .globl caller + .type caller, @function +caller: +.LFB0: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + movl %edi, -4(%rbp) + movl %esi, -8(%rbp) + movl -8(%rbp), %eax + movl -4(%rbp), %edx + addl %edx, %eax + popq %rbp + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size caller, .-caller + .ident "GCC: (GNU) 4.8.5 20150623 (NeoKylin 4.8.5-36)" + .section .note.GNU-stack,"",@progbits \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/mult_inline_asm/gcd.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/mult_inline_asm/gcd.c new file mode 100644 index 0000000..8e4ce48 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/mult_inline_asm/gcd.c @@ -0,0 +1,52 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +int gcd(int a, int b) +{ + int result; + __asm__ __volatile__( + "CONTD: cmpl $0, %%ebx\n\t" + "je END\n\t" + "xorl %%edx, %%edx\n\t" + "divl %%ebx\n\t" + "movl %%ebx, %%eax\n\t" + "movl %%edx, %%ebx\n\t" + "jmp CONTD\n\t" + "END: movl %%eax, %0\n\t" + : "=r" (result) + : "a"(a), "b"(b) + ); + return result; +} + +int Gcd(int a, int b) +{ + if (b == 0) { + return a; + } + return Gcd(b, a % b); +} + +int main() +{ + printf("Enter two integers :\n45, 66\n"); + int first = 45; + int second = 66; + printf("GCD of %d & %d is %d by function Gcd\n", first, second, Gcd(first, second)); + printf("GCD of %d & %d is %d by function gcd\n", first, second, gcd(first, second)); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/single_inline_asm/swap.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/single_inline_asm/swap.c new file mode 100644 index 0000000..69f7fdc --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/asm_trans/single_inline_asm/swap.c @@ -0,0 +1,38 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +/* 存储大小端交换 */ +unsigned int swap_big_endian(unsigned int data) +{ + unsigned int result; + /* 汇编倒序指令 */ + __asm__("bswap %0" : "=r" (result) : "0" (data)); + + return result; +} + +int main() +{ + unsigned int data = 0x12345678; + unsigned int result; + + result = swap_big_endian(data); + printf("the result is 0x%x\n", result); + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/Makefile new file mode 100644 index 0000000..b036fa2 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/Makefile @@ -0,0 +1,28 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +VERSION=1.0 +RELEASE=202104 + +CURDIR = ${shell pwd} +FLAGS = -g -DDEBUG -W -Wall -fPIC -lstdc++ +GLIBS = -lm -lrt -pthread -lz + +PATK: bytecheck.o + gcc -o PATK $(FLAGS) ./bytecheck.o $(GLIBS) + +bytecheck.o: bytecheck.cpp + gcc -o bytecheck.o -c bytecheck.cpp + +clean: + @rm -rf *.o PATK diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.cpp b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.cpp new file mode 100644 index 0000000..c903fec --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.cpp @@ -0,0 +1,146 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "bytecheck.hpp" +using namespace std; + +/* 验证引入其他自定义文件内struct的使用 */ +typedef struct myStruct4{ + char value4_1; + int value4_2; + float value4_3; + int value4_4[5][6]; + char value4_5[2][5]; + struct myStruct2 value4_6; + struct myStruct3 value4_7; +}; + +/* 验证位域不提示 */ +struct myStruct5{ + int value5_1; + int value5_2 : 1; +} *mystruct5; + +typedef struct myStruct6{ + char value6_1[50]; + char calue6_2; + struct myStruct5 mystruct5; +}temp6; + +/* 验证__attribute__((aligned(16))) */ +typedef struct myStruct7{ + char value7_1; + int calue7_2; +}temp7; + +typedef struct myStruct8{ + char value8_1; + int value8_2; +} __attribute__((aligned(16))) mystruct8; + +/* +1、 验证 #pragma pack(n) +2、验证 #pragma pack 嵌套 attribute +*/ +#pragma pack(8) + +typedef struct myStruct9{ + char value9_1; + int value9_2; +}temp9; + +typedef struct myStruct10{ + char value10_1; + int value10_2; +} __attribute__((aligned(16))) mystruct10; + +typedef struct myStruct11{ + char value11_1; + int value11_2; +} __attribute__((packed)); + +#pragma pack() + +/* +1、验证union +2、验证enum +*/ +//union +union myUnion1{ + char value1_1; + int value1_2; + double value1_3; +}; + +union myUnion2{ + char value2_1; + int value2_2; + float value2_3; + union myUnion1 value2_4; +}; + +//enum +enum myEnum1{ + MON1='A', TUE1, WED1, THU1 +}; + +enum myEnum2{ + MON2=-1, TUE2, WED2, THU2=2, FRI2='a', SAT2=123456 +}; + +struct myStruct12{ + enum myEnum1 my_enum1; + enum myEnum2 my_enum2; +}; + +struct myStruct13{ + union myUnion1 my_union1; + union myUnion2 my_union2; +}; + +int main(){ + cout << "验证自定义基本类型" << endl; + struct myStruct0 tempStruct0; + struct myStruct1 tempStruct1; + + cout << "验证嵌套使用struct" << endl; + struct myStruct2 tempStruct2; + struct myStruct3 tempStruct3; + + cout << "验证引入其他自定义文件内struct的使用" << endl; + struct myStruct4 tempStruct4; + + cout << "验证位域不提示" << endl; + struct myStruct5 tempStruct5; + struct myStruct6 tempStruct6; + + cout << "验证__attribute__((aligned(16)))" << endl; + struct myStruct7 tempStruct7; + mystruct8 tempStruct8_1; + + cout << "验证 #pragma pack(n)&&#pragma pack 嵌套 attribute" << endl; + struct myStruct9 tempStruct9; + mystruct10 tempStruct10; + struct myStruct11 mystruct11; + + cout << "验证union&&验证enum" << endl; + struct myStruct12 tempStruct12; + struct myStruct13 tempStruct13; + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.hpp b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.hpp new file mode 100644 index 0000000..9c8663c --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/byte_check/bytecheck.hpp @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +using namespace std; + + +struct myStruct0{ + char value0_1; + int value0_2; + float value0_3; + long value0_4; + long int value0_5; +}; + +struct myStruct1{ + char value1_1; + int value1_2; + float value1_3; +}; + +struct myStruct2{ + short value2_1; + int value2_2; + long double value2_3; + struct myStruct1 value2_4; + struct myStruct1 value2_5; + vector value2_6; +}; + +typedef struct myStruct3{ + char value3_1; + int value3_2; + float value3_3; + struct myStruct2 value3_4; + vector value3_5; +}; diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/Makefile new file mode 100644 index 0000000..bf88c0b --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/Makefile @@ -0,0 +1,35 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +VERSION=1.0 +RELEASE=202011 + +CURDIR = ${shell pwd} +FLAGS = -g -DDEBUG -W -Wall -fPIC -std=gnu99 +GLIBS = -lm -lrt -pthread -lz + +PATK: file_lock.o ksw.o interface.o + gcc -o PATK $(FLAGS) ./file_lock.o ./ksw.o ./interface.o $(GLIBS) + +file_lock.o: file_lock.c + gcc -o file_lock.o $(FLAGS) -c file_lock.c + +ksw.o: ksw.c + gcc -o ksw.o $(FLAGS) -c ksw.c + +interface.o: interface.s + @gcc -c ./interface.s + +clean: + @rm -rf *.o PATK diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.c new file mode 100644 index 0000000..094c51c --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.c @@ -0,0 +1,146 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include "ksw.h" + +#define TEST_NUM 10000000 + +static int g_count = 0; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +/* 存储大小端交换 */ +unsigned int swap_big_endian(unsigned int data) +{ + unsigned int result = 0; + /* 汇编倒序指令 */ + __asm__("bswap %0" : "=r" (result) : "0" (data)); + return result; +} + +long int multi_inst(long int data1, long int data2) +{ + long int result = 0; + __asm__ __volatile("nop\n\t" + "movq %[data1], %%rax\n\t" + "movl $4, %%ecx\n\t" + "addq %%rax, %%rax\n\t" + "orq %[data2], %%rax\n" + "movq %%rax, %0\n" + :"=r"(result) + :[data1]"r"(data1), [data2]"r"(data2) + :"rax", "ecx", "cc", "memory" + ); + return result; +} + +void inst_function_test_lock_inc(signed char V0) +{ + asm volatile( + "lock ; incb %[cnt] \n\t" + : [cnt] "+m"(V0) + : + ); +} + +/* 对全局变量g_count进行加操作 */ +void* inc_count(void *arg) +{ + int i = 0; + pthread_t thread_id = pthread_self(); + printf("the thread1 id is %ld\n", (long)thread_id); + + for(; i<=TEST_NUM; i++) { + pthread_mutex_lock(&mutex); + g_count += 1; + pthread_mutex_unlock(&mutex); + } +} + +/* 对全局变量g_count进行减操作 */ +void* dec_count(void *arg) +{ + int i = 0; + pthread_t thread_id = pthread_self(); + printf("the thread2 id is %ld\n", (long)thread_id); + + for(; i<=TEST_NUM; i++) { + pthread_mutex_lock(&mutex); + g_count -= 1; + pthread_mutex_unlock(&mutex); + } +} + +/* 程序功能 : 将data倒序存放,创建两个线程对全局变量g_count进行操作,将倒序存放的data和g_count比较 */ +int main() +{ + int ret; + int *p; + pthread_t thread1; + pthread_t thread2; + unsigned int data = 0x12345678; + unsigned int result1, result2; + unsigned int out; + int n, t; + + for (n = 1; n <= 20000000; n = n +1) + { + t += 1; + } + + /* 计算a + a | b */ + result1 = multi_inst(0x2, 5); + /* 数据翻转 */ + result2 = swap_big_endian(data); + /* 向量加 */ + __m256i sumVec = add_epi(result1, result2); + uint32_t *valVec = (uint32_t*)&sumVec; + printf("sum vec: %x %x %x %x \n", + valVec[0], valVec[1], valVec[2], valVec[3]); + + /* Create thread1 */ + ret = pthread_create(&thread1, NULL, inc_count, NULL); + if (ret != 0 ) { + printf("can't createthread1\n"); + return -1; + } + + /* Create thread2 */ + ret = pthread_create(&thread2, NULL, dec_count, NULL); + if (ret != 0 ) { + printf("can't createthread2\n"); + return -1; + } + printf("get g_count=%d\n", g_count); + + /* show kunpeng plugin identified optimizerable functions in ARM or kunpeng chip */ + p = memcpy(&out, &result2, sizeof(int)); + if (p == NULL) { + printf("memcpy failed\n"); + return -1; + } + printf("copy result to out=%x\n", out); + + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + + printf("destory thread to get g_count=%d\n", g_count); + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.h b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.h new file mode 100644 index 0000000..1682d22 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/file_lock.h @@ -0,0 +1,68 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __FILE_LOCK_H_ +#define __FILE_LOCK_H_ + +#define NO_FLUSH 0 +#define PARTIAL_FLUSH 1 +#define SYNC_FLUSH 2 +#define FULL_FLUSH 3 +#define FINISH 4 +#define OK 0 +#define STREAM_END 1 +#define NEED_DICT 2 +#define ERRNO (-1) +#define STREAM_ERROR (-2) +#define DATA_ERROR (-3) +#define MEM_ERROR (-4) +#define BUF_ERROR (-5) +#define VERSION_ERROR (-6) +#define NO_COMPRESSION 0 +#define BEST_SPEED 1 +#define BEST_COMPRESSION 9 +#define DEFAULT_COMPRESSION (-1) +#define FILTERED 1 +#define HUFFMAN_ONLY 2 +#define DEFAULT_STRATEGY 0 +#define BINARY 0 +#define ASCII 1 +#define UNKNOWN 2 +#define DEFLATED 8 +#define NULL 0 + +typedef struct z_stream_s { + const char *next_in; /* next input byte */ + unsigned int avail_in; /* number of bytes available at next_in */ + long total_in; /*total number of input bytes read so far */ + + char *next_out; /* next output byte will go here */ + unsigned int avail_out; /* remaining free space at next_out */ + long total_out; /* total number of bytes output so far */ + + const char *msg; /* last error message, NULL if no error */ + + void * zalloc; /* used to allocate the internal state */ + void * zfree; /* used to free the internal state */ + void * opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text + for deflate, or the decoding state for inflate */ + + long adler; /* Adler-32 or CRC-32 value of the uncompressed data */ + long reserved; /* reserved for future use */ +}z_stream; + +#endif diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/interface.s b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/interface.s new file mode 100644 index 0000000..cbf4bb2 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/interface.s @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + .file "test.s" + .text + .globl caller + .type caller, @function +caller: +.LFB0: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + movl %edi, -4(%rbp) + movl %esi, -8(%rbp) + movl -8(%rbp), %eax + movl -4(%rbp), %edx + addl %edx, %eax + popq %rbp + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size caller, .-caller + .ident "GCC: (GNU) 4.8.5 20150623 (NeoKylin 4.8.5-36)" + .section .note.GNU-stack,"",@progbits + diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.c new file mode 100644 index 0000000..130d61d --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.c @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "ksw.h" + + +__m256i add_epi(unsigned int data1, unsigned int data2) +{ + __m256i i2561 = _mm256_set1_epi32(data1); + __m256i i2562 = _mm256_set1_epi32(data2); + __m256i result256 = _mm256_sub_epi32(i2561, i2562); + return result256; +} + +__m256i max_epi(unsigned int data1, unsigned int data2) +{ + __m256i i2561 = _mm256_set1_epi32(data1); + __m256i i2562 = _mm256_set1_epi32(data2); + __m256i result256 = _mm256_max_epi32(i2561, i2562); + return result256; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.h b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.h new file mode 100644 index 0000000..c353933 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code/ksw.h @@ -0,0 +1,23 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __DEMO_H_ +#define __DEMO_H_ +#include + +__m256i add_epi(unsigned int data1, unsigned int data2); +__m256i max_epi(unsigned int data1, unsigned int data2); + +#endif diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/Makefile new file mode 100644 index 0000000..0dc14e9 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/Makefile @@ -0,0 +1,35 @@ + # Copyright 2020 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +VERSION=1.0 +RELEASE=202011 + +CURDIR = ${shell pwd} +FLAGS = -g -DDEBUG -W -Wall -fPIC -std=gnu99 -march=armv8-a -fsigned-char +GLIBS = -lm -lrt -pthread -lz + +PATK: file_lock.o ksw.o interface.o + gcc -o PATK $(FLAGS) ./file_lock.o ./ksw.o ./interface.o $(GLIBS) + +file_lock.o: file_lock.c + gcc -o file_lock.o $(FLAGS) -c file_lock.c + +ksw.o: ksw.c + gcc -o ksw.o $(FLAGS) -c ksw.c + +interface.o: interface.s + @gcc -c ./interface.s + +clean: + @rm -rf *.o PATK diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.c new file mode 100644 index 0000000..9c1ecf7 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.c @@ -0,0 +1,186 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include "ksw.h" + +#define TEST_NUM 10000000 + +static int g_count = 0; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +/* 存储大小端交换 */ +unsigned int swap_big_endian(unsigned int data) +{ + unsigned int result = 0; + /* 汇编倒序指令 */ + #if defined __x86_64__ + __asm__("bswap %0" : "=r" (result) : "0" (data)); + #elif defined __aarch64__ + // Description: Replace with the convered code block suggested. Note: + // Note 1: Check whether the C/C++ variavle expressions associated with the embedded assembly hava side effect. The side effect expressions need to be modified in the new code to be used. + //Suggestion: + { + result = data; + __asm__ __volatile__("rev %w0, %w1" + :"=r"(result) + :"0"(result) + ); + } + #endif + return result; +} + +long int multi_inst(long int data1, long int data2) +{ + long int result = 0; + #if defined __x86_64__ + __asm__ __volatile("nop\n\t" + "movq %[data1], %%rax\n\t" + "movl $4, %%ecx\n\t" + "addq %%rax, %%rax\n\t" + "orq %[data2], %%rax\n" + "movq %%rax, %0\n" + :"=r"(result) + :[data1]"r"(data1), [data2]"r"(data2) + :"rax", "ecx", "cc", "memory" + ); + #elif defined __aarch64__ + __asm__( + "mov x0, xzr \n\t" + "ldr x1, %[ARG1_64] \n\t" + "ldr x2, %[ARG2_64] \n\t" + "mov x3, %[ARG0_64_output] \n\t" + "orr x8, x2, x1, lsl #1\n\t" + "str x8, [x3]\n\t" + "b .Lfunc_end_kpt_1\n\t" + ".Lfunc_end_kpt_1:\n\t" + : + : [ARG1_64]"m"(data1), [ARG2_64]"m"(data2), [ARG0_64_output]"r"(&result) + : "x0", "x1", "x2", "x3" + ); + #endif + return result; +} + +void inst_function_test_lock_inc(signed char V0) +{ + #if defined __x86_64__ + asm volatile( + "lock ; incb %[cnt] \n\t" + : [cnt] "+m"(V0) + : + ); + #elif defined __aarch64__ + // Description: Replace with the convered code block suggested. Note: + // note 1: Check whether your memory variables are aligned. + // Suggestion: + { + unsigned char *memAddr_E0=(unsigned char*)(&V0); + __atomic_fetch_add(memAddr_E0, 1, __ATOMIC_SEQ_CST); + } + #endif +} + +/* 对全局变量g_count进行加操作 */ +void* inc_count(void *arg) +{ + int i = 0; + pthread_t thread_id = pthread_self(); + printf("the thread1 id is %ld\n", (long)thread_id); + + for (; i<=TEST_NUM; i++) { + pthread_mutex_lock(&mutex); + g_count += 1; + pthread_mutex_unlock(&mutex); + } +} + +/* 对全局变量g_count进行减操作 */ +void* dec_count(void *arg) +{ + int i = 0; + pthread_t thread_id = pthread_self(); + printf("the thread2 id is %ld\n", (long)thread_id); + + for (; i<=TEST_NUM; i++) { + pthread_mutex_lock(&mutex); + g_count -= 1; + pthread_mutex_unlock(&mutex); + } +} + +/* 程序功能 : 将data倒序存放,创建两个线程对全局变量g_count进行操作*/ +int main() +{ + int ret; + int *p; + pthread_t thread1; + pthread_t thread2; + unsigned int data = 0x12345678; + unsigned int result1, result2; + unsigned int out; + unsigned int ans = 0; + int n, t; + + for (n = 1; n <= 20000000; n = n +1) + { + t += 1; + } + + /* 计算a + a | b */ + result1 = multi_inst(0x2, 5); + /* 翻转数据 */ + result2 = swap_big_endian(data); + /* 向量加 */ + __m256i sumVec = add_epi(result1, result2); + uint32_t *valVec = (uint32_t*)&sumVec; + printf("sum vec: %x %x %x %x \n", + valVec[0], valVec[1], valVec[2], valVec[3]); + + /* Create thread1 */ + ret = pthread_create(&thread1, NULL, inc_count, NULL); + if (ret != 0) { + printf("can't create thread1\n"); + return -1; + } + + /* Create thread2 */ + ret = pthread_create(&thread2, NULL, dec_count, NULL); + if (ret != 0) { + printf("can't create thread2\n"); + return -1; + } + printf("get g_count=%d\n", g_count); + + /* show kunpeng plugin identified optimizerable functions in ARM or kunpeng chip */ + p = memcpy(&out, &result2, sizeof(int)); + if (p == NULL) { + printf("memcpy failed\n"); + return -1; + } + printf("copy result to out=%x\n", out); + + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + + printf("destory thread to get g_count=%d\n", g_count); + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.h b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.h new file mode 100644 index 0000000..96ad561 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/file_lock.h @@ -0,0 +1,69 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __FILE_LOCK_H_ +#define __FILE_LOCK_H_ + +#define NO_FLUSH 0 +#define PARTIAL_FLUSH 1 +#define SYNC_FLUSH 2 +#define FULL_FLUSH 3 +#define FINISH 4 +#define OK 0 +#define STREAM_END 1 +#define NEED_DICT 2 +#define ERRNO (-1) +#define STREAM_ERROR (-2) +#define DATA_ERROR (-3) +#define MEM_ERROR (-4) +#define BUF_ERROR (-5) +#define VERSION_ERROR (-6) +#define NO_COMPRESSION 0 +#define BEST_SPEED 1 +#define BEST_COMPRESSION 9 +#define DEFAULT_COMPRESSION (-1) +#define FILTERED 1 +#define HUFFMAN_ONLY 2 +#define DEFAULT_STRATEGY 0 +#define BINARY 0 +#define ASCII 1 +#define UNKNOWN 2 +#define DEFLATED 8 +#define NULL 0 + +typedef struct z_stream_s { + const char *next_in; /* next input byte */ + unsigned int avail_in; /* number of bytes available at next_in */ + long total_in; /*total number of input bytes read so far */ + +char *next_out; /* next output byte will go here */ + unsigned int avail_out; /* remaining free space at next_out */ + long total_out; /* total number of bytes output so far */ + + const char *msg; /* last error message, NULL if no error */ + + void * zalloc; /* used to allocate the internal state */ + void * zfree; /* used to free the internal state */ + void * opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text + for deflate, or the decoding state for inflate */ + + long adler; /* Adler-32 or CRC-32 value of the uncompressed data */ + long reserved; /* reserved for future use */ +}z_stream; + +#endif diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/interface.s b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/interface.s new file mode 100644 index 0000000..e1fce16 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/interface.s @@ -0,0 +1,105 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + .text + .file "llvm-link" + .p2align 4 // -- Begin function sub_0_caller_wrapper + .type sub_0_caller_wrapper,@function +sub_0_caller_wrapper: // @sub_0_caller_wrapper +// %bb.0: + and x8, x0, #0xffffffff + str q0, [sp, #-16]! + ldp x9, x10, [sp], #16 + add w11, w0, w1 + mov x0, x7 + stp x8, x11, [x6, #-16] + stp x9, x10, [x6, #-32] + ret +.Lfunc_end0: + .size sub_0_caller_wrapper, .Lfunc_end0-sub_0_caller_wrapper + // -- End function + .globl caller // --Begin function caller + .p2align 2 + .type caller,@function +caller: //@caller +// %bb.0: + stp x22, x21, [sp, #-32]! // 16-byte Folded Spill + stp x20, x19, [sp, #16] // 16-byte Folded Spill + mrs x8, TPIDR_EL0 + add x10, x8, :tprel_hi12:simulation_stack + mov w9, #8388480 + add x10,x10, :tprel_lo12_nc:simulation_stack + add x8, x8, :tprel_hi12:simulation_stack_pointer + add x9, x10, x9 + adrp x10, __unnamed_1 + add x8, x8, :tprel_lo12_nc:simulation_stack_pointer + add x10, x10, :lo12:__unnamed_1 + //APP + stur x30, [sp, #-16] + sub sp, sp, #16 // =16 + mov x21, x8 + mov x22, x9 + ldr x20, [x21] + sub x20, x22, x20 + mov x6, sp + str x6, [x20] + mov sp, x20 + ldr x19, [x10] + blr x19 + mov x20, sp + sub x20, x22, x20 + str x20, [x21] + ldr x19, [sp] + mov sp, x19 + ldr x30, [sp] + ldur x0, [sp, #-8] + ldur x1, [sp, #-16] + ldur q0, [sp, #-32] + add sp, sp, #16 //=16 + + //NO_APP + ldp x20, x19, [sp, #16] // 16-byte Folded Reload + ldp x22, x21, [sp], #32 // 16-byte Folded Reload + ret +.Lfunc_end1: + .size caller, .Lfunc_end1-caller + // -- End function + .type __unnamed_1,@object //@0 + .section .rodata, "a",@progbits + .p2align 3 +__unnamed_1: + .xword sub_0_caller_wrapper + .size __unnamed_1, 8 + + .type simulation_stack,@object // @simulation_stack + .section .tbss.simulation_stack,"aGwT",@nobits,simulation_stack,comdat + .globl simulation_stack + .p2align 4 +simulation_stack: + .zero 8388608 + .size simulation_stack, 8388608 + + .type simulation_stack_pointer,@object // @simulation_stack_pointer + .section .tbss.simulation_stack_pointer,"aGwT",@nobits,simulation_stack_pointer,comdat + .globl simulation_stack_pointer + .p2align 3 +simulation_stack_pointer: + .xword 0 // 0x0 + .size simulation_stack_pointer, 8 + + .ident "clang version 10.0.1" + .ident "clang version 10.0.1" + .section ".note.GNU-stack","",@progbits diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.c new file mode 100644 index 0000000..aca564e --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.c @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if defined __aarch64__ + #include "avx2neon.h" + //Suggestion: visit 'https://github.com/kunpengcomputer/AvxToNeon' and obtain the 'avx2neon.h' source code according to the README.md file. +#endif +#include +#include +#include "ksw.h" + + +__m256i add_epi(unsigned int data1, unsigned int data2) +{ + __m256i i2561 = _mm256_set1_epi32(data1); + __m256i i2562 = _mm256_set1_epi32(data2); + __m256i result256 = _mm256_sub_epi32(i2561, i2562); + return result256; +} + +__m256i max_epi(unsigned int data1, unsigned int data2) +{ + __m256i i2561 = _mm256_set1_epi32(data1); + __m256i i2562 = _mm256_set1_epi32(data2); + __m256i result256 = _mm256_max_epi32(i2561, i2562); + return result256; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.h b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.h new file mode 100644 index 0000000..eec3f80 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/code_migration/code_mod/ksw.h @@ -0,0 +1,28 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __DEMO_H_ +#define __DEMO_H_ +#if defined __x86_64__ + #include +#elif defined __aarch64__ + #include "avx2neon.h" +#endif + + +__m256i add_epi(unsigned int data1, unsigned int data2); +__m256i max_epi(unsigned int data1, unsigned int data2); + +#endif diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/Makefile new file mode 100644 index 0000000..c1c9686 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/Makefile @@ -0,0 +1,36 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +prog=func001 func002 func003 func004 +cleanfile=hello *.o *.out +CC=gcc +CFLAGS = -Wconversion -Wint-to-pointer-cast + +all:${prog} + +func001: func001.o + ${CC} ${CFLAGS} -o $@ func001.c + +func002: func002.o + ${CC} ${CFLAGS} -o $@ func002.c + +func003: func003.o + ${CC} ${CFLAGS} -o $@ func003.c + +func004: func004.o + ${CC} ${CFLAGS} -o $@ func004.c + +.PHONY: clean +clean: + rm -f ${cleanfile} ${prog} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func001.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func001.c new file mode 100644 index 0000000..2fce6b0 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func001.c @@ -0,0 +1,36 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +// -Wconversion +void func001(void) +{ + char c = 0; + int i = 10; + + int m = 20; + char a = m; + + c = c+i; +} + +int main(int argc, char *argv[]) +{ + func001(); + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func002.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func002.c new file mode 100644 index 0000000..1cb834d --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func002.c @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +// -Wsign-conversion + +void func002(void) +{ + char *c = NULL; + int *p = NULL; + + c = p; +} + +int main(int argc, char *argv[]) +{ + func002(); + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func003.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func003.c new file mode 100644 index 0000000..40e5529 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func003.c @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +// -Wpointer-sign +void func003(void) +{ + char *c = NULL; + unsigned char *s = c; +} + +int main(int argc, char *argv[]) +{ + func003(); + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func004.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func004.c new file mode 100644 index 0000000..f8cfcd6 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/precheck/func004.c @@ -0,0 +1,38 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +// -Wint-conversion +void func004(void) +{ + int test = 10; + char s[] = "hello"; + int a = 10; + int q = &a; /* 此处应有提示 */ + int p; + + p = &a; /* 此处应有提示 */ + + test = s; +} + +int main(int argc, char *argv[]) +{ + func004(); + + return 0; +} diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/Makefile new file mode 100644 index 0000000..b670bff --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/Makefile @@ -0,0 +1,15 @@ + # Copyright 2020 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +atomictest: atomic.o + g++ -o $@ atomic.o -lpthread \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/atomic.cpp b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/atomic.cpp new file mode 100644 index 0000000..31ab7ee --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic/atomic.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +using namespace std; + +int r1, r2; + +std::atomic x, y; + +void* thread0(void*) +{ + r2 = x.load(std::memory_order_acquire); // here + r1 = y.load(std::memory_order_acquire); // here + return nullptr; +} + +void* thread1(void*) +{ + y.fetch_add(1, std::memory_order_release); // here + x.fetch_xor(1, std::memory_order_relaxed); // here + return nullptr; +} + +int main() +{ + pthread_t t1, t2; + pthread_create(&t1, NULL, thread0, NULL); + pthread_create(&t2, NULL, thread1, NULL); + + pthread_join(t1, NULL); + pthread_join(t2, NULL); + + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/Makefile new file mode 100644 index 0000000..98805aa --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/Makefile @@ -0,0 +1,15 @@ + # Copyright 2020 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +commontest: common.o + gcc -o $@ common.o -lpthread \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/common.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/common.c new file mode 100644 index 0000000..10e2b70 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common/common.c @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +int x, y, r1, r2; + +void thread0() +{ + x = 1; + y = 1; // 扫描结果1 +} + +void thread1() +{ + r1 = y; + r2 = x; // 扫描结果2 +} + +int main() +{ + { + pthread_t t1, t2; + x = y = r1 = r2 = 0; + pthread_create(&t1, NULL, (void *)thread0, NULL); + pthread_create(&t2, NULL, (void *)thread1, NULL); + + pthread_join(t1, NULL); + pthread_join(t2, NULL); + + if (r1 == 1 && r2 == 0) { + printf("error\n"); + } + } + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/Makefile b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/Makefile new file mode 100644 index 0000000..32ccb45 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/Makefile @@ -0,0 +1,16 @@ + # Copyright 2020 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +locktest: lock.o + gcc -o $@ lock.o -lpthread \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/lock.c b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/lock.c new file mode 100644 index 0000000..ef4a3e3 --- /dev/null +++ b/examples/mpi/devkitdemo-main/Porting_advisor/testdemo/weak_consistency/lock/lock.c @@ -0,0 +1,56 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +int x, y, r1, r2; +pthread_mutex_t g_valLock; + +void thread0() +{ + pthread_mutex_lock(&g_valLock); + x = 1; + y = 1; // 锁保护,不会被扫描出 + pthread_mutex_unlock(&g_valLock); +} + +void thread1() +{ + pthread_mutex_lock(&g_valLock); + r1 = y; + r2 = x; // 锁保护,不会被扫描出 + pthread_mutex_unlock(&g_valLock); +} + +int main() +{ + { + pthread_t t1, t2; + x = y = r1 = r2 = 0; + pthread_mutex_init(&g_valLock, NULL); + pthread_create(&t1, NULL, (void *)thread0, NULL); + pthread_create(&t2, NULL, (void *)thread1, NULL); + + pthread_join(t1, NULL); + pthread_join(t2, NULL); + + if (r1 == 1 && r2 == 0) { + printf("error\n"); + } + } + return 0; +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/README.md b/examples/mpi/devkitdemo-main/README.md new file mode 100644 index 0000000..2ccdb1a --- /dev/null +++ b/examples/mpi/devkitdemo-main/README.md @@ -0,0 +1,2 @@ +# devkitdemo +The demo of DevKit. diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt new file mode 100644 index 0000000..fdd5acd --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(hmpi_demo C) + +# Add source files +set(SRC src/bcast_demo.c) + +# Set target file +set(TARGET_FILE bcast_demo) + +# Set Compiler +set(CMAKE_C_COMPILER mpicc) + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README.md new file mode 100644 index 0000000..dbb641e --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README.md @@ -0,0 +1,64 @@ +# **Hyper MPI broadcast functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [Hyper MPI](https://www.hikunpeng.com/developer/hpc/hypermpi) + 是整个高性能计算解决方案的关键组件,它实现了并行计算的网络通讯功能,可以用来支持制造、气象、超算中心等应用场景,同时该通信库也可扩展应用于AI、大数据等通用领域。Message Passing + Interface(MPI)是支持多编程语言编程的并行计算通讯应用接口,具有高性能、大规模性、可移植性、可扩展性等特点。 +2. [Hyper MPI](https://www.hikunpeng.com/developer/hpc/hypermpi) 是基于Open MPI 4.1.1和Open UCX + 1.10.1,支持MPI-V3.1标准的并行计算API接口,新增了优化的集合通信框架。同时,Hyper MPI对数据密集型和高性能计算提供了网络加速能力,使能了节点间高速通信网络和节点内共享内存机制,以及优化的集合通信算法。Hyper + MPI的COLL UCX通信框架能够支持的最大数据包长度为2^32字节。 +3. **Hyper MPI broadcast functions demo** 用于展示对MPI_Bcast集合通信的优化。 + +## 使用依赖 + +1. 确保已安装 **Hyper MPI 1.1.1** +2. 确保已安装 **HMPI** 对应版本的编译器:**GCC 9.3.0** 或 **BiSheng 2.1.0** + +## 使用教程 + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/hmpi/bcast/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + # 使用普通用户执行 + mpirun -n 4 bcast_demo + # 使用普通用户执行,并屏蔽掉coll ucx + mpirun -n 4 -mca coll ^ucx bcast_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` + +## 命令参考链接 + +1. [Non-coll模式](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0014.html) +2. [Coll模式](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0015.html) +3. [集合操作算法选择说明](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0016.html) +4. [命令说明及示例](https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hypermpi/userg_huaweimpi_0031.html) diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README_en.md new file mode 100644 index 0000000..78c0567 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/README_en.md @@ -0,0 +1,68 @@ +# **Hyper MPI broadcast functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [Hyper MPI](https://www.hikunpeng.com/en/developer/hpc/hypermpi) is key to the HPC solution. It implements network + communication for parallel computing and is applicable to manufacturing, meteorology, supercomputing, AI, and big + data. Message Passing Interface (MPI) supports multi-language programming, featuring high performance, large scale, + portability, and scalability. +2. [Hyper MPI](https://www.hikunpeng.com/en/developer/hpc/hypermpi) based on Open MPI 4.1.1 and Open UCX 1.10.1, Hyper + MPI supports the parallel computing API interface of the MPI-V3.1 standard, and optimizes the collection + communication framework. In addition, Hyper MPI accelerates the network for data-intensive and high-performance + computing, and enables a high-speed communication network and shared memory mechanism between nodes, and an optimized + collection communication algorithm. The maximum data packet length supported by the COLL UCX communication framework + of Hyper MPI is 232 bytes. +3. The **Hyper MPI broadcast functions demo** shows a code example of MPI_Bcast. + +## Dependencies + +1. Ensure that **Hyper MPI 1.1.1** has been installed. +2. Ensure that **GCC 9.3.0** or **BiSheng 2.1.0** has been installed. + +## Guidance + +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/hmpi/bcast/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + # Non-root user run demo. + mpirun -n 4 bcast_demo + # non-root user run demo with non-coll mode. + mpirun -n 4 -mca coll ^ucx bcast_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` + +## Command Reference Link + +1. [Non-coll Mode](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0014.html) +2. [Coll Mode](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0015.html) +3. [Algorithm Selection for Set Operations](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0016.html) +4. [Command Description and Example](https://support.huaweicloud.com/intl/en-us/usermanual-kunpenghpcs/userg_huaweimpi_0031.html) \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo new file mode 100644 index 0000000000000000000000000000000000000000..6875cc7822317160dd8ebd0c3a87fe0d38b91119 GIT binary patch literal 71856 zcmeI1eQ;dWb->T=O0q1;mgFx9jHMNJf-ra`8)M7R#;cWWS;Sv8VsIyIpPzQ0q%Hd) z-mXB#bSej?^$hKd6dQ0l;5dYtAeGLL!Ayq^(*g-oGGQ_$6hm7+jQFS%N&~hqR`Gg! z&VBbtZ@=7hnC73J2Y1gs=bm#ve)mJ~UH|FU9oxJf5AfrKzXj69<_DF@`2}dNpYsVq z2h4{cG{Fj}K(8`P>=)EImKSsw%S!a6$A^jHI=rNj43e0Y%asPel3OQPuFD(|)S4q- zu6I&=)%Am@y>~+k*lH-047%QMy}G?pTt;;NS@Jxz z#iD&}vB;WOG%-A~#x(8l;D+^qR5GyE88_8WzTLZSQ(dC@o<)m!nx@671YnVt)c=K; zYP3#GS7EBgRI67JUZL%Hwf6RA7b0?AM@^-|eXL51=gOPb~b}$1OILuz!s9V)bN8*#D%2 z{SQmnpD1BZm9RIK;P6oi|IbR;FO;x9gZ6r8gi#1#4j*Ug;3#I5-J5F%T*q-*w;RCd z>D_5WEZZ80rqY((yR$2nOjx~UU(5o-7>FkmMk;OEX~S?_i#k$uLs6=5eLL*j(_@6f zW-9IEOxuoHw#wh0j>avO>q^GshHWP9P+CtSnua9SU{DHE+1*Jy7Ey)Uq6sq=y~mn! zh$hlB01UtuDL0fJv@J72?YEO2c7`@IoKAt+m$cI`WMfc2#I1PBN<-X?#gbth9{K9w z#m#5}`fbaC?j1d$E@NF_?M7(BZrqU?GQ(Ee&~RTY8g5G^`_p%uw$+9`Z5yPYwE_IE ztuLAyv=Rdt6=-jxq0mv`o(eT7dRlbe%hQDW&I50umCvV##~;FN=!F%yZs_@^Y^RbQ zJOJGL|4o;j_cl46cG;c%titEk2iD_08%BA3pgnirIP1oXcHI?KQKepIWS<)o^?%Oa z-Ooms9Ybaxzsv4ECtF>1{@X%9?Jm3f{OWMo>Fneu=(5up!q0Y>ozGn=+vBp+naj^U zmz~aPe)hZUd{$H0pv%s4O7_gbf0)SlV0<6I(agaYo_OA8oFe+H>b#)JlwN`Q)h@jX^^i+nhw zZ$f>_rC*J@*E84t*HORPrLRUkzi7hrp${hC^95(7 zR>Js4$O%{SF94oD3za9%LgLU_AL>5TeW?51KXkSX^)l4UP%k@o=5rgJ{;KPU|Hp+{Z03(vSpKhgz^xkqZM#x<+b~pS}tXK zr+0TvoWDJU?c+GU3{Jp`Cw85gx8)-Bo!Ys8W6E~2)}y2|)3SI&=T z4pvQk{wjyC6hOzr1+&+{tS-KgLTljrhH5Fn3hbQxNrHzZtZ_9${jj? z`Z~yb4f9lgvAEOMKxUKnU5@e_I)8d4WEwDk6Q-hZ&5*fH`z}D)uJfmtLuNkaug6q0 zt^qPDv~TuO_Tj5JZZTxOM7^n0TrFg3weM%>w}j)WA@d39b*19wLB^wf-$%a+ov*&? z#IAQy_m+sO!SZuhPV?|O$_qNb0PU}0ei~D;@h!yi54G<CE>51mxvoCvLJ*^SaUsC1GtMTvY65eyK zppEw2^zI$FW@*3PGV#lmJ-C*)`@$rIbKU#L&*STOt=MnGrciw&t zE5nD{7{v4(`tduKyIs${PP^15rDI&*zM2(v$GwkI47If$)00^CI7+~>jw9ZqWe-+7 zRQYh#@tQ{$mT$*O$>$F+wc^+xrx(3Q&5CyAS9!eZ(VFt@3(I@z%5Paz{>>%jJC>F2 zY%Je(W%=%_R9p=*IhJvl;#h)@Rvw>6V>w#>VA=MEd=Gn%dA1#?xaGAi@4WrysW<-l zbs8OwV++Qe#yB1un&c4zLO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$qb0zyCt2mv7=1cZPP5CTF#2nYcoAOwVf z5D)@FKnMr{As_^VfDjM@LO=)z0U;m+gn$tEe@5U~RZxw1P)m;tY2UbhQ~1VB>(;Mp@9_7Nuh|!?hxg&*dOu#yhkc9ra2tPd znYOr%Cv{s2#ASYb2(H5$Eb#Dw7kZ1@eK1ngUN(CkxGVEPIq*4AlF_EJZHJ~8sL4CYhN(Co^tIAf#)jMUJJ$8`*4*u)& z?~3DJxK12<;k=Jsw%uyrear1~J-k=h{`1S$vj8sWbBO)_1vAwDeEYv?duvsYU6pjW zHNZ&TJpQNl=l2y3D#Ho$(7fw;wKH4r_k>B z*TemJ`^B-(^^@zju%2S;%|<&wEj*QXM&7OLSK#{3eePBEdN`BU?jdDg0FUHx{xh@} zYnRtyV_v&Fu95m+PQ#_v1N;9Z&;L8vt_RPPd^=TItUo7I{|nEhr&T?L=f+Q!|DuBP z=U=rw|GfG{)l+ybIUEYl+wd>Z z=4897e@^FI4f%Tu_xonF*SpU{)altl{!TXM_cpZqb1aT>r>bY}9OM3vmhk^8wAU5k z@I$l{hgbAEd|bEnBV{ja_{XZA!t?x9wAXtZ3eNerwLSmb_?50F|C~RIcIpqW^HJRe zFTU90YAg7=un_IVxV4n9x9NKF{~q03!r!O;^ZU8Ag#YWf4vY13FZ!!__lBGi;W+8( zFHz4>3HzZE_V1vb<~M&_-!0+)q_Qu7q3WRO$K$Be^CNBNbE(}i!$q1GZ{gpymrB$R zZNn+MEf(!-8wiKnOw$ezZdku27EKI~tQklQx2c!>wm@L+fArn3zAbF0*9MZXDgvuU zzCs;QtRrm3V#eK;d56)T_zG1es46?1N)Pw<2f`4sY-=EzN?W#(jvL`vGGV2_Fd|7~ zAeQViV@4#Mv{QyTJOW|-W{Fv8D-zhav7^1XlhGedL=Drn%>#y&NZSXX-!|ix5gCrh z4`7H(Gte`gxx?7KZQHF|dyU@C(2lL-nA2<|*N{q^b{dQ=zrU+< zXHOUG+|y%(a4=EJMn9axmkFTRMHqU6A@|{=Pja$&W@Lep`F5=vN$fqWH_gGLWLi- zalO_;IhJ=Po&Tvl=8?xY=yD2LnA(YS@H#UNrWwsSFDM06jVrd8{tbw#Of_d6D zSe8^{3Rr`BqYOqcmNh5B*)dK8=dofl9t~rwNvsQh0;&P0GMqLD5M0E>^yrC%F<6-Bocse{c6{gCEP>55FI< z?MBSd-5baAcln4m9Mg_`KSy^8^l&|EF@GNKwm6>e^Xl~9kyhpHv_V;p*JijGGu4~)pZ!?w!*aU&W1a68#&o=2$LIH7n_&Pm#FFFr9^xq-KcXGE{rvIYspCW1kMAp5 z^#vy1cT)T^O!@H#(MC*kbF=pvBifO_XVFDHJnyXEg&B7|-+zp8LwUf}JsZZbJd_`= zzfZ^X1#1m=OgG5YY8C!GFP`sH9;tOaxE=P-@Bd%wc;?UdE>G(C7zb*ZAOB!pJm1eW z>V|v&hxi}l#q&MRkdEJ%$1i{Ue}nN0G3o6xd*5?7<20P_&pOLz(T#@6@q8~d_8Z2( zgt0V59MAVh$87tzDh$nEmH(Dx|~k>mNE>E$d%0r=JL+z-dId<~1-@q8b3M#mqX z3spIeV@dxW;*RHgt085bTc=zN$FV+z8M1Nz`MrBo$5-YpnEd#E$5?8=9h3Xvc-r6Y zhkWT_`6=f0R#$fZKAF}Yes)x)bLX~Jl^3slwvlY~I)NSfA71F+bGk8c|M~o-ZOUWE f?Ci6r#)*G3uQ0DW_$^dCzO~NrtjG(FbQiv literal 0 HcmV?d00001 diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c new file mode 100644 index 0000000..c1a78a9 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/hmpi/bcast/src/bcast_demo.c @@ -0,0 +1,92 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: KML blas library demo + * Refrence: www.mpitutorial.com + * Create: 2022-05-17 + */ +#include +#include +#include +#include + +int InputParameterParse(int argc, char** argv) +{ + if (argc == 1) + { + return 0; + } + // Parameter must be 1 + printf("Invalid parameter.\n"); + return -1; +} + +double BcastData(int trialsNum, int elementsNum, int* sendData) +{ + if (trialsNum == 0) + { + return 0; + } + double totalMPIBcastTime = 0.0; + + int i; + for (i = 0; i < trialsNum; i++) + { + // An MPI barrier completes after all group members have entered the barrier. + MPI_Barrier(MPI_COMM_WORLD); + // MPI_Wtime returns a floating-point number of seconds, representing elapsed wall-clock time since some time in the past. + totalMPIBcastTime -= MPI_Wtime(); + // MPI_Bcast broadcasts a message from the process with rank root to all processes of the group, itself included. + MPI_Bcast(sendData, elementsNum, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); + totalMPIBcastTime += MPI_Wtime(); + } + return totalMPIBcastTime; +} + +int main(int argc, char** argv) +{ + if (InputParameterParse(argc, argv) != 0) + { + return -1; + } + // Send data numbers. + int elementsNum = 10000; + int trialsNum = 10; + int rankNum; + int sizeOfInt = sizeof(int); + double totalMPIBcastTime = 0.0; + int* sendData = (int*)malloc(sizeof(int) * elementsNum); + if (sendData == NULL) + { + printf("Out of memory.\n"); + return -1; + } + memset(sendData, 0, elementsNum); + + // Init. + MPI_Init(NULL, NULL); + // This function gives the rank of the process in the particular communicator’s group. + MPI_Comm_rank(MPI_COMM_WORLD, &rankNum); + + totalMPIBcastTime = BcastData(trialsNum, elementsNum, sendData); + + if (rankNum == 0) + { + printf("Data size = %d, Trials = %d\n", elementsNum * sizeOfInt, trialsNum); + printf("Average of MPI_Bcast time = %lf seconds\n", totalMPIBcastTime / trialsNum); + } + free(sendData); + MPI_Finalize(); +} \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/CMakeLists.txt b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/CMakeLists.txt new file mode 100644 index 0000000..2a81ba6 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_blas_demo C) + +# Add source files +set(SRC src/blas_demo.c) + +# Set target file +set(TARGET_FILE blas_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Add link library +link_directories(${KML_PATH}/lib/kblas/nolocking) + +# Find link library +find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/nolocking) + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KBLAS}) + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README.md new file mode 100644 index 0000000..43d4441 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README.md @@ -0,0 +1,60 @@ +# **KML_BLAS library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. BLAS(Basic Linear Algebra + Subprograms)提供了一系列基本线性代数运算函数的标准接口,包括矢量线性组合、矩阵乘以矢量、矩阵乘以矩阵等功能。BLAS已被广泛的应用于工业界和科学计算,成为业界标准。[KML_BLAS](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0012.html) + 库提供BLAS函数的C语言接口。 +2. **KML_BLAS library functions demo** 展示使用KML_BLAS库函数的代码示例,演示矩阵乘法、对称矩阵乘法、更新对称矩阵轶等函数的使用流程。 + +## 使用依赖 + +1. 确保已安装 **boostkit-kml-1.4.0** +2. 确保环境变量正常加载,执行 **env | grep LD_LIBRARY_PATH** +3. 确保已安装编译器版本 >= **GCC 7.3.0** + +## 使用教程 + +KML_BLAS有多个版本: +- 单线程不加锁版本:/usr/local/kml/lib/kblas/nolocking/libkblas.so +- 单线程加锁版本:/usr/local/kml/lib/kblas/locking/libkblas.so +- pthread实现多线程版本:/usr/local/kml/lib/kblas/pthread/libkblas.so +- OpenMP实现多线程版本:/usr/local/kml/lib/kblas/omp/libkblas.so + +**Demo中使用单线程不加锁版本** + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/blas/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + ./blas_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README_en.md new file mode 100644 index 0000000..b45b5dc --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/README_en.md @@ -0,0 +1,61 @@ +# **KML_BLAS library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. Basic Linear Algebra Subprograms (BLAS) provides a series of standard interfaces for basic linear algebra operation + functions, including vector linear combination, matrix multiplied by vector, and matrix multiplied by matrix. BLAS + has been widely used in industry and scientific computing, and has become an industry standard. + The [KML_BLAS](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0012.html) + library provides the C language interface for BLAS functions. +2. The **KML_BLAS library functions demo** shows a code example for KML_BLAS library functions, demonstrates the use process of matrix multiplication, symmetric matrix multiplication, update the rank of sysmmetric matrix, etc functions. + +## Dependencies + +1. Ensure that boostkit-kml-1.4.0 has been installed. +2. Run the **env | grep LD_LIBRARY_PATH** command to ensure that the environment variable loaded. +3. Ensure that compiler version >= **GCC 7.3.0** has been installed. + +## Guidance + +There are multiple versions of KML_BLAS: +- Single-thread version without locking: /usr/local/kml/lib/kblas/nolocking/libkblas.so +- Single-thread version with locking: /usr/local/kml/lib/kblas/locking/libkblas.so +- Multi-thread version using pthread: /usr/local/kml/lib/kblas/pthread/libkblas.so +- Multi-thread version using OpenMP: /usr/local/kml/lib/kblas/omp/libkblas.so + +**Single-thread version without locking is used by demo.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/blas/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + ./blas_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/src/blas_demo.c b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/src/blas_demo.c new file mode 100644 index 0000000..c4ad50d --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/blas/src/blas_demo.c @@ -0,0 +1,111 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_BLAS library functions demo demonstrates the use process of matrix multiplication, + * symmetric matrix multiplication, update the rank of sysmmetric matrix, etc functions. + * Create: 2022-05-15 + */ + +#include +#include +#include + +#include + +void PrintMatrix(int row, int column, const float* matrix) +{ + int i; + for (i = 0; i < row; i++) + { + int j; + for (j = 0; j < column; j++) + { + printf("%-12.6f", matrix[j * column + i]); + } + printf("\n"); + } + printf("\n"); +} + +int main() +{ + // Rows of matrices of op(A) and C + int m = 3; + // Columns of matrices of op(B) and C + int n = 3; + // Columns of the matrix op(A) and rows of the matrix op(B) + int k = 3; + // If the matrix is column store and TransA = CblasNoTrans, lda is at least max(1, m); otherwise, lda is at least max(1, k). + // If A is row-store matrix and TransA = CblasNoTrans, lda is at least max(1, k); otherwise, lda is at least max(1, m). + int lda = 3, ldb = 3, ldc = 3; + // Multiplication coefficient + float alpha = 1.0F, beta = 1.0F; + + float a[9] = { 1.0F, 0, 0, + 0, 1.0F, 0, + 0, 0, 1.0F }; + printf("Input matrix A(3*3):\n"); + PrintMatrix(3, 3, a); + + float b[9] = { 0, 0, 2.0F, + 0, 2.0F, 0, + 2.0F, 0, 0 }; + printf("Input matrix B(3*3):\n"); + PrintMatrix(3, 3, b); + + float c[9] = { 3.0F, 0, 4.0F, + 0, 0, 0, + 4.0F, 0, 3.0F }; + printf("Input matrix C(3*3):\n"); + PrintMatrix(3, 3, c); + + float d[9]; + memcpy(d, c, sizeof(d)); + + /* + * Multiply one matrix by another. + * C = alpha * op(A) * op(B) + beta * C + * The value of op(X) may be op(X) = X, op(X) = X', op(X) = conjg(X') + * alpha and beta are multiplication coefficient. + * op(A) is an m*k matrix, op(B) is a k*n matrix, C is an m*n matrix. + */ + cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc); + printf("cblas_sgemm --> Output matrix C(3*3):\n"); + PrintMatrix(m, n, c); + + /* + * Compute the product of matrices in which matrix A is symmetric. + * C = alpha * A * B + beta * C or C = alpha * B * A + beta * C + * alpha and beta are multiplication coefficient. + * A is a symmetric matrix, B and C are m*n general matrices. + */ + cblas_ssymm(CblasColMajor, CblasLeft, CblasLower, m, n, alpha, a, lda, b, ldb, beta, c, ldc); + printf("cblas_ssymm --> Output matrix C(3*3):\n"); + PrintMatrix(m, n, c); + + /* + * Perform a rank-k matrix-matrix operation for a symmetric matrix. + * C = alpha * A * A' + beta * C or C = alpha * A' * A + beta * C + * alpha and beta are multiplication coefficient. + * C is an n*n symmetric matrix. + * In the first case, A is an n*k matrix. + * In the second case, A is a k*n general matrix. + */ + cblas_ssyrk(CblasColMajor, CblasUpper, CblasNoTrans, n, k, alpha, c, lda, beta, d, ldc); + printf("cblas_ssyrk --> Output matrix C(3*3):\n"); + PrintMatrix(m, n, c); + + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/CMakeLists.txt b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/CMakeLists.txt new file mode 100644 index 0000000..0175d85 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_fft_demo C) + +# Add source files +set(SRC src/fft_demo.c) + +# Set target file +set(TARGET_FILE fft_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Add link library +link_directories(${KML_PATH}/lib) + +# Find link library +find_library(KFFT kfft HINTS ${KML_PATH}/lib) + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KFFT}) + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README.md new file mode 100644 index 0000000..1eb55eb --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README.md @@ -0,0 +1,56 @@ +# **KML_FFT library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_FFT](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0122.html) + 是一个快速傅里叶变换(FFT)的数学库。 +2. **KML_FFT library functions demo** 展示使用KML_FFT库函数的代码示例,演示C2C变换等函数的使用流程。 + +## 使用依赖 + +1. 确保已安装 **boostkit-kml-1.4.0** +2. 确保环境变量正常加载,执行 **env | grep LD_LIBRARY_PATH** +3. 确保已安装编译器版本 >= **GCC 7.3.0** + +## 使用教程 + +KML_FFT有多个版本: +- 单精度版本:/usr/local/kml/lib/libkfft.so +- 双精度版本:/usr/local/kml/lib/libkfftf.so + +**Demo中使用单精度版本** +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/fft/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + ./fft_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README_en.md new file mode 100644 index 0000000..532c33f --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/README_en.md @@ -0,0 +1,56 @@ +# **KML_FFT library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [KML_FFT](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0122.html) + is a math library of fast Fourier transform (FFT). +2. The **KML_FFT library functions demo** shows a code example for KML_FFT library functions, demonstrates the use process of C2C transforms, etc functions. + +## Dependencies + +1. Ensure that boostkit-kml-1.4.0 has been installed. +2. Run the **env | grep LD_LIBRARY_PATH** command to ensure that the environment variable loaded. +3. Ensure that compiler version >= **GCC 7.3.0** has been installed. + +## Guidance + +There are multiple versions of KML_FFT: +- Single-precision version: /usr/local/kml/lib/libkfft.so +- Double-precision version: -L /usr/local/kml/lib/libkfftf.so + +**Single-precision version is used by demo.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/fft/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + ./fft_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/src/fft_demo.c b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/src/fft_demo.c new file mode 100644 index 0000000..2340db2 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/fft/src/fft_demo.c @@ -0,0 +1,112 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_FFT library functions demo demonstrates the use process of C2C transforms, etc functions. + * Create: 2022-05-15 + */ + +#include +#include + +#include + +void PrintComplex(kml_fft_complex* complex, const int length) +{ + printf("{\n"); + int i; + for (i = 0; i < length; i++) + { + printf(" {%.6f, ", complex[i].r); + printf("%.6f}", complex[i].i); + if (i != length - 1) + { + printf(","); + } + printf("\n"); + } + printf("}\n"); +} + +int main() +{ + // Dimension of FFT. The constraint is 1 ≤ rank ≤ 3. + int rank = 2; + // Indicates an array whose dimension is rank, including the size of each dimension in the FFT sequence. + // The constraint is n[i] ≥ 1, for i in 0 to rank - 1. + int* n; + n = (int*)kml_fft_malloc(sizeof(int) * rank); + n[0] = 2; + n[1] = 3; + double init[6][2] = {{ 120, 0 }, { 8, 8 }, { 0, 0 }, { 0, 16 }, { 0, 16 }, { -8, 8 }}; + + kml_fft_complex* in; + in = (kml_fft_complex*)kml_fft_malloc(sizeof(kml_fft_complex) * n[0] * n[1]); + int i; + for (i = 0; i < n[0] * n[1]; i++) + { + in[i].r = init[i][0]; + in[i].i = init[i][1]; + } + + printf("Input complex:\n"); + PrintComplex(in, n[0] * n[1]); + + kml_fft_complex* out; + out = (kml_fft_complex*)kml_fft_malloc(sizeof(kml_fft_complex) * n[0] * n[1]); + kml_fft_plan plan; + + /* + * Create a plan for the n-dimensional complex-to-complex (C2C) transform of a single contiguous data sequence. + */ + plan = kml_fft_plan_dft(rank, n, in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + kml_fft_execute_dft(plan, in, out); + + printf("kml_fft_plan_dft --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + /* + * Create a plan for the one-dimensional C2C transform of a single contiguous data sequence. + */ + plan = kml_fft_plan_dft_1d(n[0], in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + kml_fft_execute_dft(plan, in, out); + + printf("kml_fft_plan_dft_1d --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + /* + * Create a plan for the two-dimensional C2C transform of a single contiguous data sequence. + */ + plan = kml_fft_plan_dft_2d(n[0], n[1], in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + kml_fft_execute_dft(plan, in, out); + + printf("kml_fft_plan_dft_2d --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + /* + * Create a plan for the there-dimensional C2C transform of a single contiguous data sequence. + */ + plan = kml_fft_plan_dft_3d(n[0], n[1], 1, in, out, KML_FFT_FORWARD, KML_FFT_ESTIMATE); + kml_fft_execute_dft(plan, in, out); + + printf("kml_fft_plan_dft_3d --> OutPut complex:\n"); + PrintComplex(out, n[0] * n[1]); + + kml_fft_destroy_plan(plan); + kml_fft_free(n); + kml_fft_free(in); + kml_fft_free(out); + + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/CMakeLists.txt b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/CMakeLists.txt new file mode 100644 index 0000000..8395aa6 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_lapack_demo C) + +# Add source files +set(SRC src/lapack_demo.c) + +# Set target file +set(TARGET_FILE lapack_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Add link library +find_library(KLAPACK klapack HINTS ${KML_PATH}/lib) +find_library(KSERVICE kservice HINTS ${KML_PATH}/lib) +find_library(LAPACK_ADAPT liblapack_adapt.a HINTS ${KML_PATH}/lib) +find_library(KBLAS kblas HINTS ${KML_PATH}/lib/kblas/omp) + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KLAPACK} ${LAPACK_ADAPT} ${KBLAS} gfortran m ${KSERVICE}) + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README.md new file mode 100644 index 0000000..568231b --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README.md @@ -0,0 +1,52 @@ +# **KML_LAPACK library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_LAPACK](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0203.html) + 通过分块、求解算法组合、多线程、BLAS接口优化等手段,基于鲲鹏架构对线性代数运算库(Linear Algebra PACKage)的计算效率进行了优化。 +2. **KML_LAPACK library functions demo** 展示使用KML_LAPACK库函数的代码示例,演示矩阵分解、矩阵求逆等函数的使用流程。 + +## 使用依赖 + +1. 确保已安装 **boostkit-kml-1.4.0** +2. 确保已从 **lapack3.9.1** 生成 **lapack_adapt.a** +3. 确保环境变量正常加载,执行 **env | grep LD_LIBRARY_PATH** +4. 确保已安装编译器版本 >= **GCC 7.3.0** + +## 使用教程 + +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/lapack/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + ./lapack_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README_en.md new file mode 100644 index 0000000..bdc82ee --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/README_en.md @@ -0,0 +1,53 @@ +# **KML_LAPACK library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [KML_LAPACK](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0203.html) + optimizes the Linear Algebra PACKage (LAPACK) computing efficiency based on the Kunpeng architecture by means of + block division, algorithm combination, multi-thread, and BLAS interface optimization. +2. The **KML_LAPACK library functions demo** shows a code example for KML_LAPACK library functions, demonstrates the use process of matrix factorization, matrix inversion, etc functions. + +## Dependencies + +1. Ensure that boostkit-kml-1.4.0 has been installed. +2. Ensure that lapack_adapt.a has been generated from lapack3.9.1. +3. Run the **env | grep LD_LIBRARY_PATH** command to ensure that the environment variable loaded. +4. Ensure that compiler version >= **GCC 7.3.0** has been installed. + +## Guidance + +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/lapack/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + ./lapack_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/src/lapack_demo.c b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/src/lapack_demo.c new file mode 100644 index 0000000..ccf7fa7 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/lapack/src/lapack_demo.c @@ -0,0 +1,152 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_LAPACK library functions demo demonstrates the use process of matrix factorization, + * matrix inversion, etc functions + * Create: 2022-05-15 + */ + +#include +#include + +#include + +void PrintArray(const double* array, const int row, const int column) +{ + int i; + for (i = 0; i < row; i++) + { + int j; + for (j = 0; j < column; j++) + { + printf("%-12.6f", array[j * column + i]); + } + printf("\n"); + } + printf("\n"); +} + +int TestDgetrf(double* a, int* ipiv, const int m, const int n, const int lda) +{ + int info = 0; + /* + * Compute the LU factorization of matrix A. This function uses partial pivoting, allowing row interchanges. + * The operation is defined as A = PLU, where P is a permutation matrix, L is a lower triangular matrix or + * a lower echelon matrix and the diagonal is 1, and U is an upper triangular matrix or an upper echelon matrix. + */ + dgetrf_(&m, &n, a, &lda, ipiv, &info); + if (info != 0) + { + if (info > 0) + { + printf("Error: The value of the -%d-th parameter is invalid.", info); + } + else + { + printf("Error: The %d-th element on the diagonal of matrix U is 0. " + "The matrix factorization is complete, but U is singular. As a result, " + "an error of dividing by zero occurs when a system of linear equations is solved.", info); + } + } + return info; +} + +int TestDgetri(double* a, const int* ipiv, const int n, const int lda) +{ + /* + * Compute the inverse matrix based on the LU factorization result obtained using ?getrf. + */ + int info = 0; + // Temporary storage space. After lwork=-1 is called, work[0] is the optimal lwork value. + double* work = NULL; + double qwork; + // Length of the work array + int lwork = -1; + /* Query optimal work size */ + dgetri_(&n, a, &lda, ipiv, &qwork, &lwork, &info); + if (info != 0) + { + if (info > 0) + { + printf("Error: The value of the -%d-th parameter is invalid.", info); + } + else + { + printf("Error: The %d-th element on the diagonal of U is 0, and the matrix cannot be inverted.", info); + } + return info; + } + lwork = (int)qwork; + work = (double*)malloc(sizeof(double) * lwork); + /* Calculate inversion */ + dgetri_(&n, a, &lda, ipiv, work, &lwork, &info); + free(work); + if (info != 0) + { + if (info > 0) + { + printf("Error: The value of the -%d-th parameter is invalid.", info); + } + else + { + printf("Error: The %d-th element on the diagonal of U is 0, and the matrix cannot be inverted.", info); + } + return info; + } + return info; +} + +int main() +{ + // Number of rows in matrix A + int m = 4; + // Number of columns in matrix A + int n = 4; + // Leading dimension of the matrix A. lda >= max(1, n). + int lda = 4; + // An array containing pivot indices obtained from ?getrf. Its length is min(m, n). + // For 1 <= ipiv <= min(m, n), row i and row ipiv[i-1] of the matrix are interchanged during factorization. + int ipiv[4]; + + /* + * A (stored in column-major): + * 1.80 2.88 2.05 -0.89 + * 5.25 -2.95 -0.95 -3.08 + * 1.58 -2.69 -2.90 -1.04 + * -1.11 -0.66 -0.59 0.80 + */ + double a[16] = { 1.80, 5.25, 1.58, -1.11, + 2.88, -2.95, -2.69, -0.66, + 2.05, -0.95, -2.90, -0.59, + -0.89, -3.80, -1.04, 0.80 }; + printf("Input matrix A(4*4):\n"); + PrintArray(a, m, n); + + if (TestDgetrf(a, ipiv, m, n, lda) != 0) + { + return EXIT_FAILURE; + } + + printf("dgetrf --> Matrix A:\n"); + PrintArray(a, m, n); + + if (TestDgetri(a, ipiv, n, lda) == 0) + { + printf("dgetri --> Matrix A:\n"); + PrintArray(a, m, n); + } + + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/CMakeLists.txt b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/CMakeLists.txt new file mode 100644 index 0000000..bcdf976 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/CMakeLists.txt @@ -0,0 +1,43 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_math_demo C) + +# Add source files +set(SRC src/math_demo.c) + +# Set target file +set(TARGET_FILE math_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Add link library +link_directories(${KML_PATH}/lib) + +# Find link library +find_library(MATH m HINTS ${KML_PATH}/lib) +find_library(KMATH km HINTS ${KML_PATH}/lib) + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${MATH} ${KMATH}) + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README.md new file mode 100644 index 0000000..81a5966 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README.md @@ -0,0 +1,56 @@ +# **KML_MATH library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_MATH](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0111.html) + 是C语言实现的基本数学函数库。 +2. **KML_MATH library functions demo** 展示使用KML_MATH库函数的代码示例,演示三角函数的使用流程。 + +## 使用依赖 + +1. 确保已安装 **boostkit-kml-1.4.0** +2. 确保环境变量正常加载,执行 **env | grep LD_LIBRARY_PATH** +3. 确保已安装编译器版本 >= **GCC 7.3.0** + +## 使用教程 + +KML_MATH有多个版本: +- 高性能版本:/usr/local/kml/lib/libkm.so +- 高精度版本:/usr/local/kml/lib/libkm_l9.so + +**Demo使用高性能版本** +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/math/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. 运行demo + + ```shell + ./math_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README_en.md new file mode 100644 index 0000000..b8bad51 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/README_en.md @@ -0,0 +1,56 @@ +# **KML_MATH library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. [KML_MATH](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0111.html) + is a basic math function library implemented by the C language. +2. The **KML_MATH library functions demo** shows a code example for KML_MATH library functions, demonstrates the use process of trigonometric functions. + +## Dependencies + +1. Ensure that boostkit-kml-1.4.0 has been installed. +2. Run the **env | grep LD_LIBRARY_PATH** command to ensure that the environment variable loaded. +3. Ensure that compiler version >= **GCC 7.3.0** has been installed. + +## Guidance + +There are multiple versions of KML_MATH: +- High-performance version: /usr/local/kml/lib/libkm.so +- High-precision version: /usr/local/kml/lib/libkm_l9.so + +**High-performance version is used by demo.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/math/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + ./math_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/src/math_demo.c b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/src/math_demo.c new file mode 100644 index 0000000..45ca0af --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/math/src/math_demo.c @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_MATH library functions demo demonstrates the use process of trigonometric functions. + * Create: 2022-05-15 + */ + +#include +#include +#include + +#include + +int main() +{ + double sinx, cosx; + sincos(M_PI_4, &sinx, &cosx); + printf("Input:\npi/4 = %.14f\n\n", M_PI_4); + printf("Output:\nsincos { sin(pi/4) = %.14f, cos(pi/4) = %.14f }\n\n", sinx, cosx); + printf("Output:\nasin(sin(pi/4)) = %.14f\n\n", asin(sinx)); + printf("Output:\nacos(cos(pi/4)) = %.14f\n\n", acos(cosx)); + return EXIT_SUCCESS; +} + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/CMakeLists.txt b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/CMakeLists.txt new file mode 100644 index 0000000..cd919ba --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8) +project(kml_spblas_demo C) + +# Add source files +set(SRC src/spblas_demo.c) + +# Set target file +set(TARGET_FILE spblas_demo) + +# Set KML path +set(KML_PATH /usr/local/kml) + +# Add header file include directories +include_directories(${KML_PATH}/include) + +# Add link library +link_directories(${KML_PATH}/lib/kspblas/single) + +# Find link library +find_library(KSPBLAS kspblas HINTS ${KML_PATH}/lib/kspblas/single) + +# Add openmp option +add_compile_options(-fopenmp) + +# Generate execute file +add_executable(${TARGET_FILE} ${SRC}) +target_link_libraries(${TARGET_FILE} ${KSPBLAS}) + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README.md new file mode 100644 index 0000000..12a5aa4 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README.md @@ -0,0 +1,56 @@ +# **KML_SPBLAS library functions demo** + +简体中文 | [English](README_en.md) + +## 介绍 + +1. [KML_SPBLAS](https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0067.html) + 库是稀疏矩阵(Sparse Matrix)的基础代数运算库,稀疏矩阵是指大部分矩阵元素为零的矩阵。 +2. **KML_SPBLAS library functions demo** 展示使用KML_SPBLAS库函数的代码示例,演示系数矩阵与向量计算函数的使用流程。 + +## 使用依赖 + +1. 确保已安装 **boostkit-kml-1.4.0** +2. 确保环境变量正常加载,执行 **env | grep LD_LIBRARY_PATH** +3. 确保已安装编译器版本 >= **GCC 7.3.0** + +## 使用教程 + +KML_SPBLAS有多个版本: +- 单线程版本:/usr/local/kml/lib/kspblas/single/libkspblas.so +- 多线程版本:/usr/local/kml/lib/kspblas/multi/libkspblas.so + +**Demo使用单线程版本** +1. 获取代码 + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. 切入到项目根路径 + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/spblas/ + ``` + +3. 编译demo + + ```shell + mkdir build + cd build + cmake . + make + ``` + +4. 运行demo + + ```shell + ./spblas_demo + ``` + +5. 清理demo + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README_en.md new file mode 100644 index 0000000..8a8de0f --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/README_en.md @@ -0,0 +1,60 @@ +# **KML_SPBLAS library functions demo** + +English | [简体中文](README.md) + +## Introduction + +1. + +The [KML_SPBLAS](https://www.hikunpeng.com/document/detail/en/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0067.html) +library is a basic algebraic operation library of a sparse matrix. The majority of the elements in a sparse matrix are +zero. + +2. The **KML_SPBLAS library functions demo** shows a code example for KML_SPBLAS library functions, demonstrates the use process of sparse matrix and vector calculation function. + +## Dependencies + +1. Ensure that boostkit-kml-1.4.0 has been installed. +2. Run the **env | grep LD_LIBRARY_PATH** command to ensure that the environment variable loaded. +3. Ensure that compiler version >= **GCC 7.3.0** has been installed. + +## Guidance + +There are multiple versions of KML_SPBLAS: +- Single-thread version: /usr/local/kml/lib/kspblas/single/libkspblas.so +- Multi-thread version: /usr/local/kml/lib/kspblas/multi/libkspblas.so + +**Single-thread version is used by demo.** +1. Obtain the code. + + ```shell + git clone https://github.com/kunpengcompute/devkitdemo.git + ``` + +2. Switch to the project root path. + + ```shell + cd ./devkitdemo/hpc-sdk/examples/kml/spblas/ + ``` + +3. Compile the demo. + + ```shell + mkdir build + cd build + cmake .. + make + ``` + +4. Run the demo. + + ```shell + ./spblas_demo + ``` + +5. Clean up the demo. + + ```shell + cd .. + rm -rf build + ``` \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/src/spblas_demo.c b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/src/spblas_demo.c new file mode 100644 index 0000000..fa9ca7c --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/examples/kml/spblas/src/spblas_demo.c @@ -0,0 +1,140 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * Description: + * KML_SPBLAS library functions demo demonstrates the use process of sparse matrix and vector calculation function. + * Create: 2022-05-15 + */ + +#include +#include +#include + +#include + +void PrintMatrix(int row, int column, const float* matrix) +{ + int i; + for (i = 0; i < row; i++) + { + int j; + for (j = 0; j < column; j++) + { + printf("%-12.6f", matrix[j * column + i]); + } + printf("\n"); + } + printf("\n"); +} + +void Print_CSR_To_Matrix(int m, float* values, int values_length, + KML_INT* row_offsets, int row_offsets_length, + KML_INT* column_indices) +{ + int i; + for (i = 0; i < row_offsets_length; ++i) + { + if (row_offsets[i] >= values_length) + { + break; + } + float x[m]; + // Initialize the matrix row array + memset(x, 0, m * sizeof(float)); + + // Confirm the range of values for each row based on the offset + int j; + for (j = row_offsets[i]; j < row_offsets[i + 1]; ++j) + { + x[column_indices[j]] = values[j]; + } + + // print matrix row array + int y; + for (y = 0; y < m; ++y) + { + printf("%.6f\t", x[y]); + } + + printf("\n"); + } + printf("\n"); +} + +int main() +{ + // Record sparse matrices using the 'Compressed Sparse Row Formate (CSR)' storage format + // Represents the number of rows and columns of the matrix A(m*m) [Define NNZ (Num-non-zero) as the number of non-zero elements in matrix A] + KML_INT m = 4; + // Mainly used to record the values of non-zero elements (values) from left to right and top to bottom in the matrix A(m*m), the length of the array is NNZ [Values array] + float a[9] = { 2.0F, -3.0F, 7.0F, 1.0F, -6.0F, 8.0F, -4.0F, 5.0F, 9.0F }; + // Indicates the column indices of the non-zero elements in the matrix A(m*m), the length of the array is NNZ [ColumnIndices array] + KML_INT ja[9] = { 1, 2, 4, 3, 4, 1, 3, 4, 1 }; + // Represents the offset (row offsets) of the matrix A(m*m), the first m elements in the array represent the subscripts of the first non-zero element of each row in the matrix A(m*m) in the Values array, The value of the last item is NNZ, the length of the array is m+1 [RowOffsets array] + KML_INT ia[5] = { 1, 4, 6, 9, 10 }; + + // Only used by functions that support 0-based matrix indexing [conforms to C indexing specification] + KML_INT scsrgemv_ja[9]; + KML_INT scsrgemv_ia[5]; + + int ix; + for (ix = 0; ix < 9; ++ix) + { + scsrgemv_ja[ix] = ja[ix] - 1; + } + + int iy; + for (iy = 0; iy < 5; ++iy) + { + scsrgemv_ia[iy] = ia[iy] - 1; + } + + // array of vectors x + float x[4] = { 1.0F, 3.0F, -2.0F, 5.0F }; + // array of vectors y + float y[4] = { -1.0F, 1.0F, 5.0F, 3.0F }; + + printf("Input A(4*4):\n"); + Print_CSR_To_Matrix(m, a, 9, scsrgemv_ia, 5, scsrgemv_ja); + printf("Input x:\n"); + PrintMatrix(1, m, x); + printf("Input y:\n"); + PrintMatrix(1, m, y); + + // [only supports matrix indices starting from 1] + kml_sparse_status_t status_kml_sparse_scsrgemv = kml_sparse_scsrgemv(KML_SPARSE_OPERATION_NON_TRANSPOSE, m, a, ia, ja, x, y); + if (status_kml_sparse_scsrgemv == KML_SPARSE_STATUS_SUCCESS) + { + printf("(kml_sparse_scsrgemv) --> Output y:\n"); + PrintMatrix(1, m, y); + } + + // [only supports matrix indices starting from 1] + kml_sparse_status_t status_kml_sparse_scsrsymv = kml_sparse_scsrsymv(KML_SPARSE_FILL_MODE_LOWER, m, a, ia, ja, x, y); + if (status_kml_sparse_scsrsymv == KML_SPARSE_STATUS_SUCCESS) + { + printf("(kml_sparse_scsrsymv) --> Output y:\n"); + PrintMatrix(1, m, y); + } + + // [only supports matrix indices starting from 0] + kml_sparse_status_t status_kml_csparse_scsrgemv = kml_csparse_scsrgemv(KML_SPARSE_OPERATION_NON_TRANSPOSE, m, a, scsrgemv_ia, scsrgemv_ja, x, y); + if (status_kml_csparse_scsrgemv == KML_SPARSE_STATUS_SUCCESS) + { + printf("(kml_csparse_scsrgemv) --> Output y:\n"); + PrintMatrix(1, m, y); + } + + return EXIT_SUCCESS; +} diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/module/bisheng_modulefiles b/examples/mpi/devkitdemo-main/hpc-sdk/module/bisheng_modulefiles new file mode 100644 index 0000000..c98fb82 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/module/bisheng_modulefiles @@ -0,0 +1,23 @@ +#%Module1.0 +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Bisheng module for use with 'environment-modules' package: +set version 2.1.0.B010 +set prefix +setenv BISHENG_DIR $prefix + +prepend-path PATH $prefix/bin +prepend-path LD_LIBRARY_PATH $prefix/lib +prepend-path MODULEPATH $prefix diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/module/gcc_modulefiles b/examples/mpi/devkitdemo-main/hpc-sdk/module/gcc_modulefiles new file mode 100644 index 0000000..799ce4d --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/module/gcc_modulefiles @@ -0,0 +1,24 @@ +#%Module1.0 +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Gcc module for use with 'environment-module' package: +set version 10.3.1 +set prefix +setenv GCC_DIR $prefix + +prepend-path PATH $prefix/bin +prepend-path INCLUDE $prefix/include +prepend-path LD_LIBRARY_PATH $prefix/lib64 +prepend-path MODULEPATH $prefix diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/module/hmpi_modulefiles b/examples/mpi/devkitdemo-main/hpc-sdk/module/hmpi_modulefiles new file mode 100644 index 0000000..5b37cae --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/module/hmpi_modulefiles @@ -0,0 +1,24 @@ +#%Module1.0 +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# HMPI module for use with 'environment-modules' package: +conflict mpi +set version 1.1.1 +set prefix + +prepend-path OPAL_PREFIX $prefix/ompi +prepend-path PATH $prefix/ompi/bin:$prefix/ucx/bin +prepend-path LD_LIBRARY_PATH $prefix/ompi/lib:$prefix/ucx/lib +prepend-path INCLUDE $prefix/ompi/include: $prefix/ucx/include diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/README.md b/examples/mpi/devkitdemo-main/hpc-sdk/script/README.md new file mode 100644 index 0000000..e6647aa --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/README.md @@ -0,0 +1,113 @@ +# **鲲鹏HPC SDK一键式安装脚本使用** + +简体中文 | [English](README_en.md) + +## 1、介绍 + +#### 1、自动化安装脚本部署HPC相关软件。包括Hyper-mpi、kml、gcc、毕昇 + +#### 2、支持自定义路径安装 + + +## 2、使用依赖 + +#### 1、服务器兼容性如下 + +| OS | HYPER-MPI | 毕昇2.1 | GCC | 数学库 | +|----| ---- | ---- | ---- | ---- | +| centos 7 | Y (GCC= 9.3,毕昇) | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 LTS | Y (毕昇) | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 sp1 | N | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 sp2 | N | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 sp3 | N | Y | Y | Y (GCC >= 7.3) | +| 麒麟V10 SP1 | Y (GCC = 9.3,毕昇) | Y | Y | N | +| 麒麟V10 SP2 | Y (GCC = 9.3,毕昇) | Y | Y | N | +| unbuntu18.04 | N | Y | Y | Y (GCC >= 7.3)| +| unbuntu20.04 | N | Y | Y | Y (GCC >= 7.3) | +| UOS 1020e | N | Y | Y | N | + +说明:以上表中均为aarch64架构;小括号中为GCC、毕昇编译器的版本代表依赖最小版本,表中的Y代表系统支持安装,N代表不支持安装。 + +#### 2、软件依赖列表 + + +| 依赖 | HYPER-MPI | 毕昇2.1 | GCC | 数学库 | +| ---- | ---- | ---- | ---- | ---- | +| gcc | Y(9.3.0) | Y(>=4.8.5)| N | N | +| bisheng | Y | N | N | N | +| glibc-devel(libc-dev-bin) | N | N | Y(>=2.17) | N | +| glibc | N | Y(>=2.17)| Y(>=2.17) | N | +| libatomic | N | Y(>=1.2.0) | N | N | +| libgomp | N | N | N | Y | + +说明:以上表中内容为hyper-mpi、数学库、GCC、毕昇编译器安装所需要的依赖,表中的Y代表系统依赖,N代表不依赖。redhat系安裝毕昇编译的rpm包时需确保系统已经安装libgomp。 + +## 3、使用教程 + +#### 1、获取kunpeng-hpc-xxx-aarc64-linux.tar.gz包 +[https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.0-aarch64-linux.tar.gz] +(https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.0-aarch64-linux.tar.gz) +#### 2、执行如下命令进行安装 +``` +tar -xf kunpeng-hpc-xxx-aarch64-linux.tar.gz +cd kunpeng-hpc-xxx-aarch64-linux/script +bash install.sh +``` +#### 3、在执行安装过程中根据提示做相应的操作完成HPC安装 +#### 4、安装完成后根据提示添加环境变量:如下回显信息这里以gcc为例 + +> 4.1第一种方式执行下面命令添加环境变量到/etc/profile +``` + echo 'export PATH=/opt/gcc/gcc-xxx-aarch64-linux/bin:$PATH' >>/etc/profile + echo 'export INCLUDE=/opt/gcc/gcc-xxx-aarch64-linux/include:$INCLUDE' >>/etc/profile + echo 'export LD_LIBRARY_PATH=/opt/gcc/gcc-xxx-aarch64-linux/lib64:$LD_LIBRARY_PATH' >>/etc/profile + source /etc/profile +``` +> 4.2 第二种使用module加载module_file使环境变量生效 +``` + module load /opt/modules/gcc/gcc_modulefiles +``` +> 4.3 可以通过如下方式使变量永久生效 + +> * 1、打开~/.bashrc 文件 +``` + vim ~/.bashrc +``` +> * 2、把下面命令写入到 ~/.bashrc +``` + module use /opt/modules/gcc/ + module load gcc_modulefiles +``` +> * 3、保存文件 +> * 4、执行如下命令让配置生效 +``` + source ~/.bashrc +``` +4.4 运行脚本配置环境变量 +``` + cd kunpeng-hpc-xxx-aarch64-linux/script + bash configure_environment_xxxx.sh +``` + +## 4、注意事项 + +#### 1、安装剩余磁盘空间应满足大于3GB +#### 2、仅支持在aarch64环境中安装 + +## 5、卸载软件 +#### 以gcc和kml为例进行说明 +#### 1、打开/etc/profile 或者 ~/.bashrc 检查相关软件二进制文件或者lib文件所在路径 。 +``` +vim /etc/profile(~/.bashrc) +export LD_LIBRARY_PATH=/usr/local/kml/lib:$LD_LIBRARY_PATH +... +export LD_LIBRARY_PATH=/usr/local/kml/lib/kspblas/multi:$LD_LIBRARY_PATH +export INCLUDE=/opt/gcc/gcc-xxxx-aarch64-linux/include:$INCLUDE +``` + +说明:执行上述命令打开/etc/profile(~/.bashrc)可以查看到具体的安装路径为‘/usr/local/kml’ 和 ‘/opt/gcc/gcc-xxxx-aarch64-linux/’ +或者执行env / export 查看软件的安装路径。 + +#### 2、把/etc/profile 或者 ~/.bashrc中的gcc和kml环境变量删除。 +#### 3、根据1步骤中获取的安装目录,在确认此目录中无其他要保留的文件后进行删除操作。路径中/opt为默认安装路径,若为其他自定义路径请自行替换。 +#### 4、打开新的终端窗口,使修改的环境变量生效。 diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/README_en.md b/examples/mpi/devkitdemo-main/hpc-sdk/script/README_en.md new file mode 100644 index 0000000..ae78fa8 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/README_en.md @@ -0,0 +1,110 @@ +# **Kunpeng HPC SDK One-Click Installation Script** + +English | [简体中文](README.md) + +## 1、Introduction + +#### 1、Use the automatic installation script to automatically deploy HPC software, including HYPER-MPI, KML, GCC, and BISHENG. + +#### 2、Support installation in a user-defined path. + + +## 2、Dependency + +#### 1、The server compatibility is as follows: + +| OS | HYPER-MPI | BISHENG 2.1 | GCC | KML | +| ---- | ---- | ---- | ---- | ---- | +| centos 7 | Y (GCC >= 9.3,BISHENG) | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 LTS | Y (BISHNEG) | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 sp1 | N | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 sp2 | N | Y | Y | Y (GCC >= 7.3) | +| openEuler20.03 sp3 | N | Y | Y | Y (GCC >= 7.3) | +| kylin V10 SP1 | Y (GCC >= 9.3,BISHENG) | Y | Y | N | +| kylin V10 SP2 | Y (GCC >= 9.3,BISHENG) | Y | Y | N | +| unbuntu18.04 | N | Y | Y | Y (GCC >= 7.3)| +| unbuntu20.04 | N | Y | Y | Y (GCC >= 7.3) | +| UOS 1020e | N | Y | Y | N | + +Note: The OSs listed in the preceding table use the AArch64 architecture. The versions of the GCC and Bisheng Compiler in parentheses indicate the earliest supported versions. Y indicates supported installation and N indicates the installation is not supported. + +#### 2、Software dependency list + + +| Dependency | HYPER-MPI | BISHENG2.1 | GCC | KML | +| ---- | ---- | ---- | ---- | ---- | +| gcc | Y(9.3.0) | Y(>4.8.5)| N | N | +| bisheng | Y | N | N | N | +| glibc-devel(libc-dev-bin) | N | N | Y(>2.17) | N | +| glibc | N | Y(>2.17)| Y(>2.17) | N | +| libatomic | N | Y(>=1.2) | N | N | +| libgomp | N | N | N | Y | + +Note: The preceding table lists the dependencies required for installing the HYPER-MPI, math library, GCC, and Bisheng Compiler. Y indicates required dependency for the software and N indicates the dependency is not required. Before installing the RPM package compiled by Bisheng in the Red Hat system, ensure that libgomp has been installed in the system. + +## 3、Usage Guide + +#### 1、Obtain the kunpeng-hpc-1.0.0-aarc64-linux.tar.gz package. +[https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.0-aarch64-linux.tar.gz] +(https://mirrors.huaweicloud.com/kunpeng/archive/Kunpeng_SDK/HPC/kunpeng-hpc-1.0.0-aarch64-linux.tar.gz) +#### 2、Run the following commands to install the software: +``` +tar -xf kunpeng-hpc-xxx-aarch64-linux.tar.gz +cd kunpeng-hpc-xxx-aarch64-linux/script +bash install.sh +``` +#### 3、Perform operations as prompted to install the HPC software. +#### 4、After the installation is complete, add environment variables ad prompted. The following command output uses GCC as an example: + +> 4.1 Method 1: Add environment variables to /etc/profile. +``` + echo 'export PATH=/opt/gcc/gcc-xxx-aarch64-linux/bin:$PATH' >>/etc/profile + echo 'export INCLUDE=/opt/gcc/gcc-xxx-aarch64-linux/include:$INCLUDE' >>/etc/profile + echo 'export LD_LIBRARY_PATH=/opt/gcc/gcc-xxx-aarch64-linux/lib64:$LD_LIBRARY_PATH' >>/etc/profile + source /etc/profile +``` +> 4.2 Method 2: Use the module command to load module_file for the environment variables to take effect. +``` + module load /opt/modules/gcc/gcc_modulefiles +``` +> 4.3 Method 3: Make the environment variables take effect permanently. + +> * 1、Open the ~/.bashrc. +``` + vim ~/.bashrc +``` +> * 2、Add the following content to the ~/.bashrc file: +``` + module use /opt/modules/gcc + module load gcc_modulefiles +``` +> * 3、Save the file. +> * 4、Make the configuration take effect: +``` + source ~/.bashrc +``` +4.4 Method 4: Run the script to configure environment variables. +``` + cd kunpeng-hpc-xxx-aarch64-linux/script + bash configure_environment_xxxxx.sh +``` +## 4、Precautions + +#### 1、The free drive space for the installation must be greater than 3 GB. +#### 2、The installation can be performed only in the AArch64 environment. + +## 5、Software Uninstallation +#### The following uses gcc and kml as an example. +#### 1、Open /etc/profile or ~/.bashrc to check the directory where the binary or lib files of related software are stored. +``` +vim /etc/profile(~/.bashrc) +export LD_LIBRARY_PATH=/usr/local/kml/lib:$LD_LIBRARY_PATH +... +export LD_LIBRARY_PATH=/usr/local/kml/lib/kspblas/multi:$LD_LIBRARY_PATH +export INCLUDE=/opt/gcc/gcc-xxxx-aarch64-linux/include:$INCLUDE +``` +Note: After you access /etc/profile (~/.bashrc), you can view that the installation paths are /usr/local/kml and /opt/gcc/gcc-xxxx-aarch64-linux/ or Run the 'env / export' command to view the software installation path. + +#### 2、Delete environment variables. +#### 3、In the installation path obtained in step 1, ensure that there are no other files to be stored in the path, and then delete the installation path. In then path, '/opt' is then default installation path. Replace it if it is a user-defined path. +#### 4、Open a new terminal window for the modified environment variables to take effect. diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/common_fun.sh b/examples/mpi/devkitdemo-main/hpc-sdk/script/common_fun.sh new file mode 100644 index 0000000..34fac2f --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/common_fun.sh @@ -0,0 +1,530 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# ctrl+c +onCtrlC() { + logger "The Ctrl+C exception is triggered." {TIP_COLOR_FAILED} + exit 0 +} + +# ctrl+z +onCtrlZ() { + logger "The Ctrl+Z exception is triggered." {TIP_COLOR_FAILED} + exit 0 +} + +# SSH disconnection exception +onDisconnect() { + logger "The SSH connection was disconnected exception is triggered." {TIP_COLOR_FAILED} + exit 0 +} + +create_log_file() { + time_stamp=$(date +%s) + # Installation log file name + LOG_FILE_NAME="install_hpc_${time_stamp}.log" + # Absolute path of log files + log_file_of_abspath=${current_dir}/../log/$LOG_FILE_NAME + # Create a log file + mkdir -p ${current_dir}/../log + touch ${log_file_of_abspath} +} + +logger() { + local msg="$1" + local tip_color=$2 + local datetime=$(date "+%Y-%m-%d %H:%M:%S") + if [[ "${tip_color}" ]] && [[ -z $(echo "${tip_color}" | sed "s/[0-9]//g") ]]; then + echo -e "\e[1;${tip_color}m${msg}\e[0m" + if [[ "${tip_color}" == "${TIP_COLOR_FAILED}" ]]; then + level='ERROR' + elif [[ "${tip_color}" == "${TIP_COLOR_WARNING}" ]]; then + level='WARNING' + else + level='INFO' + fi + else + if [[ "${tip_color}" == "ERROR" ]]; then + level='ERROR' + elif [[ "${tip_color}" == "WARNING" ]]; then + level='WARNING' + else + level='INFO' + fi + fi + if [ -f "${log_file_of_abspath}" ]; then + echo "[${datetime}] [${level}] ${msg}" >>${log_file_of_abspath} + fi +} + +get_os_name() { + # Obtain the os name + os_name=$(cat /etc/os-release | grep "PRETTY_NAME" | awk -F '"' '{print $2}') + os_name_del_space=${os_name// /} + if [[ ${os_name_del_space} =~ "KylinLinuxAdvancedServerV10" ]]; then + os_name="KylinLinuxAdvancedServerV10" + elif [[ ${os_name_del_space} =~ "Ubuntu20.04" ]]; then + os_name="Ubuntu20.04" + elif [[ ${os_name_del_space} =~ "Ubuntu18.04" ]]; then + os_name="Ubuntu18.04" + elif [[ ${os_name_del_space} =~ "CentOSLinux" ]]; then + red_os=$(cat /etc/redhat-release) + red_os=${red_os// /} + [[ ${red_os} =~ "CentOSLinuxrelease7.6.1810" ]] && os_name="CentOSLinuxrelease7.6.1810" + else + os_name=${os_name_del_space} + fi +} + +version_ge() { + # Compare the version + if [[ "$#" != 2 ]]; then + return 1 + fi + test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1" + if [[ "$?" == 0 ]]; then + return 0 + else + return 1 + fi +} + +user_customize_path() { + # Enter a user-defined path. + install_name=$1 + flag=1 + while [[ ${flag} == '1' ]]; do + logger "For a non-root user, enter the directory on which the user has permission." ${TIP_COLOR_WARNING} + read -p "Enter the path for installing ${install_name}(default /opt):" you_path + if [[ -z "${you_path}" ]]; then + # Default installation path + customize_path="/opt" + else + customize_path="${you_path}" + fi + check_customize_path "${customize_path}" + if [[ "$?" == 0 ]]; then + break + fi + done + check_space ${customize_path} +} + +get_install_kml_mode() { + # Obtain the dpkg or rpm installation mode of the math library + if [[ "${os_name}" =~ "Ubuntu" ]]; then + install_package_kind='dpkg' + else + install_package_kind='rpm' + fi +} + +check_customize_path() { + # Check whether the entered path is valid [0-9a-zA-Z-_/] + customize_path="$1" + len_path=${#customize_path} + char_max=$(($(getconf SCHAR_MAX) - 59)) + unset new_customize_path + if [[ "${len_path}" -ge "${char_max}" ]]; then + logger "The path length exceeds the limit. Enter another one." ${TIP_COLOR_FAILED} + return 1 + fi + if echo "${customize_path}" | grep -vqE "^/"; then + logger "The path should be an absolute path. Enter another one." ${TIP_COLOR_FAILED} + return 1 + fi + ar=($(echo "${customize_path}" | tr '/' ' ')) + for value in ${ar[*]}; do + str_status=$(echo "$value" | tr -d "[a-zA-Z0-9-_]") + if [[ -n "$str_status" ]]; then + logger "The entered installation path can contain digital alphabets and special characters such as ${ALLOW_STRING} Please enter a correct path and try again." ${TIP_COLOR_FAILED} + return 1 + else + new_customize_path=${new_customize_path}/${value} + fi + done + if [ -f ${customize_path} ]; then + logger "A file with the same name exists. Enter another one." ${TIP_COLOR_FAILED} + return 1 + fi + customize_path=${new_customize_path} + [[ -z ${customize_path} ]] && customize_path="/" + mark_customize_path_status + mkdir -p ${customize_path} + [[ ${customize_path} == "/" ]] || customize_path=$( + cd ${customize_path} + pwd + )/ +} + +mark_customize_path_status() { + if [[ -d ${customize_path} ]]; then + customize_path_status=1 + else + valid_customize_path=${customize_path} + while [[ ${flag} == 1 ]]; do + valid_customize_path=${valid_customize_path%/*} + if [ -d ${valid_customize_path} ]; then + customize_path_status=2 + break + fi + if [ -z ${valid_customize_path} ]; then + break + fi + done + fi +} + +check_space() { + # Check the drive space + customize_path="$1" + space_flag=1 + while [[ ${space_flag} == 1 ]]; do + if [[ -d ${customize_path} ]]; then + avail_space=$(df -lkP ${customize_path} | awk "NR>1" | awk -F " " '{print $4}') + break + else + customize_path=${customize_path%/*} + if [[ -z ${customize_path} ]]; then + opt_space=$(df -lkP '/' | awk "NR>1" | awk -F " " '{print $4}') + break + fi + fi + done + if [[ ${avail_space} -lt ${low_space} ]]; then + logger "The disk space of the selected installation directory is insufficient." ${TIP_COLOR_FAILED} + logger "Ensure that the available space of the ${customize_path} directory is greater than ${low_space_package_g} GB" ${TIP_COLOR_FAILED} + exit 1 + fi +} + +user_choose() { + while_flag=1 + while [[ ${while_flag} == 1 ]]; do + num=${#software_support_list[@]} + # Install the software according to the sequence selected by the user. + echo -n -e "\e[1;33mEnter the serial number of the software that can be installed. Format: a single digit or 'digits+commas', for example, (1,2,3). To exit the installation, enter no:\e[0m" + read -r choose_install + # If the length of the entered character string exceeds the upper limit, the system prompts you to enter a new character string. + max_length_number=$((2 * ${num} - 1)) + length_number=$(echo ${choose_install} | wc -L) + if [[ ${length_number} -gt ${max_length_number} ]]; then + logger "The character string you entered is too long." ${TIP_COLOR_FAILED} + continue + fi + # Only one Hyper MPI can be installed. + if [[ "${os_name}" =~ "KylinLinux" ]] || [[ "${os_name}" =~ "CentOSLinux" ]]; then + if [[ ${choose_install} =~ "1" ]] && [[ ${choose_install} =~ "2" ]]; then + logger "Only one hyper-mpi can be installed." ${TIP_COLOR_FAILED} + continue + fi + fi + if [[ ${choose_install} =~ ^[nN]$|^no$ ]]; then + logger "Exit installation." ${TIP_COLOR_FAILED} + exit 1 + fi + if echo ${choose_install} | grep -qE "([1-$num],){1,$num}[1-$num]$|^[1-$num]$"; then + break + else + logger "Select one or multiple sequences and use commas to separate them." ${TIP_COLOR_FAILED} + fi + done + if [[ ${length_number} -eq 1 ]]; then + # Only one is selected by the user. + # Display the item that the user selects to install. + select_result=${software_support_list[((${choose_install} - 1))]} + else + # Display repeated user input. + choose_install=$(echo ${choose_install} | tr ',' ' ' | xargs -n 1 | sort -u) + for i in ${choose_install}; do + select_result="$select_result,${software_support_list[(($i - 1))]}" + done + fi + logger "The software you select to install is ${select_result#,}." ${TIP_COLOR_SUCCESS} +} + +show_software_support_list() { + # Display the software supported by the current system user. + logger "Installation environment check result:" ${TIP_COLOR_CHECKING} + if [[ "${software_support_list}" =~ "HMPI" ]]; then + logger "The hyper-mpi corresponds to a specific compiler. Install the matched compiler for the hyper-mpi. For example, the compiler corresponding to HMPI-BISHENG is BISHENG." ${TIP_COLOR_ECHO} + fi + if [[ "${software_support_list}" =~ "KML" ]]; then + logger "The KML corresponds to a specific compiler. Install the matched compiler for the KML. For example, the compiler corresponding to KML is GCC." ${TIP_COLOR_ECHO} + fi + printf "%-16s %-29s %-14s %-20s\n" "SequenceNumber" "Software" "Support" >>${log_file_of_abspath} + printf "%-16s %-29s %-14s %-20s\n" "SequenceNumber" "Software" "Support" + software_support_list=($(echo ${software_support_list} | tr ' ' ' ')) + for ((i = 0; i < ${#software_support_list[@]}; i++)); do + printf "%-16s %-29s %-20s\n" "$((i + 1))" "${software_support_list[i]}" "${check_result_list[i]}" >>${log_file_of_abspath} + printf "%-16s %-29s \033[1;32m%-20s\033[0m\n" "$((i + 1))" "${software_support_list[i]}" "${check_result_list[i]}" + done +} + +read_answer() { + # Process user interaction operations. + ask_question="$*" + ask_flag=1 + while [[ ${ask_flag} == 1 ]]; do + read -p "${ask_question} [Y/N]:" you_choose + if [[ ${you_choose} =~ ^[Yy]$ ]]; then + return 0 + elif [[ ${you_choose} =~ ^[nN]$ ]]; then + return 1 + else + logger 'input error' ${TIP_COLOR_FAILED} + continue + fi + done +} + + +hand_precondition_mpi() { + # Handle the installation exception caused by insufficient environment dependency. + if [[ ${#miss_package[@]} -gt 0 ]]; then + logger "The $(echo ${miss_package[@]}) dependency is not detected in the environment." ${TIP_COLOR_WARNING} + read_answer "The corresponding ${miss_package[@]} is missing or the version is incorrect. Are you sure you want to continue the installation?" + if [[ $? != 0 ]]; then + logger "Exit the hyper-mpi installation." ${TIP_COLOR_FAILED} + return 1 + fi + fi + install_hyper_mpi +} + +check_precondition_kml() { + # Check the math library dependency. + local install_package_kind=$1 + miss_package_kml=() + libc6="/usr/lib64/libc.so.6" + libgomp="/usr/lib64/libgomp.so.1" + [[ ${install_package_kind} == "dpkg" ]] && libc6="/lib/aarch64-linux-gnu/libc.so.6" + [[ ${install_package_kind} == "dpkg" ]] && libgomp="/usr/lib/aarch64-linux-gnu/libgomp.so.1" + [[ ! -f ${libc6} ]] && miss_package_kml[${#miss_package_kml[*]}]="libc6" + [[ ! -f ${libgomp} ]] && miss_package_kml[${#miss_package_kml[*]}]="libgomp" + result=$(command -v nm) + if [[ -z ${result} ]]; then + miss_package_kml[${#miss_package_kml[*]}]="nm" + fi +} + +hand_precondition_kml() { + if [[ ${#miss_package_kml[@]} -gt 0 ]]; then + logger "The ${miss_package_kml[@]} dependency is not detected in the environment." + read_answer "The system does not have dependencies such as ${miss_package_kml[@]} or the version does not meet the requirements. Are you sure you want to continue the installing the KML?" + if [[ $? != 0 ]]; then + logger "Exit the KML installation." ${TIP_COLOR_FAILED} + return 1 + fi + fi + if [[ ${kml_install_status} == ${SUCCESS} ]]; then + del_math_kml + if [[ $? == 1 ]]; then + return 1 + fi + fi + install_math_kml +} + +check_precondition_compiler() { + # Check the compiler dependency. + local compiler_type=$1 + miss_package_bisheng=() + miss_package_gcc=() + glibc_version=$(ldd --version | grep -Po '\d+.\d+\d+' | head -n 1) + version_ge "${glibc_version}" "2.17" + if [[ "$?" != 0 ]]; then + miss_package_gcc[${#miss_package_gcc[*]}]="GLIBC(>=2.17)" + miss_package_bisheng[${#miss_package_bisheng[*]}]="GLIBC(>=2.17)" + fi + if [[ ${compiler_type} == "gcc" ]]; then + if [[ ${install_package_kind} == "rpm" ]]; then + glibc_devel_version=$(${install_package_kind} -qa | grep -E "^glibc-devel" | head -n 1 | grep -Po "\d+\.\d+\d+") + glibc_devel="glibc-devel(>=2.17)" + else + glibc_devel_version=$(${install_package_kind} -l | grep "libc-dev-bin" | head -n 1 | grep -Po "\d+\.\d+\d+") + glibc_devel="libc-dev-bin(>=2.17)" + fi + version_ge "${glibc_devel_version}" '2.17' + if [[ "$?" != 0 ]]; then + miss_package_gcc[${#miss_package_gcc[*]}]="${glibc_devel}" + fi + fi + if [[ ${compiler_type} == "bisheng" ]]; then + gcc_version=$(gcc --version 2>&1 | head -n 1 | grep -Po "\d+\.\d+\.\d+" | head -n 1) + version_ge "${gcc_version}" '4.8.5' + if [[ "$?" != 0 ]]; then + miss_package_bisheng[${#miss_package_bisheng[*]}]="gcc(>=4.8.5)" + fi + libatomic_version=$(ldconfig -v 2>&1 | grep libatomic | awk -F '->' '{print $2}' | grep -Po "\d+\.\d+\.\d+") + version_ge "${libatomic_version}" '1.2.0' + if [[ "$?" != 0 ]]; then + miss_package_bisheng[${#miss_package_bisheng[*]}]="libatomic(>=1.2.0)" + fi + fi +} + +hand_precondition_compiler() { + local compiler_type=$1 + if [[ ${compiler_type} == "gcc" ]]; then + miss_package_compiler=(${miss_package_gcc[*]}) + compiler_install_status=${gcc_install_status} + else + miss_package_compiler=(${miss_package_bisheng[*]}) + compiler_install_status=${bisheng_install_status} + fi + if [[ ${#miss_package_compiler[@]} -gt 0 ]]; then + logger "The ${miss_package_compiler[@]} dependency is nit detected in the environment." + read_answer "The system does not have dependencies such as ${miss_package_compiler[@]} or the version does not meet the requirements. Are you sure you want to continue the installing the ${compiler_type^^}?" + if [[ $? != 0 ]]; then + logger "Exit the ${compiler_type^^} installation." ${TIP_COLOR_FAILED} + return 1 + fi + fi + install_compiler ${compiler_type} + if [[ $? == 1 ]]; then + logger "Exit the ${compiler_type^^} installation." ${TIP_COLOR_FAILED} + return 1 + fi +} + +check_install_user() { + # Prompt for non-root users + current_user=$(whoami) + if [[ "${current_user}" != "root" ]]; then + logger "The current user is not the root user, run the sudo bash install.sh command." ${TIP_COLOR_WARNING} + exit 1 + fi +} + +check_os_name() { + # Check whether the current system supports the installation. + get_os_name + if [[ ! "${support_os_names}" =~ "${os_name}" ]]; then + logger "The system does not support the HPC software." ${TIP_COLOR_FAILED} + exit 1 + fi +} + +check_os_architecture() { + if [[ $(uname -m) != "aarch64" ]]; then + logger "The system does not support installation. Please select the aarch64 architecture." ${TIP_COLOR_FAILED} + exit 1 + fi +} + +change_directory_owner() { + local directory="$1" + if [ -d "${directory}" ]; then + chown root:root -R ${directory} + fi +} + +change_directory_permissions() { + local directory="$1" + local bin_type="$2" + local flag=1 + local path='' + if [[ ${bin_type} ]]; then + [[ ${bin_type} == "hyper-mpi" ]] && local software_ompi_bin="${directory}/ompi/bin" && local software_ucx_bin="${directory}/ucx/bin" + [[ ${bin_type} == "gcc" ]] && local software_gcc_bin="${directory}/bin" && local software_gcc_gnu_bin="${directory}/aarch64-linux-gnu/bin" + [[ ${bin_type} == "bisheng" ]] && local software_bisheng_bin="${directory}/bin" + fi + if [[ ${customize_path_status} == 1 ]]; then + cd ${customize_path} + elif [[ ${customize_path_status} == 2 ]]; then + if [ -z ${valid_customize_path} ]; then + local customize_path_special=${customize_path} + else + cd ${valid_customize_path} + local split_path=$(echo $directory | awk -F "^${valid_customize_path}/" '{print $2}') + fi + fi + if [[ "${split_path}" ]];then + local valid_customize_path_split=${valid_customize_path} + for path in $(echo ${split_path} | tr '/' ' ');do + valid_customize_path_split=${valid_customize_path_split}/${path} + chmod 755 ${valid_customize_path_split} + done + else + local delete_last_slashes=${customize_path%%/} + for path in $(echo ${directory} | tr '/' ' ');do + local chmod_path=${chmod_path}/${path} + [[ -z "${customize_path_special}" && ${#delete_last_slashes} -ge ${#chmod_path} ]] && continue || chmod 755 ${chmod_path} + done + fi + + [[ $(ls -A "${directory}") ]] && chmod 755 -R ${directory}/* + find ${directory} -type f | xargs chmod 644 + [[ ${software_ompi_bin} ]] && find ${software_ompi_bin} -type f | xargs chmod 755 + [[ ${software_ucx_bin} ]] && find ${software_ucx_bin} -type f | xargs chmod 755 + [[ ${software_gcc_bin} ]] && find ${software_gcc_bin} -type f | xargs chmod 755 + [[ ${software_gcc_gnu_bin} ]] && find ${software_gcc_gnu_bin} -type f | xargs chmod 755 + [[ ${software_bisheng_bin} ]] && find ${software_bisheng_bin} -type f | xargs chmod 755 +} + +del_math_kml() { + # Delete the original kml environment variables + read_answer "Before the installation, the existing software will be uninstalled. Are you sure you want to authorize the script to continue?" + if [[ $? != 0 ]];then + logger "Do not install the kml repeatedly." ${TIP_COLOR_ECHO} + return 1 + fi + logger "Deleting kml" ${TIP_COLOR_ECHO} + if [[ ${install_package_kind} == "rpm" ]]; then + $install_package_kind -e "${boost_math_name}" + else + $install_package_kind -P "${boost_math_name}" + fi + logger "Deleting kml successfull" ${TIP_COLOR_ECHO} +} + +del_hyper_mpi() { + # Delete the original hyper mpi environment variables + local hyper_mpi_type="$1" + install_hyper_mpi_path="${customize_path}hyper_mpi/${hyper_mpi_type}/${hmpi_package_name}" + hyper_mpi_modules_path="${customize_path}modules/${hyper_mpi_type}/hmpi_modulefiles" + if [[ -d "${install_hyper_mpi_path}" ]] || [[ -f "${hyper_mpi_modules_path}" ]];then + [[ -f "${hyper_mpi_modules_path}" ]] && logger "${hyper_mpi_modules_path} file already exists." ${TIP_COLOR_WARNING} + [[ -d "${install_hyper_mpi_path}" ]] && logger "${install_hyper_mpi_path} directory is not empty." ${TIP_COLOR_WARNING} + read_answer "Are you sure you want to continue the instation? if yes, ${install_hyper_mpi_path} the directory or ${hyper_mpi_modules_path} file will be overwritten." + if [[ $? != 0 ]];then + logger 'Do not install the hyper-mpi repeatedly.' ${TIP_COLOR_ECHO} + return 1 + fi + [[ -f "${hyper_mpi_modules_path}" ]] && rm -rf "${hyper_mpi_modules_path}" + [[ -d "${install_hyper_mpi_path}" ]] && rm -rf "${install_hyper_mpi_path}" + logger "Deleting ${hyper_mpi_type}" ${TIP_COLOR_ECHO} + fi +} + +del_compiler() { + local compiler_type=$1 + local compiler_path="${customize_path}${compiler_type}/${compiler_name}" + local compiler_modules_path="${customize_path}modules/${compiler_type}_modulefiles" + if [[ -f "${compiler_modules_path}" ]] || [[ -d "${compiler_path}" ]];then + [[ -f "${compiler_modules_path}" ]] && logger "${compiler_modules_path} file already exists." ${TIP_COLOR_WARNING} + [[ -d "${compiler_path}" ]] && logger "${compiler_path} directory is not empty." ${TIP_COLOR_WARNING} + read_answer "Are you sure you want to continue the instllation? if yes, the ${compiler_path} directory or ${compiler_modules_path} file will be overwritten." + if [[ $? != 0 ]];then + logger "Do not install the ${compiler_type^^} repeatedly." ${TIP_COLOR_ECHO} + return 1 + fi + [[ -d "${compiler_path}" ]] && rm -rf ${compiler_path} + [[ -f "${compiler_modules_path}" ]] && rm -rf ${compiler_modules_path} + logger "Deleting ${compiler_type^^} " ${TIP_COLOR_ECHO} + fi +} diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/configure_environment.sh b/examples/mpi/devkitdemo-main/hpc-sdk/script/configure_environment.sh new file mode 100644 index 0000000..0678469 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/configure_environment.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +compiler_gcc='' +compiler_gcc_install='' +compiler_bisheng='' +compiler_bisheng_install='' +hyper_mpi_gcc='' +hyper_mpi_gcc_install='' +hyper_mpi_bisheng='' +hyper_mpi_bisheng_install='' + + +configure_env(){ + # configure env + if [[ "${compiler_gcc}${compiler_bisheng}${hyper_mpi_gcc}${hyper_mpi_bisheng}test" == 'test' ]];then + echo -e "\e[1;33mYou have not installed any software. Please run the installation script before running the script.\e[0m" + exit + fi + [[ ${hyper_mpi_bisheng} ]] && set_hyper_mpi_env ${hyper_mpi_bisheng_install} + [[ ${hyper_mpi_gcc} ]] && set_hyper_mpi_env ${hyper_mpi_gcc_install} + [[ ${compiler_gcc} ]] && set_compiler_gcc_env ${compiler_gcc_install} + [[ ${compiler_bisheng} ]] && set_compiler_bisheng_env ${compiler_bisheng_install} + echo -e "\e[1;33mTo make the related commands take effect, run the following command:\e[0m" + if [[ ${hyper_mpi_bisheng} || ${hyper_mpi_gcc} ]];then + echo "source ~/.bashrc" + fi + + if [[ ${compiler_gcc} || ${compiler_bisheng} ]];then + echo "source /etc/profile" + fi +} + +set_compiler_gcc_env(){ + local install_compiler_path=$1 + echo "export PATH=${install_compiler_path}/${compiler_gcc}/bin:\$PATH" >>/etc/profile + echo "export INCLUDE=${install_compiler_path}/${compiler_gcc}/INCLUDE:\$INCLUDE" >>/etc/profile + echo "export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_gcc}/lib64:\$LD_LIBRARY_PATH" >>/etc/profile +} + +set_compiler_bisheng_env(){ + local install_compiler_path=$1 + echo "export PATH=${install_compiler_path}/${compiler_bisheng}/bin:\$PATH" >>/etc/profile + echo "export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_bisheng}/lib:\$LD_LIBRARY_PATH" >>/etc/profile + +} + +set_hyper_mpi_env(){ + local install_path=$1 + echo "hwmpi=${install_path}" >> ~/.bashrc + echo 'export OPAL_PREFIX=${hwmpi}/ompi' >> ~/.bashrc + echo 'export PATH=${hwmpi}/ompi/bin:${hwmpi}/ucx/bin:$PATH' >> ~/.bashrc + echo 'export INCLUDE=${hwmpi}/ompi/include:${hwmpi}/ucx/include:$INCLUDE' >> ~/.bashrc + echo 'export LD_LIBRARY_PATH=${hwmpi}/ompi/lib:${hwmpi}/ucx/lib:$LD_LIBRARY_PATH' >> ~/.bashrc +} + +configure_env \ No newline at end of file diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/const.conf b/examples/mpi/devkitdemo-main/hpc-sdk/script/const.conf new file mode 100644 index 0000000..152f7f7 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/const.conf @@ -0,0 +1,39 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OSs supported by HPC +SUPPORT_OS_NAME=openEuler20.03(LTS);openEuler20.03(LTS-SP1);openEuler20.03(LTS-SP2);openEuler20.03(LTS-SP3);KylinLinuxAdvancedServerV10;UnionTechOSServer20;CentOSLinuxrelease7.6.1810;Ubuntu20.04;Ubuntu18.04; +SOFTWARE_TO_BE_INSTALLED=HMPI-GCC;HMPI-BISHENG;BISHENG;GCC;KML; +KYLINV10_LINUX_HMPI_GCC_NAME=Hyper-MPI_1.1.1_aarch64_KylinV10SP2_gcc9.3.0_MLNX-OFED5.4 +KYLINV10_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_KylinV10SP2_Bisheng2.1.0_MLNX-OFED5.4 +CENTOS7.6_LINUX_HMPI_GCC_NAME=Hyper-MPI_1.1.1_aarch64_CentOS7.6_GCC9.3_MLNX-OFED5.0 +CENTOS7.6_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_CentOS7.6_Bisheng2.1.0_MLNX-OFED5.0 +OPENEULER20.03_LTS_LINUX_HMPI_BISHENG_NAME=Hyper-MPI_1.1.1_aarch64_OpenEuler20.03-LTS_Bisheng2.1.0_MLNX-OFED5.4 +BISHENG_COMPILER_NAME=bisheng-compiler-2.1.0-aarch64-linux +GCC_COMPILER_NAME=gcc-10.3.1-2021.09-aarch64-linux +LIBRARY_MATH_DEB_NAME=boostkit-kml-1.6.0.aarch64 +LIBRARY_MATH_RPM_NAME=boostkit-kml-1.6.0-1.aarch64 +# Color of the terminal input +TIP_COLOR_FAILED=31 +TIP_COLOR_SUCCESS=32 +TIP_COLOR_WARNING=33 +TIP_COLOR_COMMAND=35 +TIP_COLOR_CHECKING=36 +TIP_COLOR_ECHO=37 +# The maximum drive space is 3GB +LOW_SPACE=3145728 +LOW_SPACE_PACKAGE_G=3 +# User-defined path format +ALLOW_STRING="_-" + diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/const.sh b/examples/mpi/devkitdemo-main/hpc-sdk/script/const.sh new file mode 100644 index 0000000..6844602 --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/const.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Read the configuration file and use it as the global variable of the installation script +current_dir=$( + cd $(dirname $0) + pwd +) +# Supported OSs +support_os_names=$(sed '/^SUPPORT_OS_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) + +declare -A software_support_lists=(["openEuler20.03(LTS)"]="HMPI-BISHENG BISHENG GCC KML" + ["openEuler20.03(LTS-SP1)"]="BISHENG GCC KML" + ["openEuler20.03(LTS-SP2)"]="BISHENG GCC KML" + ["openEuler20.03(LTS-SP3)"]="BISHENG GCC KML" + ["KylinLinuxAdvancedServerV10"]="HMPI-GCC HMPI-BISHENG BISHENG GCC" + ["UnionTechOSServer20"]="BISHENG GCC" + ["CentOSLinuxrelease7.6.1810"]="HMPI-GCC HMPI-BISHENG BISHENG GCC KML" + ["Ubuntu20.04"]="BISHENG GCC KML" + ["Ubuntu18.04"]="BISHENG GCC KML" + ["KylinLinuxAdvancedServerV10_HMPI_GCC"]="${kylinv10_hmpi_gcc_name}" + ["KylinLinuxAdvancedServerV10_HMPI_BISHENG"]="${kylinv10_hmpi_bisheng_name}" + ["CentOSLinuxrelease7.6.1810_HMPI_GCC"]="${centos7_6_linux_hmpi_gcc_name}" + ["CentOSLinuxrelease7.6.1810_HMPI_BISHENG"]="${centos7_6_hmpi_bisheng_name}" +) +# Minimum drive size +low_space=$(sed '/^LOW_SPACE=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +low_space_package_g=$(sed '/^LOW_SPACE_PACKAGE_G=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +# Math library name +boost_math_name="boostkit-kml" +boost_math_rpm_name=$(sed '/^LIBRARY_MATH_RPM_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +boost_math_deb_name=$(sed '/^LIBRARY_MATH_DEB_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +bisheng_compiler_name=$(sed '/^BISHENG_COMPILER_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +gcc_compiler_name=$(sed '/^GCC_COMPILER_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +kylinv10_hmpi_gcc_name=$(sed '/^KYLINV10_LINUX_HMPI_GCC_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +kylinv10_hmpi_bisheng_name=$(sed '/^KYLINV10_LINUX_HMPI_BISHENG_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +centos7_6_linux_hmpi_gcc_name=$(sed '/^CENTOS7.6_LINUX_HMPI_GCC_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +centos7_6_hmpi_bisheng_name=$(sed '/^CENTOS7.6_LINUX_HMPI_BISHENG_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +openeuler20_03_lts_hmpi_bisheng_name=$(sed '/^OPENEULER20.03_LTS_LINUX_HMPI_BISHENG_NAME=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +hyper_mpi_gcc_package_names=(${kylinv10_hmpi_gcc_name} ${centos7_6_linux_hmpi_gcc_name}) +hyper_mpi_bisheng_package_names=(${kylinv10_hmpi_bisheng_name} ${centos7_6_hmpi_bisheng_name} ${openeuler20_03_lts_hmpi_bisheng_name}) +# List of software to be installed +software_to_be_installed=$(sed '/^SOFTWARE_TO_BE_INSTALLED=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +# User-defined path rule +ALLOW_STRING=$(sed '/^ALLOW_STRING=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) +# Success or failure status +SUCCESS=1 +FAILED=0 +# Color processing for terminal output +TIP_COLOR_FAILED=$(sed '/^TIP_COLOR_FAILED=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # red +TIP_COLOR_SUCCESS=$(sed '/^TIP_COLOR_SUCCESS=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # green +TIP_COLOR_WARNING=$(sed '/^TIP_COLOR_WARNING=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # yellow +TIP_COLOR_COMMAND=$(sed '/^TIP_COLOR_COMMAND=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # purple +TIP_COLOR_CHECKING=$(sed '/^TIP_COLOR_CHECKING=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # blue +TIP_COLOR_ECHO=$(sed '/^TIP_COLOR_ECHO=/!d;s/.*=//;s/\r//' ${current_dir}/const.conf) # white diff --git a/examples/mpi/devkitdemo-main/hpc-sdk/script/install.sh b/examples/mpi/devkitdemo-main/hpc-sdk/script/install.sh new file mode 100644 index 0000000..7f595ee --- /dev/null +++ b/examples/mpi/devkitdemo-main/hpc-sdk/script/install.sh @@ -0,0 +1,497 @@ +#!/bin/bash + +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +current_dir=$( + cd $(dirname $0) + pwd +) +source ${current_dir}/const.sh +source ${current_dir}/common_fun.sh +install_package_dir=${current_dir}/../package +module_file_dir=${current_dir}/../module +time_stamp=$(date +%s) +# Press ctrl-c to capture terminal disconnection exceptions. +trap 'onCtrlC' INT +trap 'onCtrlZ' SIGTSTP +trap 'onDisconnect' HUP + +set_software_status() { + # Obtain the installation status of supported software. + check_result_list=() + suggestion_list=() + software_support_list=${software_support_lists["$os_name"]} + for software_support in $(echo $software_support_list | tr ' ' ' '); do + if [[ ${software_support} =~ ^HMPI-GCC$|^HMPI-BISHENG$|^BISHENG$|^GCC$|^KML$ ]]; then + check_result_list[${#check_result_list[*]}]='Y' + fi + done +} + +get_hyper_mpi_package_name() { + # Obtain the HMPI package name. + if [[ "${os_name}" =~ "KylinLinux" ]]; then + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${kylinv10_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${kylinv10_hmpi_bisheng_name} + fi + elif [[ "${os_name}" =~ "CentOSLinux" ]]; then + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${centos7_6_linux_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${centos7_6_hmpi_bisheng_name} + fi + elif [[ "${os_name}" =~ "openEuler20.03" ]]; then + if [[ ${select_result} =~ "HMPI-GCC" ]]; then + hmpi_package_name=${openeuler20_03_lts_hmpi_gcc_name} + elif [[ ${select_result} =~ "HMPI-BISHENG" ]]; then + hmpi_package_name=${openeuler20_03_lts_hmpi_bisheng_name} + fi + fi +} + +check_software_installed() { + # Check the installed software + case $1 in + "HMPI-GCC"|"HMPI-BISHENG") + hmpi_gcc_install_status=${FAILED} + hmpi_bisheng_install_status=${FAILED} + hyper_install_status=${FAILED} + which mpirun >/dev/null 2>&1 + if [[ $? == 0 ]]; then + hyper_install_status=${SUCCESS} + hmpi_name_string=$(which mpirun | awk -F "/ompi/bin/mpirun" '{print $1}') + if [[ "${hyper_mpi_gcc_package_names[@]}" =~ "${hmpi_name_string##*/}" ]];then + hmpi_gcc_install_status=${SUCCESS} + fi + if [[ "${hyper_mpi_bisheng_package_names[@]}" =~ "${hmpi_name_string##*/}" ]];then + hmpi_bisheng_install_status=${SUCCESS} + fi + fi + ;; + "GCC") + if gcc -v 2>&1 | grep -q "Kunpeng gcc 10.3.1-2.0.0.b020"; then + gcc_install_status=${SUCCESS} + else + gcc_install_status=${FAILED} + if grep -q "gcc-10.3.1-2021.09-aarch64-linux" /etc/profile; then + gcc_install_status=${SUCCESS} + fi + fi + ;; + "BISHENG") + # clang -v Standard errot output 2>&1 + check_system_bisheng_status + ;; + "KML") + [[ ${install_package_kind} == "rpm" ]] && result=$(${install_package_kind} -qa ${boost_math_name}) || result=$(${install_package_kind} -l ${boost_math_name}) + [[ "${result}" ]] && kml_install_status=${SUCCESS} || kml_install_status=${FAILED} + ;; + esac +} + +check_system_gcc_status() { + # Check whether the GCC version in the system is supported. + install_reply=$1 + [[ ${install_reply} == "kml" ]] && gcc_support_version='7.3.0' || gcc_support_version='9.3.0' + gcc_version=$(gcc --version 2>&1 | head -n 1 | grep -Po "\d+\.\d+\.\d+" | head -n 1) + if [[ ${install_reply} == "kml" ]]; then + version_ge ${gcc_version} ${gcc_support_version} + [[ "$?" == "0" ]] && gcc_kml_check_status=${SUCCESS} || gcc_kml_check_status=${FAILED} + else + [[ ${gcc_support_version} == ${gcc_version} ]] && gcc_hmpi_check_status=${SUCCESS} || gcc_hmpi_check_status=${FAILED} + fi +} + +check_system_bisheng_status() { + # Check whether the Bisheng version in the system is supported. + if clang -v 2>&1 | grep -q "HUAWEI BiSheng Compiler 2.1.0.B010 clang version 12.0.0"; then + bisheng_check_status=${SUCCESS} + else + bisheng_check_status=${FAILED} + if grep -q "bisheng-compiler-2.1.0-aarch64-linux" /etc/profile; then + bisheng_check_status=${SUCCESS} + fi + fi +} + +set_software_choose_status() { + # Set the status of the software selected by the user. + [[ "${select_result}" =~ ^GCC*$|,GCC* ]] && gcc_choose_status=${SUCCESS} || gcc_choose_status=${FAILED} + [[ "${select_result}" =~ ^BISHENG*$|,BISHENG* ]] && bisheng_choose_status=${SUCCESS} || bisheng_choose_status=${FAILED} + [[ "${select_result}" =~ "HMPI-GCC" ]] && hmpi_gcc_choose_status=${SUCCESS} || hmpi_gcc_choose_status=${FAILED} + [[ "${select_result}" =~ "HMPI-BISHENG" ]] && hmpi_bisheng_choose_status=${SUCCESS} || hmpi_bisheng_choose_status=${FAILED} + [[ "${select_result}" =~ "KML" ]] && kml_choose_status=${SUCCESS} || kml_choose_status=${FAILED} +} + +install_hyper_mpi_env_check() { + # Check the hyper mpi installation environment. + hmpi_type=$1 + [[ ${hmpi_type} == "gcc" ]] && hmpi_choose_status=${hmpi_gcc_choose_status} || hmpi_choose_status=${hmpi_bisheng_choose_status} + if [[ ${hmpi_choose_status} == ${FAILED} ]]; then + return 1 + fi + [[ ${hmpi_type} == "gcc" ]] && hmpi_install_status=${hmpi_gcc_install_status} || hmpi_install_status=${hmpi_bisheng_install_status} + [[ ${hmpi_type} == "gcc" ]] && compiler_choose_status=${gcc_choose_status} || compiler_choose_status=${bisheng_choose_status} + [[ ${hmpi_type} == "gcc" ]] && compiler_hmpi_check_status=${gcc_hmpi_check_status} || compiler_hmpi_check_status=${bisheng_check_status} + logger "Start installing the HMPI-${hmpi_type^^}." ${TIP_COLOR_CHECKING} + unset miss_package + if [[ ! -f ${install_package_dir}/hyper_mpi/"${hmpi_package_name}.tar.gz" ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + fi + if [[ ${hyper_install_status} == ${SUCCESS} ]];then + if [[ ${hmpi_gcc_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "gcc" ]];then + answer_msg="The HPMI-${hmpi_type^^} already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + if [[ ${hmpi_gcc_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "bisheng" ]];then + answer_msg="The HPMI-GCC already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + if [[ ${hmpi_bisheng_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "gcc" ]];then + answer_msg="The HPMI-BISHENG already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + if [[ ${hmpi_bisheng_install_status} == ${SUCCESS} ]] && [[ ${hmpi_type} == "bisheng" ]];then + answer_msg="The HPMI-${hmpi_type^^} already exists. Are you sure you want to continue installing the HPMI-${hmpi_type^^}?" + fi + logger "Hyper-mpi is installed in this system" ${TIP_COLOR_WARNING} + read_answer "${answer_msg}" + if [[ $? != 0 ]]; then + logger "Do not install the hyper-mpi repeatedly." ${TIP_COLOR_ECHO} + return 1 + fi + fi + if [[ ${compiler_hmpi_check_status} == ${SUCCESS} ]]; then + hand_precondition_mpi + return 0 + fi + [[ ${hmpi_type} == "gcc" ]] && logger "The gcc version must be 9.3.0 in the system where the hmpi-gcc is to be installed" ${TIP_COLOR_WARNING} + [[ ${hmpi_type} == "gcc" ]] && miss_package[${#miss_package[*]}]="${hmpi_type}(9.3.0)" + hand_precondition_mpi +} + +install_kml_env_check() { + # Check the math library + if [[ ${kml_choose_status} == ${FAILED} ]]; then + return 1 + fi + logger "Start installing the KML." ${TIP_COLOR_CHECKING} + check_precondition_kml ${install_package_kind} + if [[ ${install_package_kind} == "rpm" ]] && [[ ! -f ${install_package_dir}/kml/${boost_math_rpm_name}.rpm ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + elif [[ ${install_package_kind} == "dpkg" ]] && [[ ! -f ${install_package_dir}/kml/${boost_math_deb_name}.deb ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + fi + if [[ ${kml_install_status} == ${SUCCESS} ]]; then + logger "The KML already exists. Are you sure you want to continue installing the KML?" + read_answer "The KML already exists. Are you sure you want to continue installing the KML?" + if [[ $? != 0 ]]; then + logger "The KML already exists. Are you sure you want to continue installing the KML? N" + logger "Do not install the KML repeatedly." ${TIP_COLOR_FAILED} + return 1 + fi + fi + if [[ ${gcc_kml_check_status} == ${SUCCESS} ]]; then + hand_precondition_kml + return 0 + fi + miss_package_kml[${#miss_package_kml[*]}]='gcc(>=7.3.0)' + hand_precondition_kml +} + +install_compiler_env_check() { + # Check the compiler before installation. + local compiler_type=$1 + [[ ${compiler_type} == "gcc" ]] && compiler_choose_status=${gcc_choose_status} || compiler_choose_status=${bisheng_choose_status} + if [[ ${compiler_choose_status} == ${SUCCESS} ]]; then + [[ ${compiler_type} == "gcc" ]] && compiler_install_status=${gcc_install_status} || compiler_install_status=${bisheng_check_status} + [[ ${compiler_type} == "gcc" ]] && compiler_name=${gcc_compiler_name} || compiler_name=${bisheng_compiler_name} + check_precondition_compiler ${compiler_type} + logger "Start installing the ${compiler_type^^}." ${TIP_COLOR_CHECKING} + if [[ ! -f ${install_package_dir}/${compiler_type}/"${compiler_name}.tar.gz" ]]; then + logger "The installation package cannot be found." ${TIP_COLOR_SUCCESS} + return 1 + fi + # Check whether the compiler is installed. + if [[ ${compiler_install_status} == ${SUCCESS} ]]; then + logger "The ${compiler_type^^} already exists. Are you sure you want to continue installing the ${compiler_type^^}?" + read_answer "The ${compiler_type^^} already exists. Are you sure you want to continue installing the ${compiler_type^^}?" + if [[ $? != 0 ]]; then + logger "Do not install the ${compiler_type^^} repeatedly." ${TIP_COLOR_FAILED} + return 1 + fi + fi + if [[ ${compiler_type} == "gcc" ]];then + hand_precondition_compiler "gcc" + else + hand_precondition_compiler "bisheng" + fi + [[ $? == 1 ]] && return 1 + fi + if [[ ${compiler_type} == "gcc" ]]; then + # Check whether the GCC in the systecm meets the requirements. If no, add a mark. + check_system_gcc_status "kml" + check_system_gcc_status "hmpi" + else + check_system_bisheng_status + fi +} + +install_hyper_mpi() { + # Install Hyper MPI + user_customize_path 'hyper-mpi' + logger "You choose to install Hyper MPI in the $( + cd ${customize_path} + pwd + ) directory." ${TIP_COLOR_SUCCESS} + cd ${install_package_dir}/hyper_mpi + [[ ${hmpi_gcc_choose_status} == 1 ]] && install_hyper_mpi_name="hyper_mpi_gcc" + [[ ${hmpi_bisheng_choose_status} == 1 ]] && install_hyper_mpi_name="hyper_mpi_bisheng" + del_hyper_mpi "${install_hyper_mpi_name}" + if [[ $? == 1 ]];then + return 1 + fi + cd ${install_package_dir}/hyper_mpi + install_hmpi_path=${customize_path}hyper_mpi/${install_hyper_mpi_name} + if [ ! -d "${install_hmpi_path}" ]; then + mkdir -p ${install_hmpi_path} + fi + tar -xf ${hmpi_package_name}.tar.gz -C ${install_hmpi_path} + cd ${install_hmpi_path}/${hmpi_package_name} + # Suggestions for setting Hyper MPI environment variables + command_pwd=" echo 'hwmpi=$PWD' >> ~/.bashrc" + command_opal_prefix=" echo 'export OPAL_PREFIX=\${hwmpi}/ompi' >> ~/.bashrc" + command_path=" echo 'export PATH=\${hwmpi}/ompi/bin:\${hwmpi}/ucx/bin:\$PATH' >> ~/.bashrc" + command_include=" echo 'export INCLUDE=\${hwmpi}/ompi/include:\${hwmpi}/ucx/include:\$INCLUDE' >> ~/.bashrc" + command_ld_library_path=" echo 'export LD_LIBRARY_PATH=\${hwmpi}/ompi/lib:\${hwmpi}/ucx/lib:\$LD_LIBRARY_PATH' >> ~/.bashrc" + logger "Hyper MPI is installed." + if [[ ${hmpi_gcc_choose_status} == 1 ]]; then + change_modules "HMPI-GCC" + hmpi_gcc_installed=1 + sed -i "s#hyper_mpi_gcc=.*#hyper_mpi_gcc=${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#hyper_mpi_gcc_install=.*#hyper_mpi_gcc_install=${install_hmpi_path}/${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + elif [[ ${hmpi_bisheng_choose_status} == 1 ]]; then + change_modules "HMPI-BISHENG" + hmpi_bisheng_installed=1 + sed -i "s#hyper_mpi_bisheng=.*#hyper_mpi_bisheng=${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#hyper_mpi_bisheng_install=.*#hyper_mpi_bisheng_install=${install_hmpi_path}/${hmpi_package_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + fi + change_directory_owner "${install_hmpi_path}/${hmpi_package_name}" + change_directory_permissions "${install_hmpi_path}/${hmpi_package_name}" "hyper-mpi" + [[ "${install_hyper_mpi_name}" == "hyper_mpi_bisheng" ]] && install_hyper_mpi_tip="HMPI-BISHENG" || install_hyper_mpi_tip="HMPI-GCC" + logger "To make the related commands take effect, run the following command:" ${TIP_COLOR_WARNING} + logger "${command_pwd}" ${TIP_COLOR_COMMAND} + logger "${command_opal_prefix}" ${TIP_COLOR_COMMAND} + logger "${command_path}" ${TIP_COLOR_COMMAND} + logger "${command_include}" ${TIP_COLOR_COMMAND} + logger "${command_ld_library_path}" ${TIP_COLOR_COMMAND} + logger " source ~/.bashrc" ${TIP_COLOR_COMMAND} + logger "Use module set env for ${install_hyper_mpi_tip}" ${TIP_COLOR_SUCCESS} + logger " module load ${show_modulefile_path}" ${TIP_COLOR_COMMAND} + logger "The ${install_hyper_mpi_tip} is installed." ${TIP_COLOR_SUCCESS} +} + +install_compiler() { + # Install compiler + local compiler_type=$1 + user_customize_path "${compiler_type} compiler" + logger "you choose install ${compiler_type} path is $(cd ${customize_path};pwd)" ${TIP_COLOR_SUCCESS} + del_compiler "${compiler_type}" + if [[ $? == 1 ]];then + return 1 + fi + cd ${install_package_dir}/${compiler_type} + install_compiler_path=${customize_path}${compiler_type} + if [ ! -d ${install_compiler_path} ]; then + mkdir -p ${install_compiler_path} + fi + tar -xf ${compiler_name}.tar.gz -C ${install_compiler_path} + cd ${install_compiler_path}/${compiler_name} + if [[ ${compiler_type} == "bisheng" ]]; then + change_modules "BISHENG" + bisheng_installed=1 + sed -i "s#compiler_bisheng=.*#compiler_bisheng=${compiler_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#compiler_bisheng_install=.*#compiler_bisheng_install=${install_compiler_path}#g" ${current_dir}/configure_environment_${time_stamp}.sh + else + change_modules "GCC" + gcc_installed=1 + sed -i "s#compiler_gcc=.*#compiler_gcc=${compiler_name}#g" ${current_dir}/configure_environment_${time_stamp}.sh + sed -i "s#compiler_gcc_install=.*#compiler_gcc_install=${install_compiler_path}#g" ${current_dir}/configure_environment_${time_stamp}.sh + fi + if [[ ${compiler_type} == "gcc" ]]; then + command_env_path=" echo 'export PATH=${install_compiler_path}/${compiler_name}/bin:\$PATH' >>/etc/profile" + command_env_include=" echo 'export INCLUDE=${install_compiler_path}/${compiler_name}/INCLUDE:\$INCLUDE' >>/etc/profile" + command_env_ld_library_path=" echo 'export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_name}/lib64:\$LD_LIBRARY_PATH' >>/etc/profile" + command_module=" module load ${show_modulefile_path}" + fi + if [[ ${compiler_type} == "bisheng" ]]; then + command_env_path=" echo 'export PATH=${install_compiler_path}/${compiler_name}/bin:\$PATH' >>/etc/profile" + command_env_ld_library_path=" echo 'export LD_LIBRARY_PATH=${install_compiler_path}/${compiler_name}/lib:\$LD_LIBRARY_PATH' >>/etc/profile" + command_module=" module load ${show_modulefile_path}" + fi + change_directory_owner "${install_compiler_path}/${compiler_name}" + change_directory_permissions "${install_compiler_path}/${compiler_name}" "${compiler_type}" + logger "To make the related commands take effect, run the following command:" ${TIP_COLOR_WARNING} + [[ ${command_env_path} ]] && logger "${command_env_path}" ${TIP_COLOR_COMMAND} + [[ ${command_env_include} && ${compiler_type} == "gcc" ]] && logger "${command_env_include}" ${TIP_COLOR_COMMAND} + [[ ${command_env_ld_library_path} ]] && logger "${command_env_ld_library_path}" ${TIP_COLOR_COMMAND} + + logger " source /etc/profile" ${TIP_COLOR_COMMAND} + logger "use module set env for $compiler_type" ${TIP_COLOR_SUCCESS} + logger "${command_module}" ${TIP_COLOR_COMMAND} + logger "The ${compiler_type} Compiler is installed." ${TIP_COLOR_SUCCESS} +} + +install_math_kml() { + # Install KML + check_space /usr/local + if [[ ${install_package_kind} == "rpm" ]]; then + $install_package_kind -ivh ${install_package_dir}/kml/${boost_math_rpm_name}.rpm + else + $install_package_kind -i ${install_package_dir}/kml/${boost_math_deb_name}.deb + fi + if [[ $? -ne 0 ]];then + logger "Failed to install the math library." ${TIP_COLOR_FAILED} + return 1 + fi + nm_math_kml + if [[ $? -ne 0 ]];then + logger "Failed to install the math library." ${TIP_COLOR_FAILED} + return 1 + fi + logger "To make the related commands take effect, run the following command: source /etc/profile" ${TIP_COLOR_WARNING} + logger "The math library is installed." ${TIP_COLOR_SUCCESS} +} + +nm_math_kml() { + # Add math library symbols + # /usr/local/kml/lib is the default path for installing the math library. + logger "Generating a Complete LAPACK..." ${TIP_COLOR_CHECKING} + cp -rf ${install_package_dir}/kml/liblapack_adapt.a /usr/local/kml/lib + cp -rf ${install_package_dir}/kml/libblas.a /usr/local/kml/lib + cd /usr/local/kml/lib + klapack=/usr/local/kml/lib/libklapack.a + # get symbols defined both in klapack and netlib lapack + nm -g liblapack_adapt.a | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq >netlib.sym + nm -g $klapack | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq >klapack.sym + comm -12 klapack.sym netlib.sym >comm.sym + + # update symbols name of liblapack_adapt.a + while read sym; do + if ! nm liblapack_adapt.a | grep -qe " T ${sym}_\$"; then + continue + fi + ar x liblapack_adapt.a $sym.f.o >/dev/null 2>&1 + mv $sym.f.o ${sym}_netlib.f.o + objcopy --redefine-sym ${sym}_=${sym}_netlib_ ${sym}_netlib.f.o + ar d liblapack_adapt.a ${sym}.f.o >/dev/null 2>&1 + ar ru liblapack_adapt.a ${sym}_netlib.f.o >/dev/null 2>&1 + rm ${sym}_netlib.f.o + done gdb.log +for proc in $process +do + echo "**************Process $proc**************" >> gdb.log + # 使用GDB获取进程的堆栈信息 + gdb -ex "attach $proc" -ex "thread apply all bt" -ex "detach" -ex "quit" -batch >> gdb.log + echo "******************************************">> gdb.log +done -- Gitee From 65adb6c1f3635af556cc4d778e196edde7d28dde Mon Sep 17 00:00:00 2001 From: iotwins Date: Wed, 20 Sep 2023 20:08:01 +0800 Subject: [PATCH 2/2] Add osu examples --- package/kml/2.1.0/bisheng/install.sh | 103 ++++++++++++++++++++++++ package/kml/2.1.0/gcc/install.sh | 102 +++++++++++++++++++++++ package/osu/1.0.0/install.sh | 2 +- package/osu/7.2.0/install.sh | 11 +++ src/installService.py | 16 +++- templates/OSU/5.3/osu.opensource.config | 38 +++++++++ 6 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 package/kml/2.1.0/bisheng/install.sh create mode 100644 package/kml/2.1.0/gcc/install.sh create mode 100644 package/osu/7.2.0/install.sh create mode 100644 templates/OSU/5.3/osu.opensource.config diff --git a/package/kml/2.1.0/bisheng/install.sh b/package/kml/2.1.0/bisheng/install.sh new file mode 100644 index 0000000..fdc84b3 --- /dev/null +++ b/package/kml/2.1.0/bisheng/install.sh @@ -0,0 +1,103 @@ +#!/bin/bash +set -x +set -e +kml_version=2.1.0 +. ${DOWNLOAD_TOOL} -u https://kunpeng-repo.obs.cn-north-4.myhuaweicloud.com/Kunpeng%20BoostKit/Kunpeng%20BoostKit%2023.0.RC2/BoostKit-kml_${kml_version}_bisheng.zip +. ${DOWNLOAD_TOOL} -u https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.1.tar.gz -f lapack-3.10.1.tar.gz +. ${DOWNLOAD_TOOL} -u https://github.com/Reference-ScaLAPACK/scalapack/archive/refs/tags/v2.2.0.tar.gz -f scalapack-2.2.0.tar.gz + +cd ${JARVIS_TMP} +rm -rf boostkit-kml-${kml_version}-1.aarch64.rpm +unzip -o ${JARVIS_DOWNLOAD}/BoostKit-kml_${kml_version}_bisheng.zip +rpm --force --nodeps -ivh --prefix=$1 boostkit-kml-${kml_version}-1.aarch64.rpm +mv $1/kml/* $1/ + +# generate full lapack +netlib=${JARVIS_DOWNLOAD}/lapack-3.10.1.tar.gz +netlib2=${JARVIS_DOWNLOAD}/scalapack-2.2.0.tar.gz +klapack=$1/lib/libklapack.a +kservice=$1/lib/libkservice.a +kscalapack=$1/lib/libkscalapack.a +kblas=$1/lib/kblas/omp/libkblas.so +echo $netlib +echo $klapack +echo $netlib2 +echo $kscalapack + +# build netlib lapack +cd ${JARVIS_TMP} +rm -rf netlib +mkdir netlib +cd netlib +tar zxvf $netlib +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_DEPRECATED=ON ../lapack-3.10.1 +make -j +cd ../ + +cp build/lib/liblapack.a liblapack_adapt.a + +# get symbols defined both in klapack and netlib lapack +nm -g liblapack_adapt.a | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > netlib.sym +nm -g $klapack | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > klapack.sym +comm -12 klapack.sym netlib.sym > comm.sym + +objcopy -W dsecnd_ -W second_ liblapack_adapt.a + +# add _netlib_ postfix to symbols in liblapack_adapt.a (e.g. dgetrf_netlib_) +while read sym; do \ + if ! nm liblapack_adapt.a | grep -qe " T ${sym}_\$"; then \ + continue; \ + fi; \ + ar x liblapack_adapt.a $sym.f.o; \ + mv $sym.f.o ${sym}_netlib.f.o; \ + objcopy --redefine-sym ${sym}_=${sym}_netlib_ ${sym}_netlib.f.o; \ + ar d liblapack_adapt.a ${sym}.f.o; \ + ar ru liblapack_adapt.a ${sym}_netlib.f.o; \ + rm -rf ${sym}_netlib.f.o; \ +done < comm.sym + +# (optional) build a full lapack shared library +clang -o libklapack_full.so -shared -fPIC -Wl,--whole-archive $klapack liblapack_adapt.a $kservice -Wl,--no-whole-archive -fopenmp -lpthread -lflang -lm + +\cp libklapack_full.so $1/lib/ + +# build netlib2 scalapack +cd ${JARVIS_TMP} +rm -rf netlib2 +mkdir netlib2 +cd netlib2 +tar zxvf $netlib2 +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_Fortran_COMPILER=mpifort -DLAPACK_LIBRARIES=$1/lib/libklapack_full.so -DBLAS_LIBRARIES=$kblas ../scalapack-2.2.0 +make -j +cd ../ + +cp ../netlib/build/lib/liblapack.a liblapack_adapt.a +cp build/lib/libscalapack.a libscalapack_adapt.a + +nm -g libscalapack_adapt.a | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > netlib.sym +nm -g $kscalapack | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > kscalapack.sym +comm -12 kscalapack.sym netlib.sym > comm.sym +# update symbols name of libscalapack_adapt.a +while read sym; do \ + if ! nm libscalapack_adapt.a | grep -qe " T ${sym}_\$"; then \ + continue; \ + fi; \ + ar x libscalapack_adapt.a $sym.f.o; \ + mv $sym.f.o ${sym}_netlib.f.o; \ + objcopy --redefine-sym ${sym}_=${sym}_netlib_ ${sym}_netlib.f.o; \ + ar d libscalapack_adapt.a ${sym}.f.o; \ + ar ru libscalapack_adapt.a ${sym}_netlib.f.o; \ + rm -rf ${sym}_netlib.f.o; \ +done < comm.sym + +clang -o libkscalapack_full.so -shared -fPIC -Wl,--whole-archive $kscalapack libscalapack_adapt.a -Wl,--no-whole-archive $klapack liblapack_adapt.a $kservice -fopenmp -lpthread -lflang -lm + +\cp libkscalapack_full.so $1/lib/ +echo "Generated liblapack_adapt.a and libklapack_full.so" +echo "Generated libscalapack_adapt.a and libkscalapack_full.so" + +exit 0 diff --git a/package/kml/2.1.0/gcc/install.sh b/package/kml/2.1.0/gcc/install.sh new file mode 100644 index 0000000..d9e3981 --- /dev/null +++ b/package/kml/2.1.0/gcc/install.sh @@ -0,0 +1,102 @@ +#!/bin/bash +set -x +set -e +kml_version=2.1.0 +. ${DOWNLOAD_TOOL} -u https://kunpeng-repo.obs.cn-north-4.myhuaweicloud.com/Kunpeng%20BoostKit/Kunpeng%20BoostKit%2023.0.RC2/BoostKit-kml_${kml_version}.zip +. ${DOWNLOAD_TOOL} -u https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.1.tar.gz -f lapack-3.10.1.tar.gz +. ${DOWNLOAD_TOOL} -u https://github.com/Reference-ScaLAPACK/scalapack/archive/refs/tags/v2.2.0.tar.gz -f scalapack-2.2.0.tar.gz + +cd ${JARVIS_TMP} +rm -rf boostkit-kml-${kml_version}-1.aarch64.rpm +unzip -o ${JARVIS_DOWNLOAD}/BoostKit-kml_${kml_version}.zip +rpm --force --nodeps -ivh --relocate /usr/local/kml=$1 --badreloc=$1 boostkit-kml-${kml_version}-1.aarch64.rpm + +# generate full lapack +netlib=${JARVIS_DOWNLOAD}/lapack-3.10.1.tar.gz +netlib2=${JARVIS_DOWNLOAD}/scalapack-2.2.0.tar.gz +klapack=$1/lib/libklapack.a +kservice=$1/lib/libkservice.a +kscalapack=$1/lib/libkscalapack.a +kblas=$1/lib/kblas/omp/libkblas.so +echo $netlib +echo $klapack +echo $netlib2 +echo $kscalapack + +# build netlib lapack +cd ${JARVIS_TMP} +rm -rf netlib +mkdir netlib +cd netlib +tar zxvf $netlib +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_DEPRECATED=ON ../lapack-3.10.1 +make -j +cd ../ + +cp build/lib/liblapack.a liblapack_adapt.a + +# get symbols defined both in klapack and netlib lapack +nm -g liblapack_adapt.a | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > netlib.sym +nm -g $klapack | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > klapack.sym +comm -12 klapack.sym netlib.sym > comm.sym + +objcopy -W dsecnd_ -W second_ liblapack_adapt.a + +# add _netlib_ postfix to symbols in liblapack_adapt.a (e.g. dgetrf_netlib_) +while read sym; do \ + if ! nm liblapack_adapt.a | grep -qe " T ${sym}_\$"; then \ + continue; \ + fi; \ + ar x liblapack_adapt.a $sym.f.o; \ + mv $sym.f.o ${sym}_netlib.f.o; \ + objcopy --redefine-sym ${sym}_=${sym}_netlib_ ${sym}_netlib.f.o; \ + ar d liblapack_adapt.a ${sym}.f.o; \ + ar ru liblapack_adapt.a ${sym}_netlib.f.o; \ + rm -rf ${sym}_netlib.f.o; \ +done < comm.sym + +# (optional) build a full lapack shared library +gcc -o libklapack_full.so -shared -fPIC -Wl,--whole-archive $klapack liblapack_adapt.a $kservice -Wl,--no-whole-archive -fopenmp -lpthread -lgfortran -lm + +\cp libklapack_full.so $1/lib/ + +# build netlib2 scalapack +cd ${JARVIS_TMP} +rm -rf netlib2 +mkdir netlib2 +cd netlib2 +tar zxvf $netlib2 +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_Fortran_COMPILER=mpifort -DLAPACK_LIBRARIES=$1/lib/libklapack_full.so -DBLAS_LIBRARIES=$kblas ../scalapack-2.2.0 +make -j +cd ../ + +cp ../netlib/build/lib/liblapack.a liblapack_adapt.a +cp build/lib/libscalapack.a libscalapack_adapt.a + +nm -g libscalapack_adapt.a | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > netlib.sym +nm -g $kscalapack | grep 'T ' | grep -oP '\K\w+(?=_$)' | sort | uniq > kscalapack.sym +comm -12 kscalapack.sym netlib.sym > comm.sym +# update symbols name of libscalapack_adapt.a +while read sym; do \ + if ! nm libscalapack_adapt.a | grep -qe " T ${sym}_\$"; then \ + continue; \ + fi; \ + ar x libscalapack_adapt.a $sym.f.o; \ + mv $sym.f.o ${sym}_netlib.f.o; \ + objcopy --redefine-sym ${sym}_=${sym}_netlib_ ${sym}_netlib.f.o; \ + ar d libscalapack_adapt.a ${sym}.f.o; \ + ar ru libscalapack_adapt.a ${sym}_netlib.f.o; \ + rm -rf ${sym}_netlib.f.o; \ +done < comm.sym + +gcc -o libkscalapack_full.so -shared -fPIC -Wl,--whole-archive $kscalapack libscalapack_adapt.a -Wl,--no-whole-archive $klapack liblapack_adapt.a $kservice -fopenmp -lpthread -lgfortran -lm + +\cp libkscalapack_full.so $1/lib/ +echo "Generated liblapack_adapt.a and libklapack_full.so" +echo "Generated libscalapack_adapt.a and libkscalapack_full.so" + +exit 0 diff --git a/package/osu/1.0.0/install.sh b/package/osu/1.0.0/install.sh index 5540f6c..f7b7afb 100755 --- a/package/osu/1.0.0/install.sh +++ b/package/osu/1.0.0/install.sh @@ -7,5 +7,5 @@ rm -rf osu-micro-benchmarks-master unzip ${JARVIS_DOWNLOAD}/osu-micro-benchmarks.zip cd osu-micro-benchmarks-master ./configure --prefix=$1 CC=mpicc CXX=mpicxx -make +make -j32 make install diff --git a/package/osu/7.2.0/install.sh b/package/osu/7.2.0/install.sh new file mode 100644 index 0000000..1f1c561 --- /dev/null +++ b/package/osu/7.2.0/install.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -x +set -e +. ${DOWNLOAD_TOOL} -u https://mvapich.cse.ohio-state.edu/download/mvapich/osu-micro-benchmarks-7.2.tar.gz -f osu-micro-benchmarks-7.2.tar.gz +cd ${JARVIS_TMP} +rm -rf osu-micro-benchmarks-7.2 +tar -xzvf ${JARVIS_DOWNLOAD}/osu-micro-benchmarks-7.2.tar.gz +cd osu-micro-benchmarks-7.2 +./configure --prefix=$1 CC=mpicc CXX=mpicxx +make -j32 +make install diff --git a/src/installService.py b/src/installService.py index e99f0ad..609e9e0 100644 --- a/src/installService.py +++ b/src/installService.py @@ -275,6 +275,19 @@ class InstallService: file_list = [d for d in glob(abs_path+'/**', recursive=True)] return file_list + def add_special_library_path(self, install_path, sname, libs_dir): + prefix = install_path.replace(install_path, "$prefix") + if "kml" in sname: + libs_dir.append(os.path.join(prefix, "lib/kblas/nolocking")) + libs_dir.append(os.path.join(prefix, "lib/kblas/pthread")) + libs_dir.append(os.path.join(prefix, "lib/kblas/omp")) + libs_dir.append(os.path.join(prefix, "lib/kblas/locking")) + libs_dir.append(os.path.join(prefix, "lib/kvml/single")) + libs_dir.append(os.path.join(prefix, "lib/kvml/multi")) + libs_dir.append(os.path.join(prefix, "lib/kspblas/single")) + libs_dir.append(os.path.join(prefix, "lib/kspblas/multi")) + return libs_dir + def get_module_file_content(self, install_path, sname, sversion): module_file_content = '' file_list = self.get_files(install_path) @@ -298,6 +311,7 @@ class InstallService: libs_dir.append(file.replace(install_path, "$prefix")) elif last_dir in incs_dir_type: incs_dir.append(file.replace(install_path, "$prefix")) + self.add_special_library_path(install_path, sname, libs_dir) if len(bins_dir) >= 1: bins_str = "prepend-path PATH "+':'.join(bins_dir) if len(libs_dir) >= 1: @@ -335,7 +349,7 @@ setenv {sname.upper().replace('-','_')}_PATH {install_path} if not self.is_installed(install_path): return '' # if install_path is empty, The module file should not generated. - if len(os.listdir(install_path)) == 1: + if len(os.listdir(install_path)) == 0: print('module file did not generated because no file generated under install path') return '' if stype == SType.MPI: diff --git a/templates/OSU/5.3/osu.opensource.config b/templates/OSU/5.3/osu.opensource.config new file mode 100644 index 0000000..5f8d308 --- /dev/null +++ b/templates/OSU/5.3/osu.opensource.config @@ -0,0 +1,38 @@ +[SERVER] +11.11.11.11 + +[DEPENDENCY] +set -e +set -x +module purge +gcc_version=$(gcc --version | awk 'NR==1{print $NF}') +module use ./software/moduledeps/gcc${gcc_version} +./jarvis -install hmpi/1.2.0 gcc +module load hmpi/1.2.0 +./jarvis -install osu/7.2.0 gcc+mpi +#test if mpi is normal +./jarvis -bench mpi +mkdir -p osu + +[ENV] +module purge +gcc_version=$(gcc --version | awk 'NR==1{print $NF}') +module use ./software/moduledeps/gcc${gcc_version} +module load hmpi/1.2.0 +module load osu/7.2.0 + +[APP] +app_name = OSU +build_dir = ${OSU_PATH}/ +binary_dir = ${OSU_PATH}/libexec/osu-micro-benchmarks/mpi/collective +case_dir = ./osu + +[BUILD] + +[CLEAN] +./jarvis -remove osu + +[RUN] +run = mpirun -np 16 --bind-to core -mca pml ucx -mca osc ^ucx -mca btl ^vader,tcp,openib -x UCX_TLS=rc_x +binary = osu_allgather -m 32:4096 --validation --type mpi_int +nodes = 1 \ No newline at end of file -- Gitee