diff --git a/workload-xsave/CMakeLists.txt b/workload-xsave/CMakeLists.txt new file mode 100644 index 00000000..63920857 --- /dev/null +++ b/workload-xsave/CMakeLists.txt @@ -0,0 +1,151 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2024 Intel Corporation. +# Yi Sun +# Haoliang Zhu + +cmake_minimum_required(VERSION 3.12) +project(Yogini) + +# Set the compiler +set(CMAKE_C_COMPILER ${CROSS_COMPILE}gcc) + +# Set the build output directory +set(BUILD_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}) + +# Set the installation prefix +if(NOT CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX /usr) +endif() + +# Set the source files +set(SRC + yogini.c + yogini.h + work_UMWAIT.c + work_TPAUSE.c + work_RDTSC.c + work_PAUSE.c + work_memcpy.c + work_MEM.c + # run_common.c + # work_GETCPU.c + # worker_init4.c + # worker_init_dotprod.c +) + +# Get target CPU information +execute_process( + COMMAND ${CMAKE_C_COMPILER} -march=native -Q --help=target + OUTPUT_VARIABLE TARGET_CPU + ERROR_QUIET +) + +# Print information about the target CPU +message(STATUS "Target CPU: ${TARGET_CPU}") + +# Check whether the CPU feature is enabled +function(check_cpu_feature feature var_name) + string(REGEX MATCH "${feature}[ \t]+\\[enabled\\]" feature_enabled_match "${TARGET_CPU}") + if(feature_enabled_match) + set(${var_name} TRUE PARENT_SCOPE) + else() + set(${var_name} FALSE PARENT_SCOPE) + endif() +endfunction() + +add_compile_definitions(CMAKE_FLAG=0) + +# Check whether "-mamx" is enabled and get the result +check_cpu_feature("-mamx-tile" mamx_enabled) +if(mamx_enabled) + message(STATUS "-mamx-tile is enabled") + add_compile_definitions(MAMX_ENABLED=1) + list(APPEND SRC work_AMX.c) + # list(APPEND SRC worker_init_amx.c) +else() + message(STATUS "-mamx-tile is disabled or not found") +endif() + +# Check whether "-mavx" is enabled and get the result +check_cpu_feature("-mavx" mavx_enabled) +if(mavx_enabled) + message(STATUS "-mavx is enabled") + add_compile_definitions(MAVX_ENABLED=1) + list(APPEND SRC work_AVX.c) + # list(APPEND SRC worker_init_avx.c) +else() + message(STATUS "-mavx is disabled or not found") +endif() + +# Check whether "-mavx2" is enabled and get the result +check_cpu_feature("-mavx2" mavx2_enabled) +if(mavx2_enabled) + message(STATUS "-mavx2 is enabled") + add_compile_definitions(MAVX2_ENABLED=1) + list(APPEND SRC work_AVX2.c) + list(APPEND SRC work_DOTPROD.c) + # list(APPEND SRC worker_init_avx2.c) +else() + message(STATUS "-mavx2 is disabled or not found") +endif() + +# Check whether "-mavx512f" is enabled and get the result +check_cpu_feature("-mavx512f" mavx512f_enabled) +if(mavx512f_enabled) + message(STATUS "-mavx512f is enabled") + add_compile_definitions(MAVX512F_ENABLED=1) + list(APPEND SRC work_AVX512.c) +else() + message(STATUS "-mavx512f is disabled or not found") +endif() + +# Check whether "-msse" is enabled and get the result +check_cpu_feature("-msse" sse_enabled) +if(sse_enabled) + message(STATUS "-msse is enabled") + add_compile_definitions(MSSE_ENABLED=1) + list(APPEND SRC work_SSE.c) + # list(APPEND SRC worker_init_sse.c) +else() + message(STATUS "-msse is disabled or not found") +endif() + +# Check whether "-mvnni" is enabled and get the result +check_cpu_feature("-mvnni" vnni_enabled) +if(vnni_enabled) + message(STATUS "-mvnni is enabled") + add_compile_definitions(MVNNI_ENABLED=1) + list(APPEND SRC work_VNNI.c) +else() + message(STATUS "-mvnni is disabled or not found") +endif() + +# Check whether "-mvnni512" is enabled and get the result +check_cpu_feature("-mvnni512" vnni512_enabled) +if(vnni512_enabled) + message(STATUS "-mvnni512 is enabled") + add_compile_definitions(MVNNI512_ENABLED=1) + list(APPEND SRC work_VNNI512.c) +else() + message(STATUS "-mvnni512 is disabled or not found") +endif() + + +# Print the contents of the SRC +message(STATUS "SRC contains the following files: ${SRC}") + +# Set the compiler flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -Wall -O3") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") +# Add the -g flags, if use gdb for debugging +# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + +# Add the executable +add_executable(yogini ${SRC}) + +# Link libraries +target_link_libraries(yogini m pthread) + +# Install the program +install(TARGETS yogini DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) \ No newline at end of file diff --git a/workload-xsave/README.md b/workload-xsave/README.md index 6c167d6d..1bbe8e7e 100644 --- a/workload-xsave/README.md +++ b/workload-xsave/README.md @@ -14,7 +14,7 @@ These instructions will help you get a copy of the Intel SIMD Instruction Microb ### Prerequisites * C/C++ compiler with support for the desired SIMD instruction sets. -* Make installed. +* CMake and make installed. ### Installation Clone the repository to your local machine: @@ -25,8 +25,19 @@ Enter the project directory: ``` cd workload-xsave ``` +#### CMake(Recommended) +The CMakeLists.txt is capable of selecting the appropriate source files for compilation based on the instruction sets supported by the target CPU. Build the benchmarks using CMake: ``` +mkdir build +cd build +cmake .. +make +``` + +#### Make(Alternative) +Build the benchmarks using Make: +``` make ``` Or, if your platform is not support all SIMD feature, you can try diff --git a/workload-xsave/yogini.h b/workload-xsave/yogini.h index 69a58ff1..46e38ef0 100644 --- a/workload-xsave/yogini.h +++ b/workload-xsave/yogini.h @@ -9,9 +9,14 @@ #ifndef YOGINI_H #define YOGINI_H -#include +#include +#include #include +#ifndef CMAKE_FLAG +#define CMAKE_FLAG 1 +#endif + struct work_instance { struct work_instance *next; pthread_t thread_id; @@ -55,13 +60,19 @@ extern unsigned int SIZE_1GB; #ifdef YOGINI_MAIN struct workload *(*all_register_routines[]) () = { +#if MAVX_ENABLED || CMAKE_FLAG register_AVX, +#endif +#if MAVX2_ENABLED || CMAKE_FLAG register_AVX2, +#endif +#if MAVX512F_ENABLED || CMAKE_FLAG register_AVX512, -#if __GNUC__ >= 9 +#endif +#if MVNNI512_ENABLED || CMAKE_FLAG register_VNNI512, #endif -#if __GNUC__ >= 11 +#if MVNNI_ENABLED || CMAKE_FLAG register_VNNI, #endif register_DOTPROD, @@ -71,10 +82,14 @@ struct workload *(*all_register_routines[]) () = { register_UMWAIT, #endif register_RDTSC, +#if MSSE_ENABLED || CMAKE_FLAG register_SSE, +#endif register_MEM, register_memcpy, +#if MAMX_ENABLED || CMAKE_FLAG register_AMX, +#endif NULL }; #endif