https://github.com/adamrehn/spirv-installer
SPIR-V Toolchain Installer
https://github.com/adamrehn/spirv-installer
Last synced: 7 months ago
JSON representation
SPIR-V Toolchain Installer
- Host: GitHub
- URL: https://github.com/adamrehn/spirv-installer
- Owner: adamrehn
- License: mit
- Created: 2016-09-14T04:21:51.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-14T12:57:43.000Z (about 9 years ago)
- Last Synced: 2025-01-08T12:50:53.153Z (9 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SPIR-V Toolchain Installer
==========================This Python script downloads and builds the [Khronos OpenCL C++ compiler for SPIR-V](https://github.com/KhronosGroup/SPIR/tree/spirv-1.1) and the [SPIR-V Tools](https://github.com/KhronosGroup/SPIRV-Tools) from source, and generates a platform-specific installation package.
Prerequisites
-------------The following tools are required to be in the system PATH:
- [Python](https://www.python.org/) 3.x
- [Git](https://git-scm.com/)
- [Cmake](https://cmake.org/)
- A C++11-compliant compiler:
- GCC or Clang under macOS and Linux
- Visual Studio under Windows (be sure to run `vcvarsall.bat` to add `cl.exe` to the PATH)
- `zip` under macOS and Linux
- [Nullsoft Scriptable Install System (NSIS)](http://nsis.sourceforge.net/) under Windows (preferably the [64-bit version](https://bitbucket.org/dgolub/nsis64))Generating the installer
------------------------To generate the installation package for your platform, simply run:
```
python3 generate-installer.py
```Under Windows, an installer executable is generated. To install, simply run the installer.
Under macOS and Linux, a ZIP file is generated that contains the required files and an installation script. To install, extract the ZIP file, and then run the following command inside the directory where the files were extracted:
```
sudo ./install.sh
```Compiling OpenCL kernels
------------------------In addition to installing the SPIR-V-enabled version of Clang under the name `spirv-clang`, two convenience wrappers are also provided to simplify compilation of OpenCL kernels:
- `spirv-cc` invokes `spirv-clang` with the necessary arguments for compiling OpenCL C code
- `spirv-c++` invokes `spirv-clang` with the necessary arguments for compiling OpenCL C++ code### Compiling OpenCL C Code
Assume we have the following OpenCL C code in the file `example-c.cl`:
```
__kernel void example()
{
int globalThreadIdx = get_global_id(0);
printf("This is thread %d", globalThreadIdx);
}
```We can compile the kernel using `spirv-clang` directly like so:
```
spirv-clang -cc1 -emit-spirv -triple spir-unknown-unknown -x cl -cl-std=CL2.0 -include opencl.h example-c.cl -o example-c.spv
```Or we can compile it using the convenience wrapper like so:
```
spirv-cc example-c.cl -o example-c.spv
```### Compiling OpenCL C++ Code
Assume we have the following OpenCL C++ code in the file `example-cxx.cl`:
```
#include
#include__kernel void example()
{
int globalThreadIdx = cl::get_global_id(0);
cl::printf("This is thread %d", globalThreadIdx);
}
```We can compile the kernel using `spirv-clang` directly like so (note that the path to the `openclc++` headers directory will vary based on the platform. Under macOS and Linux the installer places it in `/usr/local/spirv/1.1/include/openclc++`, under Windows with the default install location it will be in `C:\Program Files\SPIR-V\spirv\1.1\include\openclc++`):
```
spirv-clang -cc1 -emit-spirv -triple spir-unknown-unknown -x cl -cl-std=c++ -I/path/to/openclc++ example-cxx.cl -o example-cxx.spv
```Or we can compile it using the convenience wrapper like so:
```
spirv-c++ example-cxx.cl -o example-cxx.spv
```License
-------The Python script is licensed under the MIT License. See the repositories for the [Khronos OpenCL C++ compiler for SPIR-V](https://github.com/KhronosGroup/SPIR/tree/spirv-1.1) and the [SPIR-V Tools](https://github.com/KhronosGroup/SPIRV-Tools) for the license details of those projects.