Skip to content

Commit

Permalink
Rendering toolkit 05ispc sample addition PR (oneapi-src#800)
Browse files Browse the repository at this point in the history
* Update initial master commits to development branch (oneapi-src#789)

* ONSAM-1414 Broken Link in Headers (oneapi-src#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 (oneapi-src#682)

Co-authored-by: JoeOster <[email protected]>
Co-authored-by: ericlars <[email protected]>

* Initial commit for Render Kit 05 ispc sample updates

Signed-off-by: Michael R Carroll <[email protected]>

* Code requirement fixes for RenderKit 05ispc

Signed-off-by: Michael R Carroll <[email protected]>

* include folders are now created during compilation for fix on Linux and Darwin

* Third party program notification updates

Signed-off-by: Michael R Carroll <[email protected]>

* Update RenderingToolkit/GettingStarted/05_ispc_gsg/src/simple.ispc

Co-authored-by: tpyra <[email protected]>

* Update RenderingToolkit/GettingStarted/05_ispc_gsg/src/simple.cpp

Co-authored-by: tpyra <[email protected]>

Co-authored-by: praveenkk123 <[email protected]>
Co-authored-by: JoeOster <[email protected]>
Co-authored-by: ericlars <[email protected]>
Co-authored-by: Piotr Kanclerz <[email protected]>
Co-authored-by: tpyra <[email protected]>
  • Loading branch information
6 people authored Mar 8, 2022
1 parent 06b6eaf commit 7207470
Show file tree
Hide file tree
Showing 10 changed files with 3,339 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .repo-tools/Docs_Automation/guids.json
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,11 @@
"removed": "False",
"ver": "2021.1.Gold"
},
"BDC6B80E-E764-409D-966B-662CF7EFB072": {
"guid": "BDC6B80E-E764-409D-966B-662CF7EFB072",
"ver": "2022.1.0",
"name": "Intel oneAPI Rendering Toolkit ISPC Getting Started: 05_ispc_gsg"
},
"1F8590F3-FA2E-4246-92E4-C1848E9A768E": {
"guid": "1F8590F3-FA2E-4246-92E4-C1848E9A768E",
"name": "Jacobi Iterative",
Expand Down
85 changes: 85 additions & 0 deletions RenderingToolkit/GettingStarted/05_ispc_gsg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
project(ispc_gsg)
cmake_minimum_required(VERSION 3.1)

set(ONEAPI_ROOT "")
if(WIN32)
add_compile_definitions(WIN32)
if(MSVC)
add_compile_options(/EHsc)
endif(MSVC)
endif(WIN32)

if(DEFINED ENV{ONEAPI_ROOT})
set(ONEAPI_ROOT "$ENV{ONEAPI_ROOT}")
message(STATUS "ONEAPI_ROOT FROM ENVIRONMENT: ${ONEAPI_ROOT}")
else()
if(WIN32)
set(ONEAPI_ROOT "C:/Program Files (x86)/Intel/oneAPI")
else()
set(ONEAPI_ROOT /opt/intel/oneapi)
endif()
message(STATUS "ONEAPI_ROOT DEFAULT: ${ONEAPI_ROOT}")
endif(DEFINED ENV{ONEAPI_ROOT})

if (NOT DEFINED ISPC_EXECUTABLE)
find_program (ISPC_EXECUTABLE ispc)
if (NOT ISPC_EXECUTABLE)
message(FATAL_ERROR "Failed to find ispc" )
endif()
endif(NOT DEFINED ISPC_EXECUTABLE)
message(STATUS "ISPC_EXECUTABLE: ${ISPC_EXECUTABLE}")

set (ISPC_SRC_NAME "simple")
set (TARGET_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${ISPC_SRC_NAME}.cpp)
set (ISPC_FLAGS -O2)
set (ISPC_IA_TARGETS "sse2-i32x4")
set (ISPC_ARM_TARGETS "neon")
set (ISPC_OBJ_NAME "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc${CMAKE_CXX_OUTPUT_EXTENSION}")
set (ISPC_HEADER_NAME "${CMAKE_CURRENT_BINARY_DIR}/include-single/${ISPC_SRC_NAME}_ispc.h")
set (OUTPUT_TARGET "${ISPC_IA_TARGETS}")


list(APPEND ISPC_BUILD_OUTPUT ${ISPC_HEADER_NAME} ${ISPC_OBJ_NAME} )
# ISPC command
add_custom_command(OUTPUT ${ISPC_BUILD_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E make_directory "include-single"
COMMAND ${ISPC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.ispc ${ISPC_FLAGS} --target=${ISPC_IA_TARGETS} --arch=x86_64
-h ${ISPC_HEADER_NAME} -o ${ISPC_OBJ_NAME}
VERBATIM
DEPENDS ${ISPC_EXECUTABLE}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")


add_executable(simple ${ISPC_BUILD_OUTPUT} "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
set_target_properties(simple PROPERTIES LINKER_LANGUAGE CXX)
target_sources(simple PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.cpp)
#ISPC emits a header for the ISPC module. The header location is included below
target_include_directories(simple PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include-single)

#Set variables for multiple isa extension targeting.
#Targets with mask and gang
set (ISPC_IA_TARGETS_MG "sse2-i32x4,sse4-i32x4,avx1-i32x8,avx2-i32x8,avx512skx-i32x8")
set (ISPC_IA_TARGETS sse2 sse4 avx avx2 avx512skx)
set (ISPC_ARM_TARGETS "neon")
set (ISPC_OBJ_NAME "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc_multi${CMAKE_CXX_OUTPUT_EXTENSION}")
set (ISPC_HEADER_NAME "${CMAKE_CURRENT_BINARY_DIR}/include-multi/${ISPC_SRC_NAME}_ispc.h")
set (OUTPUT_TARGET "${ISPC_IA_TARGETS}")

list(APPEND ISPC_MULTI_BUILD_OUTPUT ${ISPC_HEADER_NAME} ${ISPC_OBJ_NAME} )
foreach(TARGET_TOKEN IN LISTS ISPC_IA_TARGETS)
list(APPEND ISPC_MULTI_BUILD_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${ISPC_SRC_NAME}_ispc_multi_${TARGET_TOKEN}${CMAKE_CXX_OUTPUT_EXTENSION}")
endforeach()

add_custom_command(OUTPUT ${ISPC_MULTI_BUILD_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E make_directory "include-multi"
COMMAND ${ISPC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc ${ISPC_FLAGS} --target=${ISPC_IA_TARGETS_MG} --arch=x86_64
-h ${ISPC_HEADER_NAME} -o ${ISPC_OBJ_NAME}
VERBATIM
DEPENDS ${ISPC_EXECUTABLE}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")

add_executable(simple_multi ${ISPC_MULTI_BUILD_OUTPUT} "${CMAKE_CURRENT_SOURCE_DIR}/src/${ISPC_SRC_NAME}.ispc")
set_target_properties(simple_multi PROPERTIES LINKER_LANGUAGE CXX)
target_sources(simple_multi PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/simple.cpp)
#ISPC emits a header for the ISPC module. The header location is included below
target_include_directories(simple_multi PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include-multi)
29 changes: 29 additions & 0 deletions RenderingToolkit/GettingStarted/05_ispc_gsg/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright Intel Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
125 changes: 125 additions & 0 deletions RenderingToolkit/GettingStarted/05_ispc_gsg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Getting Started Sample for Intel oneAPI Rendering Toolkit: Intel Implicit SPMD Program Compiler


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).

| Minimum Requirements | Description
|:--- |:---
| OS | Linux* Ubuntu* 18.04, CentOS* 8 (or compatible); Windows* 10; MacOS* 10.15+
| Hardware | Intel 64 Penryn or newer with SSE4.1 extensions; or an ARM64 with NEON extensions
| Compiler Toolchain | Windows* OS: MSVS 2019 installed with Windows* SDK and CMake*; Other platforms: C++11 compiler and CMake*
| Libraries | Install Render Kit including Intel Implicit SPMD Program Compiler

| Optimized Requirements | Description
| :--- | :---
| Hardware | Intel 64 Skylake or newer with AVX512 extensions; or ARM64 with NEON extensions

| Objective | Description
|:--- |:---
| What you will learn | How to build and run a basic Intel ISPC program using the Render Kit distribution.
| Time to complete | 5 minutes


## Purpose

This getting started sample highlights three key basic parts to using Intel ISPC.
1) the Intel ISPC kernel, `simple`.
2) kernel linking into a final program
3) vector hardware extension targeting capability


The `simple` kernel, defined in `simple.ispc`, performs an element wise operation on an input float array. The output is written to stdout.


## Key Implementation Details

### The Kernel and Linking (1 and 2)

- Our sample programs have the main entry point defined in `simple.cpp`. We compile this source to an object with a C++ compiler.
- `simple.ispc` contains the implementation of the kernel function. This source is compiled to an object by the Intel ISPC compiler driver `ispc`.
- The final program is links the C++ object to the Intel ISPC object.
- Within the C++ source, the function prototype for the kernel is introduced by way of this preprocessor code:
```
#include "simple_ispc.h"
```

- Key: The simple_ispc.h header file is generated by the `ispc` compiler driver when it compiles simple.ispc.

### Single and Multitargeting (3)

In this sample, we demonstrate both single and automatic multiple device targeting. Two output programs are built respectively they emit the same output.

- 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.
- 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.

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.
See more about programming with Intel ISPC with the [documentation](https://ispc.github.io/documentation.html).

### Targeting Documentation

- 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.
- 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.
- For targeting Intel Graphics Processors, see the article for [ISPC on Gen](https://ispc.github.io/ispc_for_gen.html).

## License

This code sample is licensed under a BSD-3-Clause license. See
[LICENSE.txt](LICENSE.txt) for details.

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)

## Build and Run


### Windows OS:


Run a new **x64 Native Tools Command Prompt for MSVS 2019**

```
call <path-to-oneapi-folder>\setvars.bat
cd <path-to-oneAPI-samples>\RenderingToolkit\GettingStarted\05_ispc_gsg
mkdir build
cd build
cmake ..
cmake --build . --config Release
cd Release
.\simple.exe
.\simple_multi.exe
```

Review the output emitted to standard out.


### Linux OS:

Start a new Terminal session
```
source <path-to-oneapi-folder>/setvars.sh
cd <path-to-oneAPI-samples>/RenderingToolkit/GettingStarted/05_ispc_gsg
mkdir build
cd build
cmake ..
cmake --build .
./simple
./simple_multi
```

Review the output emitted to standard out.

### MacOS:

Start a new Terminal session

```
source <path-to-oneapi-folder>/setvars.sh
cd <path-to-oneAPI-samples>/RenderingToolkit/GettingStarted/05_ispc_gsg
mkdir build
cd build
cmake ..
cmake --build .
./simple
./simple_multi
```

Review the output emitted to standard out.
53 changes: 53 additions & 0 deletions RenderingToolkit/GettingStarted/05_ispc_gsg/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"guid": "BDC6B80E-E764-409D-966B-662CF7EFB072",
"name": "Intel Implicit SPMD Program Compiler (Intel ISPC) Getting Started: 05_ispc_gsg",
"categories": ["Toolkit/oneAPI Libraries/ISPC"],
"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.",
"builder": ["cli"],
"languages": [{"cpp":{}}],
"os":["linux", "windows", "darwin"],
"targetDevice": ["CPU"],
"ciTests": {
"linux": [
{
"id": "Intel_ISPC_ispcHelloWorld_lin",
"steps": [
"mkdir build",
"cd build",
"cmake ..",
"cmake --build . ",
"./simple",
"./simple_multi"
]
}
],
"windows":[
{
"id": "Intel_ISPC_ispcHelloWorld_win",
"steps":[
"mkdir build",
"cd build",
"cmake ..",
"cmake --build . --config Release",
"cd Release",
".\\simple.exe",
".\\simple_multi.exe"
]

}
],
"darwin": [
{
"id": "Intel_ISPC_ispcHelloWorld_mac",
"steps": [
"mkdir build",
"cd build",
"cmake ..",
"cmake --build . ",
"./simple",
"./simple_multi"
]
}
]
}
}
55 changes: 55 additions & 0 deletions RenderingToolkit/GettingStarted/05_ispc_gsg/src/simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright (c) 2010-2022, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <stdlib.h>

// Include the header file that the ispc compiler generates
#include "simple_ispc.h"
using namespace ispc;

int main() {
float vin[16], vout[16];

// Initialize input buffer
for (int i = 0; i < 16; ++i) vin[i] = (float)i;

// Call simple() function from simple.ispc file
simple(vin, vout, 16);

// Print results
for (int i = 0; i < 16; ++i)
printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]);

return 0;
}
Loading

0 comments on commit 7207470

Please sign in to comment.