CMake:Added cmake for bench

CMakelists.txt is added in bench.
Steps are provided to build for different targets.

AMD-Internal: [CPUPL-2748]
Change-Id: I58027f4e42d1323cafb151224c45868bc8337ff4
This commit is contained in:
jagar
2024-01-16 11:10:50 +05:30
committed by Jagadish1 R
parent abc414f2ec
commit 40b1af4c3f
4 changed files with 287 additions and 125 deletions

View File

@@ -507,7 +507,7 @@ if(ENABLE_MIXED_DT)
else()
message(" Mixed datatype optimizations requiring extra memory are disabled.")
set(ENABLE_MIXED_DT_EXTRA_MEM_01 0)
endif()
endif()
set(ENABLE_MIXED_DT_01 1)
else()
message(" Mixed datatype support is disabled.")
@@ -1026,7 +1026,7 @@ endif()
# --- Library name and local paths ---
# From old CMake
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${CMake_MSVC_PARALLEL}")
@@ -1095,41 +1095,20 @@ if(ENABLE_BLAS)
add_subdirectory(blastest EXCLUDE_FROM_ALL)
endif()
if(ENABLE_BLAS AND WIN32 AND BUILD_SHARED_LIBS)
set(DETAILED_BLATEST_MESSAGE "Details: Level2 and level3 API tests define a custom version of xerbla_() to test the error codes. \
On Linux and on Windows/static versions of BLIS library, the custom xerbla_() gets called inside the library\
due to the linking process and all tests work. On Windows/shared version of the library, symbol resolution\
happens at load-time so the blis implementation of xerbla_() gets called instead of the custom one. \
That causes errors when the tests are run which are independent of the BLIS library. \
Please use static builds only on Windows.")
endif()
# Add generic testing target `test`.
set(available_testsuites checkblis)
if(WIN32 AND BUILD_SHARED_LIBS)
if(ENABLE_BLAS)
set(TEST_WARNING "Target `test` depends only on target `checkblis` because `checkblas` target is not available on Windows for shared builds of BLIS. ")
endif()
else()
if(ENABLE_BLAS)
list(APPEND available_testsuites checkblas)
endif()
if(ENABLE_BLAS)
list(APPEND available_testsuites checkblas)
endif()
add_custom_target(test
DEPENDS ${available_testsuites}
COMMENT "Running target `test`. ${TEST_WARNING} ${DETAILED_BLATEST_MESSAGE}")
add_custom_target(test DEPENDS ${available_testsuites})
# Add generic testing target `check`.
set(available_testsuites checkblis-fast)
if(WIN32 AND BUILD_SHARED_LIBS)
if(ENABLE_BLAS)
set(CHECK_WARNING "Target `check` depends only on target `checkblis-fast` because `checkblas` target is not available on Windows for shared builds of BLIS. ")
endif()
else()
if(ENABLE_BLAS)
list(APPEND available_testsuites checkblas)
endif()
if(ENABLE_BLAS)
list(APPEND available_testsuites checkblas)
endif()
add_custom_target(check
DEPENDS ${available_testsuites}
COMMENT "Running target `check`. ${CHECK_WARNING} ${DETAILED_BLATEST_MESSAGE}")
add_subdirectory(bench EXCLUDE_FROM_ALL)

View File

