diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-07-28 18:52:36 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2020-09-04 12:37:07 (GMT) |
commit | a020787a9b7ede3aa490345bd446e469fb1713d2 (patch) | |
tree | f96ef2b1d84515fda4288ffaf39e9abfb8c9cc1a /Tests/ISPC | |
parent | 5a1750017e65727660167ae1953746a3fd3d2c7b (diff) | |
download | CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.zip CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.tar.gz CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.tar.bz2 |
ISPC: Support generation for multiple instruction sets
Diffstat (limited to 'Tests/ISPC')
-rw-r--r-- | Tests/ISPC/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/ISPC/ChainedStaticLibraries/CMakeLists.txt | 22 | ||||
-rw-r--r-- | Tests/ISPC/ChainedStaticLibraries/extra.cxx | 17 | ||||
-rw-r--r-- | Tests/ISPC/ChainedStaticLibraries/extra.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/ChainedStaticLibraries/main.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/ChainedStaticLibraries/simple.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/Defines/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/ISPC/DynamicLibrary/CMakeLists.txt | 20 | ||||
-rw-r--r-- | Tests/ISPC/DynamicLibrary/extra.cxx | 17 | ||||
-rw-r--r-- | Tests/ISPC/DynamicLibrary/extra.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/DynamicLibrary/main.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/DynamicLibrary/simple.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/ObjectGenex/CMakeLists.txt | 45 | ||||
-rw-r--r-- | Tests/ISPC/ObjectGenex/main.cxx | 87 | ||||
-rw-r--r-- | Tests/ISPC/ObjectGenex/simple.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/CMakeLists.txt | 5 |
16 files changed, 305 insertions, 2 deletions
diff --git a/Tests/ISPC/CMakeLists.txt b/Tests/ISPC/CMakeLists.txt index ca5a79b..c13271a 100644 --- a/Tests/ISPC/CMakeLists.txt +++ b/Tests/ISPC/CMakeLists.txt @@ -6,7 +6,10 @@ macro (add_ispc_test_macro name) PROPERTY LABELS "ISPC") endmacro () +add_ispc_test_macro(ISPC.ChainedStaticLibraries ISPCChainedStaticLibraries) add_ispc_test_macro(ISPC.Defines ISPCDefines) +add_ispc_test_macro(ISPC.DynamicLibrary ISPCDynamicLibrary) +add_ispc_test_macro(ISPC.ObjectGenex ISPCObjectGenex) add_ispc_test_macro(ISPC.ObjectLibrary ISPCObjectLibrary) add_ispc_test_macro(ISPC.ResponseAndDefine ISPCResponseAndDefine) add_ispc_test_macro(ISPC.StaticLibrary ISPCStaticLibrary) diff --git a/Tests/ISPC/ChainedStaticLibraries/CMakeLists.txt b/Tests/ISPC/ChainedStaticLibraries/CMakeLists.txt new file mode 100644 index 0000000..bf0b57e --- /dev/null +++ b/Tests/ISPC/ChainedStaticLibraries/CMakeLists.txt @@ -0,0 +1,22 @@ + +cmake_minimum_required(VERSION 3.18) +project(ISPCChainedStaticLibraries CXX ISPC) + +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CMAKE_ISPC_FLAGS "--arch=x86") +endif() + + +add_library(ispc_objects1 STATIC extra.ispc extra.cxx) +add_library(ispc_objects2 STATIC simple.ispc) + +set_target_properties(ispc_objects1 PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(ispc_objects1 PROPERTIES ISPC_INSTRUCTION_SETS "avx1-i32x16;avx2-i32x4") + +set_target_properties(ispc_objects2 PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(ispc_objects2 PROPERTIES ISPC_INSTRUCTION_SETS "avx1-i32x16") + +target_link_libraries(ispc_objects2 PRIVATE ispc_objects1) + +add_executable(ISPCChainedStaticLibraries main.cxx) +target_link_libraries(ISPCChainedStaticLibraries PUBLIC ispc_objects2) diff --git a/Tests/ISPC/ChainedStaticLibraries/extra.cxx b/Tests/ISPC/ChainedStaticLibraries/extra.cxx new file mode 100644 index 0000000..88ef3a7 --- /dev/null +++ b/Tests/ISPC/ChainedStaticLibraries/extra.cxx @@ -0,0 +1,17 @@ +#include <stdio.h> + +#include "extra.ispc.h" + +int extra() +{ + float vin[16], vout[16]; + for (int i = 0; i < 16; ++i) + vin[i] = i; + + ispc::extra(vin, vout, 16); + + for (int i = 0; i < 16; ++i) + printf("%d: extra(%f) = %f\n", i, vin[i], vout[i]); + + return 0; +} diff --git a/Tests/ISPC/ChainedStaticLibraries/extra.ispc b/Tests/ISPC/ChainedStaticLibraries/extra.ispc new file mode 100644 index 0000000..5a4a442 --- /dev/null +++ b/Tests/ISPC/ChainedStaticLibraries/extra.ispc @@ -0,0 +1,12 @@ + +export void extra(uniform float vin[], uniform float vout[], + uniform int count) { + foreach (index = 0 ... count) { + float v = vin[index]; + if (v < 3.) + v = v * v; + else + v = sqrt(v); + vout[index] = v; + } +} diff --git a/Tests/ISPC/ChainedStaticLibraries/main.cxx b/Tests/ISPC/ChainedStaticLibraries/main.cxx new file mode 100644 index 0000000..4f1c9be --- /dev/null +++ b/Tests/ISPC/ChainedStaticLibraries/main.cxx @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include "simple.ispc.h" + +int main() +{ + float vin[16], vout[16]; + for (int i = 0; i < 16; ++i) + vin[i] = i; + + ispc::simple(vin, vout, 16); + + for (int i = 0; i < 16; ++i) + printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]); +} diff --git a/Tests/ISPC/ChainedStaticLibraries/simple.ispc b/Tests/ISPC/ChainedStaticLibraries/simple.ispc new file mode 100644 index 0000000..70cb588 --- /dev/null +++ b/Tests/ISPC/ChainedStaticLibraries/simple.ispc @@ -0,0 +1,12 @@ + +export void simple(uniform float vin[], uniform float vout[], + uniform int count) { + foreach (index = 0 ... count) { + float v = vin[index]; + if (v < 3.) + v = v * v; + else + v = sqrt(v); + vout[index] = v; + } +} diff --git a/Tests/ISPC/Defines/CMakeLists.txt b/Tests/ISPC/Defines/CMakeLists.txt index 5155106..7645804 100644 --- a/Tests/ISPC/Defines/CMakeLists.txt +++ b/Tests/ISPC/Defines/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.18) project(ISPCDefines CXX ISPC) +set(CMAKE_ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i16x8;avx1-i32x16;avx2-i32x4;avx512knl-i32x16;avx512skx-i32x8") set(CMAKE_ISPC_FLAGS -DM_PI=3.1415926535f) add_compile_definitions([==[STRUCT_DEFINE=struct{uniform int a]==]) diff --git a/Tests/ISPC/DynamicLibrary/CMakeLists.txt b/Tests/ISPC/DynamicLibrary/CMakeLists.txt new file mode 100644 index 0000000..59f875e --- /dev/null +++ b/Tests/ISPC/DynamicLibrary/CMakeLists.txt @@ -0,0 +1,20 @@ + +cmake_minimum_required(VERSION 3.18) +project(ISPCDynamicLibrary CXX ISPC) + +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CMAKE_ISPC_FLAGS "--arch=x86") +endif() + + +add_library(ispc_objects1 STATIC extra.ispc extra.cxx) +add_library(ispc_objects2 SHARED simple.ispc) + +set_target_properties(ispc_objects1 PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(ispc_objects1 PROPERTIES ISPC_INSTRUCTION_SETS "avx1-i32x16;avx2-i32x4") +set_target_properties(ispc_objects2 PROPERTIES ISPC_INSTRUCTION_SETS "avx1-i32x16") + +target_link_libraries(ispc_objects2 PRIVATE ispc_objects1) + +add_executable(ISPCDynamicLibrary main.cxx) +target_link_libraries(ISPCDynamicLibrary PUBLIC ispc_objects2) diff --git a/Tests/ISPC/DynamicLibrary/extra.cxx b/Tests/ISPC/DynamicLibrary/extra.cxx new file mode 100644 index 0000000..88ef3a7 --- /dev/null +++ b/Tests/ISPC/DynamicLibrary/extra.cxx @@ -0,0 +1,17 @@ +#include <stdio.h> + +#include "extra.ispc.h" + +int extra() +{ + float vin[16], vout[16]; + for (int i = 0; i < 16; ++i) + vin[i] = i; + + ispc::extra(vin, vout, 16); + + for (int i = 0; i < 16; ++i) + printf("%d: extra(%f) = %f\n", i, vin[i], vout[i]); + + return 0; +} diff --git a/Tests/ISPC/DynamicLibrary/extra.ispc b/Tests/ISPC/DynamicLibrary/extra.ispc new file mode 100644 index 0000000..5a4a442 --- /dev/null +++ b/Tests/ISPC/DynamicLibrary/extra.ispc @@ -0,0 +1,12 @@ + +export void extra(uniform float vin[], uniform float vout[], + uniform int count) { + foreach (index = 0 ... count) { + float v = vin[index]; + if (v < 3.) + v = v * v; + else + v = sqrt(v); + vout[index] = v; + } +} diff --git a/Tests/ISPC/DynamicLibrary/main.cxx b/Tests/ISPC/DynamicLibrary/main.cxx new file mode 100644 index 0000000..4f1c9be --- /dev/null +++ b/Tests/ISPC/DynamicLibrary/main.cxx @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include "simple.ispc.h" + +int main() +{ + float vin[16], vout[16]; + for (int i = 0; i < 16; ++i) + vin[i] = i; + + ispc::simple(vin, vout, 16); + + for (int i = 0; i < 16; ++i) + printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]); +} diff --git a/Tests/ISPC/DynamicLibrary/simple.ispc b/Tests/ISPC/DynamicLibrary/simple.ispc new file mode 100644 index 0000000..70cb588 --- /dev/null +++ b/Tests/ISPC/DynamicLibrary/simple.ispc @@ -0,0 +1,12 @@ + +export void simple(uniform float vin[], uniform float vout[], + uniform int count) { + foreach (index = 0 ... count) { + float v = vin[index]; + if (v < 3.) + v = v * v; + else + v = sqrt(v); + vout[index] = v; + } +} diff --git a/Tests/ISPC/ObjectGenex/CMakeLists.txt b/Tests/ISPC/ObjectGenex/CMakeLists.txt new file mode 100644 index 0000000..bc0cbf6 --- /dev/null +++ b/Tests/ISPC/ObjectGenex/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.18) +project(ISPCObjectGenex CXX ISPC) + +set(CMAKE_ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i16x8;avx1-i32x16;avx2-i32x4;avx512knl-i32x16;avx512skx-i32x8") + +add_library(ispc_objects OBJECT + simple.ispc + ) +target_compile_definitions(ispc_objects PRIVATE + $<$<COMPILE_LANG_AND_ID:ISPC,Intel>:M_PI=3.1415926535f> +) +set_target_properties(ispc_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set_source_files_properties(simple.ispc PROPERTIES COMPILE_OPTIONS "--arch=x86") +endif() + + +#Test ObjectFiles with file(GENERATE) +file(GENERATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gen_$<LOWER_CASE:$<CONFIG>/>path_to_objs.h + CONTENT [[ +#ifndef path_to_objs +#define path_to_objs + +#include <string> + +static std::string obj_paths = "$<TARGET_OBJECTS:ispc_objects>"; + +#endif + +]] +) + + +add_executable(ISPCObjectGenex main.cxx) +add_dependencies(ISPCObjectGenex ispc_objects) + +list(LENGTH CMAKE_ISPC_INSTRUCTION_SETS numberOfTargets) +math(EXPR numberOfTargets "${numberOfTargets}+1") +target_compile_definitions(ISPCObjectGenex PRIVATE + "ExpectedISPCObjects=${numberOfTargets}" + "CONFIG_TYPE=gen_$<LOWER_CASE:$<CONFIG>>" + ) +target_include_directories(ISPCObjectGenex PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) +target_compile_features(ISPCObjectGenex PRIVATE cxx_std_11) diff --git a/Tests/ISPC/ObjectGenex/main.cxx b/Tests/ISPC/ObjectGenex/main.cxx new file mode 100644 index 0000000..143e74e --- /dev/null +++ b/Tests/ISPC/ObjectGenex/main.cxx @@ -0,0 +1,87 @@ +#include <stdio.h> + +/* + Define GENERATED_HEADER macro to allow c++ files to include headers + generated based on different configuration types. +*/ + +/* clang-format off */ +#define GENERATED_HEADER(x) GENERATED_HEADER0(CONFIG_TYPE/x) +/* clang-format on */ +#define GENERATED_HEADER0(x) GENERATED_HEADER1(x) +#define GENERATED_HEADER1(x) <x> + +#include GENERATED_HEADER(path_to_objs.h) + +#include <vector> +std::vector<std::string> expandList(std::string const& arg) +{ + std::vector<std::string> output; + // If argument is empty or no `;` just copy the current string + if (arg.empty() || arg.find(';') == std::string::npos) { + output.emplace_back(arg); + return output; + } + + std::string newArg; + // Break the string at non-escaped semicolons not nested in []. + int squareNesting = 0; + auto last = arg.begin(); + auto const cend = arg.end(); + for (auto c = last; c != cend; ++c) { + switch (*c) { + case '\\': { + // We only want to allow escaping of semicolons. Other + // escapes should not be processed here. + auto cnext = c + 1; + if ((cnext != cend) && *cnext == ';') { + newArg.append(last, c); + // Skip over the escape character + last = cnext; + c = cnext; + } + } break; + case '[': { + ++squareNesting; + } break; + case ']': { + --squareNesting; + } break; + case ';': { + // Break the string here if we are not nested inside square + // brackets. + if (squareNesting == 0) { + newArg.append(last, c); + // Skip over the semicolon + last = c + 1; + if (!newArg.empty()) { + // Add the last argument if the string is not empty. + output.push_back(newArg); + newArg.clear(); + } + } + } break; + default: { + // Just append this character. + } break; + } + } + newArg.append(last, cend); + if (!newArg.empty()) { + // Add the last argument if the string is not empty. + output.push_back(std::move(newArg)); + } + + return output; +} + +int main() +{ + // determine that the number of object files specified in obj_paths + // is equal to the number of arch's + + std::vector<std::string> paths = expandList(obj_paths); + const bool correctSize = (paths.size() == ExpectedISPCObjects); + + return (correctSize) ? 0 : 1; +} diff --git a/Tests/ISPC/ObjectGenex/simple.ispc b/Tests/ISPC/ObjectGenex/simple.ispc new file mode 100644 index 0000000..a76b76c --- /dev/null +++ b/Tests/ISPC/ObjectGenex/simple.ispc @@ -0,0 +1,12 @@ + +export void simple(uniform float vin[], uniform float vout[], + uniform int count) { + foreach (index = 0 ... count) { + float v = vin[index]; + if (v < M_PI) + v = v * v; + else + v = sqrt(v); + vout[index] = v; + } +} diff --git a/Tests/ISPC/ObjectLibrary/CMakeLists.txt b/Tests/ISPC/ObjectLibrary/CMakeLists.txt index 333ad66..4767d7e 100644 --- a/Tests/ISPC/ObjectLibrary/CMakeLists.txt +++ b/Tests/ISPC/ObjectLibrary/CMakeLists.txt @@ -7,11 +7,12 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(CMAKE_ISPC_FLAGS "--arch=x86") endif() -add_library(ispc_objects OBJECT simple.ispc extra.ispc) -target_compile_options(ispc_objects PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--target=sse2-i32x4>") +add_library(ispc_objects OBJECT simple.ispc extra.ispc) set_target_properties(ispc_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(ispc_objects PROPERTIES ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i8x16") + add_executable(ISPCObjectLibrary main.cxx extra.cxx) target_link_libraries(ISPCObjectLibrary PRIVATE ispc_objects) |