diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-02 18:39:04 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-02 18:39:04 (GMT) |
commit | 2a6471dd7bf3aa694a9a2bc7f554478d6fdcf8f5 (patch) | |
tree | 9f9cc0a1bb5cb21ed1cb40a68058f01007f67906 /Tests/ISPC | |
parent | a9fd3a107dc4bc34b8d2822b9153ee0ab9e02ea8 (diff) | |
parent | 68b674b8bc862f943863b48925a5c4d065de8f39 (diff) | |
download | CMake-2a6471dd7bf3aa694a9a2bc7f554478d6fdcf8f5.zip CMake-2a6471dd7bf3aa694a9a2bc7f554478d6fdcf8f5.tar.gz CMake-2a6471dd7bf3aa694a9a2bc7f554478d6fdcf8f5.tar.bz2 |
Merge branch 'master' into ninja-multi-automoc-regression
Diffstat (limited to 'Tests/ISPC')
-rw-r--r-- | Tests/ISPC/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/ISPC/Defines/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/ISPC/Defines/main.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/Defines/simple.ispc | 15 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/CMakeLists.txt | 17 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/extra.cxx | 17 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/extra.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/main.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/simple.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/ResponseAndDefine/CMakeLists.txt | 28 | ||||
-rw-r--r-- | Tests/ISPC/ResponseAndDefine/main.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/ResponseAndDefine/simple.ispc | 16 | ||||
-rw-r--r-- | Tests/ISPC/StaticLibrary/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/ISPC/StaticLibrary/main.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/StaticLibrary/simple.ispc | 12 | ||||
-rw-r--r-- | Tests/ISPC/TryCompile/CMakeLists.txt | 16 | ||||
-rw-r--r-- | Tests/ISPC/TryCompile/main.cxx | 19 | ||||
-rw-r--r-- | Tests/ISPC/TryCompile/simple.ispc | 12 |
18 files changed, 279 insertions, 0 deletions
diff --git a/Tests/ISPC/CMakeLists.txt b/Tests/ISPC/CMakeLists.txt new file mode 100644 index 0000000..ca5a79b --- /dev/null +++ b/Tests/ISPC/CMakeLists.txt @@ -0,0 +1,13 @@ + + +macro (add_ispc_test_macro name) + add_test_macro("${name}" ${ARGN}) + set_property(TEST "${name}" APPEND + PROPERTY LABELS "ISPC") +endmacro () + +add_ispc_test_macro(ISPC.Defines ISPCDefines) +add_ispc_test_macro(ISPC.ObjectLibrary ISPCObjectLibrary) +add_ispc_test_macro(ISPC.ResponseAndDefine ISPCResponseAndDefine) +add_ispc_test_macro(ISPC.StaticLibrary ISPCStaticLibrary) +add_ispc_test_macro(ISPC.TryCompile ISPCTryCompile) diff --git a/Tests/ISPC/Defines/CMakeLists.txt b/Tests/ISPC/Defines/CMakeLists.txt new file mode 100644 index 0000000..5155106 --- /dev/null +++ b/Tests/ISPC/Defines/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.18) +project(ISPCDefines CXX ISPC) + +set(CMAKE_ISPC_FLAGS -DM_PI=3.1415926535f) +add_compile_definitions([==[STRUCT_DEFINE=struct{uniform int a]==]) + +add_executable(ISPCDefines + main.cxx + simple.ispc + ) + +set_target_properties(ISPCDefines PROPERTIES POSITION_INDEPENDENT_CODE ON) +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set_source_files_properties(simple.ispc PROPERTIES COMPILE_OPTIONS "--arch=x86") +endif() diff --git a/Tests/ISPC/Defines/main.cxx b/Tests/ISPC/Defines/main.cxx new file mode 100644 index 0000000..4f1c9be --- /dev/null +++ b/Tests/ISPC/Defines/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/Defines/simple.ispc b/Tests/ISPC/Defines/simple.ispc new file mode 100644 index 0000000..d8d6465 --- /dev/null +++ b/Tests/ISPC/Defines/simple.ispc @@ -0,0 +1,15 @@ + +//textual error if STRUCT_DEFINE not set +STRUCT_DEFINE;}; + +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 new file mode 100644 index 0000000..333ad66 --- /dev/null +++ b/Tests/ISPC/ObjectLibrary/CMakeLists.txt @@ -0,0 +1,17 @@ + +cmake_minimum_required(VERSION 3.18) +project(ISPCObjectLibrary CXX ISPC) + +set(CMAKE_NINJA_FORCE_RESPONSE_FILE ON) +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>") + +set_target_properties(ispc_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) + +add_executable(ISPCObjectLibrary main.cxx extra.cxx) +target_link_libraries(ISPCObjectLibrary PRIVATE ispc_objects) diff --git a/Tests/ISPC/ObjectLibrary/extra.cxx b/Tests/ISPC/ObjectLibrary/extra.cxx new file mode 100644 index 0000000..88ef3a7 --- /dev/null +++ b/Tests/ISPC/ObjectLibrary/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/ObjectLibrary/extra.ispc b/Tests/ISPC/ObjectLibrary/extra.ispc new file mode 100644 index 0000000..5a4a442 --- /dev/null +++ b/Tests/ISPC/ObjectLibrary/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/ObjectLibrary/main.cxx b/Tests/ISPC/ObjectLibrary/main.cxx new file mode 100644 index 0000000..4f1c9be --- /dev/null +++ b/Tests/ISPC/ObjectLibrary/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/ObjectLibrary/simple.ispc b/Tests/ISPC/ObjectLibrary/simple.ispc new file mode 100644 index 0000000..70cb588 --- /dev/null +++ b/Tests/ISPC/ObjectLibrary/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/ResponseAndDefine/CMakeLists.txt b/Tests/ISPC/ResponseAndDefine/CMakeLists.txt new file mode 100644 index 0000000..7539209 --- /dev/null +++ b/Tests/ISPC/ResponseAndDefine/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.18) +project(ispc_spaces_in_path ISPC CXX) + +set(CMAKE_NINJA_FORCE_RESPONSE_FILE ON) + +# Make sure we can handle an arg file with tricky defines including spaces in -I include +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/path with spaces/simple_include.h" +" + typedef float FLOAT_TYPE; +" +) + +add_executable(ISPCResponseAndDefine main.cxx simple.ispc) +set_target_properties(ISPCResponseAndDefine PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(ISPCResponseAndDefine PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + +target_compile_options(ISPCResponseAndDefine PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--target=sse2-i32x4>") +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + target_compile_options(ISPCResponseAndDefine PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--arch=x86>") +endif() + + + +target_compile_definitions(ISPCResponseAndDefine PRIVATE + "$<$<COMPILE_LANGUAGE:ISPC>:STRUCT_DEFINE=struct{uniform int a>;M_PI=3.14159f") +target_include_directories(ISPCResponseAndDefine PRIVATE + "$<$<COMPILE_LANGUAGE:ISPC>:${CMAKE_CURRENT_BINARY_DIR}/fake path with spaces>" + "$<$<COMPILE_LANGUAGE:ISPC>:${CMAKE_CURRENT_BINARY_DIR}/path with spaces>") diff --git a/Tests/ISPC/ResponseAndDefine/main.cxx b/Tests/ISPC/ResponseAndDefine/main.cxx new file mode 100644 index 0000000..4f1c9be --- /dev/null +++ b/Tests/ISPC/ResponseAndDefine/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/ResponseAndDefine/simple.ispc b/Tests/ISPC/ResponseAndDefine/simple.ispc new file mode 100644 index 0000000..81fd7ca --- /dev/null +++ b/Tests/ISPC/ResponseAndDefine/simple.ispc @@ -0,0 +1,16 @@ + +STRUCT_DEFINE;}; + +#include "simple_include.h" + +export void simple(uniform FLOAT_TYPE vin[], uniform FLOAT_TYPE vout[], + uniform int count) { + foreach (index = 0 ... count) { + FLOAT_TYPE v = vin[index]; + if (v < M_PI) + v = v * v; + else + v = sqrt(v); + vout[index] = v; + } +} diff --git a/Tests/ISPC/StaticLibrary/CMakeLists.txt b/Tests/ISPC/StaticLibrary/CMakeLists.txt new file mode 100644 index 0000000..ebe5960 --- /dev/null +++ b/Tests/ISPC/StaticLibrary/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.18) +project(ISPCStaticLibrary CXX ISPC) + +add_library(ispc_objects STATIC simple.ispc) + +target_compile_options(ispc_objects PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--target=sse2-i32x4>") +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + target_compile_options(ispc_objects PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--arch=x86>") +endif() + +set_target_properties(ispc_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) + +add_executable(ISPCStaticLibrary main.cxx) +target_link_libraries(ISPCStaticLibrary PRIVATE ispc_objects) diff --git a/Tests/ISPC/StaticLibrary/main.cxx b/Tests/ISPC/StaticLibrary/main.cxx new file mode 100644 index 0000000..4f1c9be --- /dev/null +++ b/Tests/ISPC/StaticLibrary/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/StaticLibrary/simple.ispc b/Tests/ISPC/StaticLibrary/simple.ispc new file mode 100644 index 0000000..70cb588 --- /dev/null +++ b/Tests/ISPC/StaticLibrary/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/TryCompile/CMakeLists.txt b/Tests/ISPC/TryCompile/CMakeLists.txt new file mode 100644 index 0000000..742f511 --- /dev/null +++ b/Tests/ISPC/TryCompile/CMakeLists.txt @@ -0,0 +1,16 @@ + +cmake_minimum_required(VERSION 3.18) +project(ISPCTryCompile ISPC CXX) + +set(CMAKE_NINJA_FORCE_RESPONSE_FILE ON) +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CMAKE_ISPC_FLAGS "--arch=x86") +endif() + +#Verify we can use try_compile with ISPC +try_compile(result "${CMAKE_CURRENT_BINARY_DIR}" + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/simple.ispc" + COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/result.o") + +add_executable(ISPCTryCompile main.cxx ) +target_link_libraries(ISPCTryCompile "${CMAKE_CURRENT_BINARY_DIR}/result.o") diff --git a/Tests/ISPC/TryCompile/main.cxx b/Tests/ISPC/TryCompile/main.cxx new file mode 100644 index 0000000..c8d1ed6 --- /dev/null +++ b/Tests/ISPC/TryCompile/main.cxx @@ -0,0 +1,19 @@ +#include <stdio.h> + +namespace ispc { +extern "C" { +void simple(float*, float*, int); +} +} + +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/TryCompile/simple.ispc b/Tests/ISPC/TryCompile/simple.ispc new file mode 100644 index 0000000..70cb588 --- /dev/null +++ b/Tests/ISPC/TryCompile/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; + } +} |