@@ -1,104 +1,167 @@
##Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved.##
add_definitions(-DBLAS="AOCL")
add_definitions(-DN_REPEAT=1000)
add_definitions(-DINT_FS="%lld")
add_definitions(-DUINT_FS="%llu")
add_executable(BenchAmaxv bench_amaxv.c)
target_link_libraries(BenchAmaxv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchAmaxv OpenMP::OpenMP_CXX)
##Copyright (C) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.##
# Comments:
# Set the path to the BLIS installation.
set(BLIS_INSTALL_PATH "" CACHE STRING "Setting the path to a BLIS installation that needs testing.")
if(BLIS_INSTALL_PATH)
message(STATUS "BLIS_INSTALL_PATH :" ${BLIS_INSTALL_PATH})
endif()
target_link_libraries(BenchAmaxv optimized "${LIB_NAME}.lib")
add_executable(BenchAxpbyv bench_axpbyv.c)
target_link_libraries(BenchAxpbyv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchAxpbyv OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchAxpbyv optimized "${LIB_NAME}.lib")
# - DIST_PATH is assumed to not exist if BLIS_INSTALL_PATH is given.
# - We must use recursively expanded assignment for LIB_PATH and INC_PATH in
# the second case because CONFIG_NAME is not yet set.
# Override the value of CINCFLAGS so that the value of CFLAGS returned by
# get-user-cflags-for() is not cluttered up with include paths needed only
# while building BLIS.
add_executable(BenchCopyv bench_copyv.c)
target_link_libraries(BenchCopyv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchCopyv OpenMP::OpenMP_CXX)
#if(NOT DEFINED BLIS_INSTALL_PATH)
if(BLIS_INSTALL_PATH STREQUAL "")
set(DIST_PATH ${CMAKE_BINARY_DIR})
set(LIB_PATH ${DIST_PATH}/lib/${BLIS_CONFIG_FAMILY})
set(INC_PATH ${DIST_PATH}/include/${BLIS_CONFIG_FAMILY})
set(CINFLAGS ${INC_PATH})
set(LIBBLIS libblis)
message(STATUS "CMAKE_BINARY_DIR : " ${DIST_PATH})
else()
set(LIB_PATH ${BLIS_INSTALL_PATH}/lib)
set(INC_PATH ${BLIS_INSTALL_PATH}/include)
set(CINFLAGS ${INC_PATH})
# Set up the library name.
if(WIN32)
set(LIB_BLIS AOCL-LibBlis-Win)
else()
set(LIB_BLIS libblis)
endif()
# Append if threading is required.
if(NOT (ENABLE_THREADING STREQUAL "no"))
if(WIN32)
string(APPEND LIB_BLIS -MT)
else()
string(APPEND LIB_BLIS -mt)
endif()
endif()
# Append for dll if necessary.
if(WIN32 AND BUILD_SHARED_LIBS)
string(APPEND LIB_BLIS -dll)
endif()
# Setting the suffix for find_library().
if(WIN32)
set(LIB_BLIS .lib)
else()
if(BUILD_SHARED_LIBS)
string(APPEND LIB_BLIS .so)
else()
string(APPEND LIB_BLIS .a)
endif()
endif()
set(LIBBLIS ${LIB_PATH}/${LIB_BLIS})
message(STATUS "BLIS_INSTALL_PATH : " ${LIBBLIS})
endif()
target_link_libraries(BenchCopyv optimized "${LIB_NAME}.lib")
add_executable(BenchDotv bench_dotv.c)
target_link_libraries(BenchDotv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchDotv OpenMP::OpenMP_CXX)
if(WIN32)
set(LIBSUFFIX dll)
else()
set(LIBSUFFIX so)
endif()
target_link_libraries(BenchDotv optimized "${LIB_NAME}.lib")
add_executable(BenchGemm bench_gemm.c)
target_link_libraries(BenchGemm debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchGemm OpenMP::OpenMP_CXX)
set(NREPEATS "1000" CACHE STRING "Set no. of times loop repeats.")
set(MKL_PATH $ENV{MKLROOT} CACHE STRING "Set MKL_PATH.")
if(THREADING_MODEL STREQUAL "no")
set(MKL_THREAD "${MKL_PATH}/libmkl_sequential.${LIBSUFFIX}")
else()
set(MKL_THREAD "${MKL_PATH}/libmkl_gnu_thread.${LIBSUFFIX}")
set(MKL_OMP iomp5)
endif()
target_link_libraries(BenchGemm optimized "${LIB_NAME}.lib")
set(INTEL_LP64 "${MKL_PATH}/libmkl_intel_lp64.${LIBSUFFIX}")
set(MKL_CORE "${MKL_PATH}/libmkl_core.${LIBSUFFIX}")
set(COMMON_LIBS pthread m dl ${MKL_OMP})
set(MKL_LIB ${INTEL_LP64} ${MKL_CORE} ${MKL_THREAD} ${COMMON_LIBS})
set(OPENBLAS_PATH "/home/amd/mylibs/openblas" CACHE STRING "Set OPENBLAS_PATH.")
set(OPENBLAS_LIB "${OPENBLAS_PATH}/libopenblas.${LIBSUFFIX}")
set(ATLAS_PATH "/home/amd/mylibs/atlas" CACHE STRING "Set ATLAS_PATH.")
set(F77BLAS_LIB "${ATLAS_PATH}/libf77blas.${LIBSUFFIX}")
set(ATLAS_LIB "${ATLAS_PATH}/libatlas.${LIBSUFFIX}")
set(ATLAS_LIB ${ATLAS_LIB} ${F77BLAS_LIB})
add_executable(BenchGemmt bench_gemmt.c)
target_link_libraries(BenchGemmt debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchGemmt OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchGemmt optimized "${LIB_NAME}.lib")
add_executable(BenchGemv bench_gemv.c)
target_link_libraries(BenchGemv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchGemv OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchGemv optimized "${LIB_NAME}.lib")
# Include the corresponding make_defs.cmake that holds the required compiler options.
include(${CMAKE_SOURCE_DIR}/config/${BLIS_CONFIG_FAMILY}/make_defs.cmake)
add_executable(BenchGer bench_ger.c)
target_link_libraries(BenchGer debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchGer OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchGer optimized "${LIB_NAME}.lib")
# Gather all local source files.
file(GLOB file_list LIST_DIRECTORIES false RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/" "*.c")
add_executable(BenchNrm2 bench_nrm2.c)
target_link_libraries(BenchNrm2 debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchNrm2 OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchNrm2 optimized "${LIB_NAME}.lib")
set(BENCH_FLAGS -DN_REPEAT=${NREPEATS} -DINT_FS="%lld" -DUINT_FS="%llu")
# Create an executable using the sources above.
function(benchexe extn)
set(dblas "aocl")
if(extn STREQUAL "mkl")
set(BLAS_LIBS ${MKL_LIB})
set(dblas ${extn})
elseif(extn STREQUAL "openblas")
set(BLAS_LIBS ${OPENBLAS_LIB})
set(dblas ${extn})
elseif(extn STREQUAL "atlas")
set(BLAS_LIBS ${ATLAS_LIB})
set(dblas ${extn})
endif()
set(BENCH_FLAGS "${BENCH_FLAGS}" -DBLAS="${dblas}")
foreach(src ${file_list})
string(REGEX REPLACE ".c$" "" exec_name ${src})
set(exec_name "${exec_name}_${extn}")
add_executable(${exec_name}.x ${src})
target_compile_options(${exec_name}.x
PRIVATE
# load-var-for,COPTFLAGS
${COPTFLAGS}
)
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(${exec_name}.x
PRIVATE
# in get-noopt-cflags-for
${VERS_DEF}
"-DBLIS_EXPORT=__declspec(dllimport)"
${BENCH_FLAGS}
)
else()
target_compile_definitions(${exec_name}.x
PRIVATE
# in get-noopt-cflags-for
${VERS_DEF}
${BENCH_FLAGS}
)
endif()
target_include_directories(${exec_name}.x
BEFORE
PRIVATE
# in get-noopt-cflags-for
${CINFLAGS}
)
target_link_libraries(${exec_name}.x PRIVATE ${BLAS_LIBS} ${LIBBLIS} ${LDFLAGS})
if(THREADING_MODEL STREQUAL "openmp")
target_link_libraries(${exec_name}.x PRIVATE OpenMP::OpenMP_C)
endif()
list(APPEND temp_executables ${exec_name}.x)
endforeach()
set(bench_executables ${temp_executables} PARENT_SCOPE)
endfunction()
add_executable(BenchScalv bench_scalv.c)
target_link_libraries(BenchScalv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchScalv OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchScalv optimized "${LIB_NAME}.lib")
benchexe("blis")
add_custom_target(bench_blis DEPENDS ${bench_executables})
benchexe("mkl")
add_custom_target(bench_mkl DEPENDS ${bench_executables})
benchexe("openblas")
add_custom_target(bench_openblas DEPENDS ${bench_executables})
benchexe("atlas")
add_custom_target(bench_atlas DEPENDS ${bench_executables})
add_custom_target(benchmark DEPENDS bench_blis bench_mkl bench_openblas)
add_executable(BenchSwapv bench_swapv.c)
target_link_libraries(BenchSwapv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchSwapv OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchSwapv optimized "${LIB_NAME}.lib")
# Put all those targets under bench-targets folder name so that they appear all together in IDE.
# NOTE : To run bench for atlas, add bench_atlas to the bench-targets
set_target_properties(benchmark bench_blis bench_mkl bench_openblas PROPERTIES FOLDER bench-targets)
add_executable(BenchSyrk bench_syrk.c)
target_link_libraries(BenchSyrk debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchSyrk OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchSyrk optimized "${LIB_NAME}.lib")
add_executable(BenchTrsm bench_trsm.c)
target_link_libraries(BenchTrsm debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchTrsm OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchTrsm optimized "${LIB_NAME}.lib")
add_executable(BenchTrsv bench_trsv.c)
target_link_libraries(BenchTrsv debug "${LIB_NAME}.lib")
if(ENABLE_OPENMP)
target_link_libraries(BenchTrsv OpenMP::OpenMP_CXX)
endif()
target_link_libraries(BenchTrsv optimized "${LIB_NAME}.lib")
# Add bench_aocl_gemm only if aocl_gemm is in the ENABLE_ADDON list.
# This needs to work in cases where both aocl_gemm and gemmd are requested.
# lpgemm_index will be -1 if it's not found in ENABLE_ADDON list.
list(FIND ENABLE_ADDON "aocl_gemm" lpgemm_index)
if(NOT (lpgemm_index STREQUAL -1))
add_subdirectory(bench_aocl_gemm EXCLUDE_FROM_ALL)
endif()

View File

@@ -0,0 +1,55 @@
##Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.##
# Comments:
# Gather all local source files.
file(GLOB file_list LIST_DIRECTORIES false RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/" "*.c")
set(LPGEMM_FLAGS -DBLAS="aocl" -DN_REPEAT=${NREPEATS} -DINT_FS="%ld" -DUINT_FS="%lu")
# Create an executable using the sources above.
function(lpgemmbenchexe extn)
foreach(src ${file_list})
string(REGEX REPLACE ".c$" "" exec_name ${src})
set(exec_name "${exec_name}_${extn}")
add_executable(${exec_name}.x ${src})
target_compile_options(${exec_name}.x
PRIVATE
# load-var-for,COPTFLAGS
${COPTFLAGS}
)
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(${exec_name}.x
PRIVATE
# in get-noopt-cflags-for
${VERS_DEF}
"-DBLIS_EXPORT=__declspec(dllimport)"
${LPGEMM_FLAGS}
)
else()
target_compile_definitions(${exec_name}.x
PRIVATE
# in get-noopt-cflags-for
${VERS_DEF}
${LPGEMM_FLAGS}
)
endif()
target_include_directories(${exec_name}.x
BEFORE
PRIVATE
# in get-noopt-cflags-for
${CINFLAGS}
)
target_link_libraries(${exec_name}.x PRIVATE ${LIBBLIS} ${LDFLAGS})
if(THREADING_MODEL STREQUAL "openmp")
target_link_libraries(${exec_name}.x PRIVATE OpenMP::OpenMP_C)
endif()
list(APPEND temp_executables ${exec_name}.x)
endforeach()
set(bench_executables ${temp_executables} PARENT_SCOPE)
endfunction()
lpgemmbenchexe("blis")
add_custom_target(lpgemm_blis DEPENDS ${bench_executables})
add_custom_target(benchmark_lpgemm DEPENDS lpgemm_blis)
# Put all those targets under bench_aocl_gemm-targets folder name so that they appear all together in IDE.
set_target_properties(benchmark_lpgemm lpgemm_blis PROPERTIES FOLDER bench_aocl_gemm-targets)

View File

@@ -72,9 +72,9 @@ On Windows, specify Visual Studio generator using
cmake -G "Visual Studio 17 2022"
```
For the rest of this documentation, we will use the platform-agnostic commands to build the libraries, but the usual make commands can be used instead. On the following command snippets we ommit specifying the generator, but one can use their prefered way of building using common CMake practices.
For the rest of this documentation, we will use the platform-agnostic commands to build the libraries, but the usual make commands can be used instead. On the following command snippets we ommit specifying the generator, but one can use their prefered way of building using common CMake practices.
### Choosing a configuration
### Choosing a configuration
This step is equivalent to running `./configure <confname>` using the Make system. In this case, simply run:
```
@@ -160,7 +160,7 @@ The BLIS CMake system aims to be combatible with the current `make` system. For
| `testblas` | Run the BLAS test drivers with default parameters (runs for a few seconds). |
| `checkbliscpp` | Run the BLIS C++ tests (runs for a few seconds). |
**_NOTE:_**
**_NOTE:_**
Using those targets sets the environment appropriately, so copying the input files and/or the DLL in case of Windows builds is not required.
### Running the testsuites
@@ -172,13 +172,13 @@ Using those targets sets the environment appropriately, so copying the input fil
The CMake system is designed to closely relate to the BLIS Make system. Assuming that a user has followed the steps in [Configuration How To](ConfigurationHowTo.md), adding the new configuration on the CMake system requires the following steps:
* Add a `make_defs.cmake` file which is equivalent to `make_defs.mk`. One can see `blis/config/zen/make_defs.cmake` and `blis/config/zen/make_defs.mk` for an example.
* Update `blis/CMakeLists.txt` to remove the error for the particular new configuration and to add the option in `set_property()` so that it appears in cmake-gui.
* Update `blis/CMakeLists.txt` to remove the error for the particular new configuration and to add the option in `set_property()` so that it appears in cmake-gui.
## Some examples
In this section we provide some examples for users that are familiar with the build system based in Makefiles and want to try the new CMake system.
**_NOTE:_**
**_NOTE:_**
The CMake system generates the shared libraries by default. To build the static libraries, you need to specify the corresponding CMake variable below
```
cmake .. -DBUILD_SHARED_LIBS=OFF -DBLIS_CONFIG_FAMILY=amdzen
@@ -207,7 +207,7 @@ cmake .. -G "Visual Studio 17 2022" -TClangCl -DENABLE_THREADING=openmp -DINT_SI
### Example 2: single-threaded ILP64 libraries for amdzen configuration with aocl_gemm addon enabled and default compiler
**_NOTE:_**
**_NOTE:_**
Addon functionality is currently available only on Linux.
* With configure script:
@@ -220,6 +220,71 @@ Addon functionality is currently available only on Linux.
cmake .. -DENABLE_THREADING=no -DINT_SIZE=64 -DBLAS_INT_SIZE=64 -DENABLE_ADDON=aocl_gemm -DBLIS_CONFIG_FAMILY=amdzen
```
### Bench
* Bench is used to measure performance. The bench targets depend on BLIS library, which is built depending on the cmake configuration.
## 1. Bench CMake Configuration
## 1.1.Move to "bench" folder within blis_build dir created during configuring cmake.
## 1.2.Now build bench selecting the targets
# 1.2.1.To build blis targets
* To build the benchmark executables with the BLIS library built from CMake project use
```
$ cmake ..
$ cmake --build . --target bench_blis #builds blis extension executables
```
* To build the benchmark executables with any BLIS package provide a path to the installation using
```
$ cmake .. -DBLIS_INSTALL_PATH=/BLIS_installation_path
$ cmake --build . --target bench_blis #builds blis extension executables
```
## 1.2.2.To build MKL targets
* To build the benchmark executables with MKLROOT use
```
$ cmake ..
$ cmake --build . --target bench_mkl #builds mkl extension executables
```
* If MKLROOT is not set, then set MKL_PATH and build the benchmark executables using
```
$ cmake .. -DMKL_PATH=/path_to_MKL_library
$ cmake --build . --target bench_mkl #builds mkl extension executables
```
## 1.2.3.To build openblas targets
* To build benchmark executables for Openblas,set the OPENBLAS_PATH and build using
```
$ cmake .. -DOPENBLAS_PATH=/path_to_Openblas
$ cmake --build . --target bench_openblas #builds openblas extension executables
```
## 1.2.4.To build for all targets
* To build for all benchmark executables set the MKL_PATH,OPENBLAS_PATH, then build using
```
$ cmake .. -DMKL_PATH=/path_to_MKL_library -DOPENBLAS_PATH=/path_to_Openblas
$ cmake --build . --target benchmark #builds for all targets
```
## 2.To measure performance for "bench_aocl_gemm" only when lpgemm is configured during cmake.
```
cmake .. -DENABLE_ADDON="aocl_gemm"
```
# 2.1.Move to "bench_aocl_gemm" folder within blis_build/bench folder.
# 2.2.Now build bench_aocl_gemm
```
$ cmake --build . or cmake --build . --target benchmark_lpgemm
```
## 3.Run any of the bench executable
```
./<executable> ../../bench/inputfile.txt outfile.txt
```
## Conclusion
The BLIS CMake system is developed and maintained by AMD. You can contact us on the email-id toolchainsupport@amd.com. You can also raise any issue/suggestion on the git-hub repository at https://github.com/amd/blis/issues.