Skip to content

Commit 3659819

Browse files
Initial commit for Render Kit 05 ispc sample updates
Signed-off-by: Michael R Carroll <[email protected]>
1 parent bf3bcbc commit 3659819

File tree

8 files changed

+390
-0
lines changed

8 files changed

+390
-0
lines changed

.repo-tools/Docs_Automation/guids.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,5 +1158,10 @@
11581158
"notes": "-",
11591159
"removed": "False",
11601160
"ver": "2021.1.Gold"
1161+
},
1162+
"BDC6B80E-E764-409D-966B-662CF7EFB072": {
1163+
"guid": "BDC6B80E-E764-409D-966B-662CF7EFB072",
1164+
"ver": "2022.1.0",
1165+
"name": "Intel oneAPI Rendering Toolkit ISPC Getting Started"
11611166
}
11621167
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
project(ispc_gsg)
2+
cmake_minimum_required(VERSION 3.1)
3+
4+
set(ONEAPI_ROOT "")
5+
if(WIN32)
6+
add_compile_definitions(WIN32)
7+
if(MSVC)
8+
add_compile_options(/EHsc)
9+
endif(MSVC)
10+
endif(WIN32)
11+
12+
if(DEFINED ENV{ONEAPI_ROOT})
13+
set(ONEAPI_ROOT "$ENV{ONEAPI_ROOT}")
14+
message(STATUS "ONEAPI_ROOT FROM ENVIRONMENT: ${ONEAPI_ROOT}")
15+
else()
16+
if(WIN32)
17+
set(ONEAPI_ROOT "C:/Program Files (x86)/Intel/oneAPI")
18+
else()
19+
set(ONEAPI_ROOT /opt/intel/oneapi)
20+
endif()
21+
message(STATUS "ONEAPI_ROOT DEFAULT: ${ONEAPI_ROOT}")
22+
endif(DEFINED ENV{ONEAPI_ROOT})
23+
24+
if (NOT DEFINED ISPC_EXECUTABLE)
25+
find_program (ISPC_EXECUTABLE ispc)
26+
if (NOT ISPC_EXECUTABLE)
27+
message(FATAL_ERROR "Failed to find ispc" )
28+
endif()
29+
endif(NOT DEFINED ISPC_EXECUTABLE)
30+
message(STATUS "ISPC_EXECUTABLE: ${ISPC_EXECUTABLE}")
31+
32+
set (ISPC_SRC_NAME "simple")
33+
set (TARGET_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${ISPC_SRC_NAME}.cpp)
34+
set (ISPC_FLAGS -O2)
35+
set (ISPC_IA_TARGETS "sse2-i32x4")
36+
set (ISPC_ARM_TARGETS "neon")
37+
set (ISPC_OBJ_NAME "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc${CMAKE_CXX_OUTPUT_EXTENSION}")
38+
set (ISPC_HEADER_NAME "${CMAKE_CURRENT_BINARY_DIR}/include-single/${ISPC_SRC_NAME}_ispc.h")
39+
set (OUTPUT_TARGET "${ISPC_IA_TARGETS}")
40+
41+
42+
list(APPEND ISPC_BUILD_OUTPUT ${ISPC_HEADER_NAME} ${ISPC_OBJ_NAME} )
43+
# ISPC command
44+
add_custom_command(OUTPUT ${ISPC_BUILD_OUTPUT}
45+
COMMAND ${ISPC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.ispc ${ISPC_FLAGS} --target=${ISPC_IA_TARGETS} --arch=x86_64
46+
-h ${ISPC_HEADER_NAME} -o ${ISPC_OBJ_NAME}
47+
VERBATIM
48+
DEPENDS ${ISPC_EXECUTABLE}
49+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
50+
51+
52+
add_executable(simple ${ISPC_BUILD_OUTPUT} "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
53+
set_target_properties(simple PROPERTIES LINKER_LANGUAGE CXX)
54+
target_sources(simple PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.cpp)
55+
#ISPC emits a header for the ISPC module. The header location is included below
56+
target_include_directories(simple PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include-single)
57+
58+
#Set variables for multiple isa extension targeting.
59+
#Targets with mask and gang
60+
set (ISPC_IA_TARGETS_MG "sse2-i32x4,sse4-i32x4,avx1-i32x8,avx2-i32x8,avx512skx-i32x8")
61+
set (ISPC_IA_TARGETS sse2 sse4 avx avx2 avx512skx)
62+
set (ISPC_ARM_TARGETS "neon")
63+
set (ISPC_OBJ_NAME "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc_multi${CMAKE_CXX_OUTPUT_EXTENSION}")
64+
set (ISPC_HEADER_NAME "${CMAKE_CURRENT_BINARY_DIR}/include-multi/${ISPC_SRC_NAME}_ispc.h")
65+
set (OUTPUT_TARGET "${ISPC_IA_TARGETS}")
66+
67+
list(APPEND ISPC_MULTI_BUILD_OUTPUT ${ISPC_HEADER_NAME} ${ISPC_OBJ_NAME} )
68+
foreach(TARGET_TOKEN IN LISTS ISPC_IA_TARGETS)
69+
list(APPEND ISPC_MULTI_BUILD_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc_multi_${TARGET_TOKEN}${CMAKE_CXX_OUTPUT_EXTENSION}")
70+
endforeach()
71+
72+
add_custom_command(OUTPUT ${ISPC_MULTI_BUILD_OUTPUT}
73+
COMMAND ${ISPC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc ${ISPC_FLAGS} --target=${ISPC_IA_TARGETS_MG} --arch=x86_64
74+
-h ${ISPC_HEADER_NAME} -o ${ISPC_OBJ_NAME}
75+
VERBATIM
76+
DEPENDS ${ISPC_EXECUTABLE}
77+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
78+
79+
add_executable(simple_multi ${ISPC_MULTI_BUILD_OUTPUT} "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
80+
set_target_properties(simple_multi PROPERTIES LINKER_LANGUAGE CXX)
81+
target_sources(simple_multi PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.cpp)
82+
#ISPC emits a header for the ISPC module. The header location is included below
83+
target_include_directories(simple_multi PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include-multi)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright Intel Corporation
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
* Neither the name of Intel Corporation nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
POSSIBILITY OF SUCH DAMAGE.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Getting Started Sample for Intel oneAPI Rendering Toolkit: Intel Implicit SPMD Program Compiler
2+
3+
4+
Intel Implicit SPMD Program Compiler (ISPC) optimizes single program multiple data kernels for execution on modern SIMD hardware. ISPC is often used in conjunction with high performing Embree and OpenVKL based programs. ISPC compiles a C programming language variant. The language has helpful constructs for modern parallelism. This sample introduces Intel ISPC within the scope of the Intel oneAPI Rendering Toolkit (Render Kit).
5+
6+
| Minimum Requirements | Description
7+
|:--- |:---
8+
| OS | Linux* Ubuntu* 18.04, CentOS* 8 (or compatible); Windows* 10; MacOS* 10.15+
9+
| Hardware | Intel 64 Penryn or newer with SSE4.1 extensions or an ARM64 with NEON extensions
10+
| Compiler Toolchain | Windows* OS: MSVS 2019 installed with Windows* SDK and CMake*; Other platforms: C++11 compiler and CMake*
11+
| Libraries | Install Render Kit including Intel Implicit SPMD Program Compiler
12+
13+
| Optimized Requirements | Description
14+
| :--- | :---
15+
| Hardware | Intel 64 Skylake or newer with AVX512 extentions or ARM64 with NEON extensions
16+
17+
| Objective | Description
18+
|:--- |:---
19+
| What you will learn | How to build and run a basic Intel ISPC program using the Render Kit distribution.
20+
| Time to complete | 5 minutes
21+
22+
23+
## Purpose
24+
25+
This getting started sample program, `simple`, performs an element wise operation on an input float array. The output is written to stdout.
26+
The sample builds two programs with Intel IPSC. The programs exhibit the same output behavior.
27+
The first program is targeted to x86_64 systems with SSE2 extensions (introduced in the early 2000s).
28+
The second program is multitargeted for systems with SSE2, SSE4, AVX (AVX1), AVX2, and AVX512SKX extensions. The program will runtime detect the highest target extension capability. The program will then run the codepath associated with that capability on the target system.
29+
This initial sample demonstrates Intel ISPC usage with an introductory program running on CPU only. Other Intel Embree and Intel Open VKL sample programs demonstrate usage of ISPC in conjuction with those libraries.
30+
See more about programming with ISPC with the [documentation](https://ispc.github.io/documentation.html).
31+
32+
33+
## Key Implementation Details
34+
35+
- Our c++ program has the typical main entry point defined in simple.cpp. The final program is linked to the compiled ISPC kernel function defined in simple.ispc.
36+
- The function prototype for the kernel is introduced by way of this preprocessor code:
37+
```
38+
#include "simple_ispc.h"
39+
```
40+
- simple.ispc contains the implementation of the kernel function.
41+
- The simple_ispc.h header file is generated by the `ispc` compiler driver when it compiles simple.ispc.
42+
- The first program builds the kernel targeted to SSE2 (Streaming SIMD Extensions 2) ISA extensions introduced on CPUs in the early 2000's.
43+
- Compiling the second program will create an object per ISA extension target, as well as a primary kernel linking object. All objects are linked to generate the final binary. The program will runtime detect the appropriate codepath for the target platform.
44+
45+
###Targeting
46+
47+
- To target ISA extension capability introduced in newer x86_64 processors, see the [targeting table](https://ispc.github.io/ispc.html#selecting-the-compilation-target) in the release notes.
48+
- For targeting ARM64 with NEON extensions. See the [target selection](https://ispc.github.io/ispc.html#selecting-the-compilation-target) in the release notes. Edit the CMakeLists.txt file accordingly for the build step.
49+
- For targeting Intel Graphics Processors, see the article for [ISPC on Gen](https://ispc.github.io/ispc_for_gen.html).
50+
51+
## License
52+
53+
This code sample is licensed under a BSD-3-Clause license. See
54+
[LICENSE.txt](LICENSE.txt) for details.
55+
56+
Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt)
57+
58+
## Build and Run
59+
60+
61+
### Windows OS:
62+
63+
64+
Run a new **x64 Native Tools Command Prompt for MSVS 2019**
65+
66+
```
67+
call <path-to-oneapi-folder>\setvars.bat
68+
cd <path-to-oneAPI-samples>\RenderingToolkit\GettingStarted\05_ispc_gsg
69+
mkdir build
70+
cd build
71+
cmake ..
72+
cmake --build . --config Release
73+
cd Release
74+
.\simple.exe
75+
.\simple_multi.exe
76+
```
77+
78+
Review the output emitted to standard out.
79+
80+
81+
### Linux OS:
82+
83+
Start a new Terminal session
84+
```
85+
source <path-to-oneapi-folder>/setvars.sh
86+
cd <path-to-oneAPI-samples>/RenderingToolkit/GettingStarted/05_ispc_gsg
87+
mkdir build
88+
cd build
89+
cmake ..
90+
cmake --build .
91+
./simple
92+
./simple_multi
93+
```
94+
95+
Review the output emitted to standard out.
96+
97+
### MacOS:
98+
99+
Start a new Terminal session
100+
101+
```
102+
source <path-to-oneapi-folder>/setvars.sh
103+
cd <path-to-oneAPI-samples>/RenderingToolkit/GettingStarted/05_ispc_gsg
104+
mkdir build
105+
cd build
106+
cmake ..
107+
cmake --build .
108+
./simple
109+
./simple_multi
110+
```
111+
112+
Review the output emitted to standard out.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"guid": "BDC6B80E-E764-409D-966B-662CF7EFB072",
3+
"name": "Intel Implicit SIMD Program Compiler (Intel ISPC) Getting Started",
4+
"categories": ["Toolkit/oneAPI Libraries/ISPC"],
5+
"description": "This introductory rendering toolkit sample demonstrates how to compile basic programs with Intel ISPC and the system compiler. Use this sample to further explore developing accelerated applications with Intel Embree and Intel Open VKL.",
6+
"builder": ["cli"],
7+
"languages": [{"c":{}}],
8+
"os":["linux", "windows", "darwin"],
9+
"targetDevice": ["CPU"],
10+
"ciTests": {
11+
"linux": [
12+
{
13+
"id": "Intel_ISPC_ispcHelloWorld_lin",
14+
"steps": [
15+
"mkdir build",
16+
"cd build",
17+
"cmake ..",
18+
"cmake --build . ",
19+
"./simple",
20+
"./simple_multi"
21+
]
22+
}
23+
],
24+
"windows":[
25+
{
26+
"id": "Intel_ISPC_ispcHelloWorld_win",
27+
"steps":[
28+
"mkdir build",
29+
"cd build",
30+
"cmake ..",
31+
"cmake --build . --config Release",
32+
"cd Release",
33+
".\\simple.exe",
34+
".\\simple_multi.exe"
35+
]
36+
37+
}
38+
],
39+
"darwin": [
40+
{
41+
"id": "Intel_ISPC_ispcHelloWorld_mac",
42+
"steps": [
43+
"mkdir build",
44+
"cd build",
45+
"cmake ..",
46+
"cmake --build . ",
47+
"./simple",
48+
"./simple_multi"
49+
]
50+
}
51+
]
52+
}
53+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright (c) 2010-2011, Intel Corporation
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
* Neither the name of Intel Corporation nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#include <stdio.h>
35+
#include <stdlib.h>
36+
37+
// Include the header file that the ispc compiler generates
38+
#include "simple_ispc.h"
39+
using namespace ispc;
40+
41+
int main() {
42+
float vin[16], vout[16];
43+
44+
// Initialize input buffer
45+
for (int i = 0; i < 16; ++i)
46+
vin[i] = (float)i;
47+
48+
// Call simple() function from simple.ispc file
49+
simple(vin, vout, 16);
50+
51+
// Print results
52+
for (int i = 0; i < 16; ++i)
53+
printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]);
54+
55+
return 0;
56+
}

0 commit comments

Comments
 (0)