Skip to content

Commit 7207470

Browse files
MichaelRoyceCarrollpraveenkk123JoeOsterericlarsKanclerzPiotr
authored
Rendering toolkit 05ispc sample addition PR (#800)
* Update initial master commits to development branch (#789) * ONSAM-1414 Broken Link in Headers (#685) * Update Makefile * Update Makefile * Update Makefile * Update DCT.hpp * Update intrin_ftz_sample.cpp * Update merge_sort.cpp * Update intrin_double_sample.cpp * Update intrin_dot_sample.cpp * Update DCT.cpp * fix deprecation notice (#682) Co-authored-by: JoeOster <52936608+JoeOster@users.noreply.github.com> Co-authored-by: ericlars <eric.larson@intel.com> * Initial commit for Render Kit 05 ispc sample updates Signed-off-by: Michael R Carroll <michael.carroll@alumni.usc.edu> * Code requirement fixes for RenderKit 05ispc Signed-off-by: Michael R Carroll <michael.carroll@alumni.usc.edu> * include folders are now created during compilation for fix on Linux and Darwin * Third party program notification updates Signed-off-by: Michael R Carroll <michael.carroll@alumni.usc.edu> * Update RenderingToolkit/GettingStarted/05_ispc_gsg/src/simple.ispc Co-authored-by: tpyra <tomasz.pyra@intel.com> * Update RenderingToolkit/GettingStarted/05_ispc_gsg/src/simple.cpp Co-authored-by: tpyra <tomasz.pyra@intel.com> Co-authored-by: praveenkk123 <praveen.k.kundurthy@intel.com> Co-authored-by: JoeOster <52936608+JoeOster@users.noreply.github.com> Co-authored-by: ericlars <eric.larson@intel.com> Co-authored-by: Piotr Kanclerz <piotr.kanclerz@intel.com> Co-authored-by: tpyra <tomasz.pyra@intel.com>
1 parent 06b6eaf commit 7207470

File tree

10 files changed

+3339
-0
lines changed

10 files changed

+3339
-0
lines changed

.repo-tools/Docs_Automation/guids.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,11 @@
12131213
"removed": "False",
12141214
"ver": "2021.1.Gold"
12151215
},
1216+
"BDC6B80E-E764-409D-966B-662CF7EFB072": {
1217+
"guid": "BDC6B80E-E764-409D-966B-662CF7EFB072",
1218+
"ver": "2022.1.0",
1219+
"name": "Intel oneAPI Rendering Toolkit ISPC Getting Started: 05_ispc_gsg"
1220+
},
12161221
"1F8590F3-FA2E-4246-92E4-C1848E9A768E": {
12171222
"guid": "1F8590F3-FA2E-4246-92E4-C1848E9A768E",
12181223
"name": "Jacobi Iterative",
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 ${CMAKE_COMMAND} -E make_directory "include-single"
46+
COMMAND ${ISPC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.ispc ${ISPC_FLAGS} --target=${ISPC_IA_TARGETS} --arch=x86_64
47+
-h ${ISPC_HEADER_NAME} -o ${ISPC_OBJ_NAME}
48+
VERBATIM
49+
DEPENDS ${ISPC_EXECUTABLE}
50+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
51+
52+
53+
add_executable(simple ${ISPC_BUILD_OUTPUT} "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
54+
set_target_properties(simple PROPERTIES LINKER_LANGUAGE CXX)
55+
target_sources(simple PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.cpp)
56+
#ISPC emits a header for the ISPC module. The header location is included below
57+
target_include_directories(simple PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include-single)
58+
59+
#Set variables for multiple isa extension targeting.
60+
#Targets with mask and gang
61+
set (ISPC_IA_TARGETS_MG "sse2-i32x4,sse4-i32x4,avx1-i32x8,avx2-i32x8,avx512skx-i32x8")
62+
set (ISPC_IA_TARGETS sse2 sse4 avx avx2 avx512skx)
63+
set (ISPC_ARM_TARGETS "neon")
64+
set (ISPC_OBJ_NAME "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc_multi${CMAKE_CXX_OUTPUT_EXTENSION}")
65+
set (ISPC_HEADER_NAME "${CMAKE_CURRENT_BINARY_DIR}/include-multi/${ISPC_SRC_NAME}_ispc.h")
66+
set (OUTPUT_TARGET "${ISPC_IA_TARGETS}")
67+
68+
list(APPEND ISPC_MULTI_BUILD_OUTPUT ${ISPC_HEADER_NAME} ${ISPC_OBJ_NAME} )
69+
foreach(TARGET_TOKEN IN LISTS ISPC_IA_TARGETS)
70+
list(APPEND ISPC_MULTI_BUILD_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc_multi_${TARGET_TOKEN}${CMAKE_CXX_OUTPUT_EXTENSION}")
71+
endforeach()
72+
73+
add_custom_command(OUTPUT ${ISPC_MULTI_BUILD_OUTPUT}
74+
COMMAND ${CMAKE_COMMAND} -E make_directory "include-multi"
75+
COMMAND ${ISPC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc ${ISPC_FLAGS} --target=${ISPC_IA_TARGETS_MG} --arch=x86_64
76+
-h ${ISPC_HEADER_NAME} -o ${ISPC_OBJ_NAME}
77+
VERBATIM
78+
DEPENDS ${ISPC_EXECUTABLE}
79+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
80+
81+
add_executable(simple_multi ${ISPC_MULTI_BUILD_OUTPUT} "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
82+
set_target_properties(simple_multi PROPERTIES LINKER_LANGUAGE CXX)
83+
target_sources(simple_multi PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.cpp)
84+
#ISPC emits a header for the ISPC module. The header location is included below
85+
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: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 extensions; 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 highlights three key basic parts to using Intel ISPC.
26+
1) the Intel ISPC kernel, `simple`.
27+
2) kernel linking into a final program
28+
3) vector hardware extension targeting capability
29+
30+
31+
The `simple` kernel, defined in `simple.ispc`, performs an element wise operation on an input float array. The output is written to stdout.
32+
33+
34+
## Key Implementation Details
35+
36+
### The Kernel and Linking (1 and 2)
37+
38+
- Our sample programs have the main entry point defined in `simple.cpp`. We compile this source to an object with a C++ compiler.
39+
- `simple.ispc` contains the implementation of the kernel function. This source is compiled to an object by the Intel ISPC compiler driver `ispc`.
40+
- The final program is links the C++ object to the Intel ISPC object.
41+
- Within the C++ source, the function prototype for the kernel is introduced by way of this preprocessor code:
42+
```
43+
#include "simple_ispc.h"
44+
```
45+
46+
- Key: The simple_ispc.h header file is generated by the `ispc` compiler driver when it compiles simple.ispc.
47+
48+
### Single and Multitargeting (3)
49+
50+
In this sample, we demonstrate both single and automatic multiple device targeting. Two output programs are built respectively they emit the same output.
51+
52+
- The first build target program, `simple`, builds with the simple.ispc kernel targeted to SSE2 (Streaming SIMD Extensions 2) ISA extensions. These extensions were introduced on CPUs in the early 2000's.
53+
- The second build target program, `simple_multi`, will create an object per ISA extension target, as well as a primary kernel linking object. All objects are then linked to generate the final binary. The program will runtime detect the appropriate codepath for the target platform.
54+
55+
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.
56+
See more about programming with Intel ISPC with the [documentation](https://ispc.github.io/documentation.html).
57+
58+
### Targeting Documentation
59+
60+
- 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.
61+
- 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.
62+
- For targeting Intel Graphics Processors, see the article for [ISPC on Gen](https://ispc.github.io/ispc_for_gen.html).
63+
64+
## License
65+
66+
This code sample is licensed under a BSD-3-Clause license. See
67+
[LICENSE.txt](LICENSE.txt) for details.
68+
69+
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)
70+
71+
## Build and Run
72+
73+
74+
### Windows OS:
75+
76+
77+
Run a new **x64 Native Tools Command Prompt for MSVS 2019**
78+
79+
```
80+
call <path-to-oneapi-folder>\setvars.bat
81+
cd <path-to-oneAPI-samples>\RenderingToolkit\GettingStarted\05_ispc_gsg
82+
mkdir build
83+
cd build
84+
cmake ..
85+
cmake --build . --config Release
86+
cd Release
87+
.\simple.exe
88+
.\simple_multi.exe
89+
```
90+
91+
Review the output emitted to standard out.
92+
93+
94+
### Linux OS:
95+
96+
Start a new Terminal session
97+
```
98+
source <path-to-oneapi-folder>/setvars.sh
99+
cd <path-to-oneAPI-samples>/RenderingToolkit/GettingStarted/05_ispc_gsg
100+
mkdir build
101+
cd build
102+
cmake ..
103+
cmake --build .
104+
./simple
105+
./simple_multi
106+
```
107+
108+
Review the output emitted to standard out.
109+
110+
### MacOS:
111+
112+
Start a new Terminal session
113+
114+
```
115+
source <path-to-oneapi-folder>/setvars.sh
116+
cd <path-to-oneAPI-samples>/RenderingToolkit/GettingStarted/05_ispc_gsg
117+
mkdir build
118+
cd build
119+
cmake ..
120+
cmake --build .
121+
./simple
122+
./simple_multi
123+
```
124+
125+
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 SPMD Program Compiler (Intel ISPC) Getting Started: 05_ispc_gsg",
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 C++ compiler. Use this sample to further explore developing accelerated applications with Intel Embree and Intel Open VKL.",
6+
"builder": ["cli"],
7+
"languages": [{"cpp":{}}],
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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright (c) 2010-2022, 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) vin[i] = (float)i;
46+
47+
// Call simple() function from simple.ispc file
48+
simple(vin, vout, 16);
49+
50+
// Print results
51+
for (int i = 0; i < 16; ++i)
52+
printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]);
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)