Page MenuHomePhabricator

Testing OpenCL Through SPIR-V
Updated 1,030 Days AgoPublic

WARNING: I do a lot of rebasing and push force since it remains a lot of hacking, so beware of that when updating your local copy. See further down, in the “How to Update?” section.

How Can You Test?

NOTE: This page contains information about the different supported NVIDIA GPU families and OpenCL features. From time to time you will find a new blog post here discussing what's the current status.

For now, since not many features are usable, it is best to use rSPVTES for testing. If you are using a version that supports clCreateProgramWithSource(), you can also use Tom Stellar's OpenCL examples. Either way, you just need to clone the repository, run make to build the examples, source the env file containing the paths to the custom LLVM and Mesa, and run the executables.

Here is a list of the examples included in Tom Stellar’s repository, and whether or not they are supported:

  • copy-host-ptr
  • get-global-id (G80+)
  • get-global-id2d (G80+)
  • get-global-id-3d (G80+)
  • hello_world (G80+)
  • if (G80+)
  • loop (Tesla)
  • math-int (G80+)
  • mat-mul
  • memset (G80+)
  • use-host-ptr
  • vec-load (G80+)

You can also try to run your own custom kernels, as long as you use features marked as supported on the current status page; for more details on which SPIR-V opcodes are supported, have a look at that page.

What Do You Need?

  • Branch nouveau_spirv_support of rMESA to get:
    • nv50 advertising compute support, and being able to launch kernels;
    • translation from SPIR-V to NVIR.

How to Set Up Everything?

NOTE: This script (P74) will automate everything discribed below.
  1. Let's start by cloning LLVM:
git clone -b khronos/spirv-3.6.1 llvm
  1. Now we need clang:
cd ${PATH_TO_LLVM}/llvm/tools
git clone -b spirv-1.0 clang
  1. Let's compile LLVM and clang.
mkdir llvm_build
cd llvm_build
make install
  1. Rather than reimplement a SPIR-V linker as well as a SPIR-V validator, let’s use those from SPIRV-Tools:
git clone  -b for_nouveau spvtools
cd spvtools/external
git clone
git clone spirv-headers
  1. To build SPIRV-Tools, run:
mkdir spvtools_build
cd spvtools_build
make install
  1. To get Mesa, run:
git clone -b nouveau_spirv_support mesa
  1. Compile Mesa by running:
mkdir mesa_build
cd mesa_build
../mesa/ --prefix=${MESA_INSTALL_PREFIX} --enable-llvm --with-dri-drivers= --with-gallium-drivers=nouveau --enable-opencl --with-llvm-prefix=${LLVM_INSTALL_PREFIX} --enable-debug
# or to get a minimal build with only nouveau
../mesa/ --prefix=${MESA_INSTALL_PREFIX} --disable-gles1 --disable-gles2 --disable-gbm --disable-egl --disable-osmesa --disable-xvmc --disable-va --disable-vdpau --enable-llvm -with-dri-drivers= --enable-dri3 --with-gallium-drivers=nouveau --enable-opencl --with-llvm-prefix=${LLVM_INSTALL_PREFIX} --enable-debug
make install

How to Update?

After setting up everything and waiting a couple of days, there might be some new changes/fixes available upstream (aka. my local repository). Since I tend to do a lot of rebasing (either to squash fixes with the corresponding initial commit, or rebase on top of master to stay up-to-date), running a simple git pull might yield a lot of merge conflicts. You will need to run the following code inside ${PATH_TO_LLVM}/llvm, ${PATH_TO_LLVM}/llvm/tools/clang, ${PATH_TO_SPVTOOLS}/spvtools and ${PATH_TO_MESA}/mesa (though I expect most of the updates to be found inside Mesa, and a few in SPIRV-Tools):

git fetch
git status
# This will say something like "Your branch and 'origin/nouveau_spirv_support' have diverged,
# and have 75 and 67 different commits each, respectively."
# The first number, 75 in this case, is the one to be used instead of ${SOME_NUMBER} in the following command
git reset HEAD~${SOME_NUMBER} --hard
git pull

Of course, if some changes were made, you will need to rebuild those projects (note that if clang is modified, you rebuild LLVM directly).

# To rebuild LLVM and/or clang
cd ${PATH_TO_LLVM}/llvm_build
make install
# To rebuild SPIRV-Tools
cd ${PATH_TO_SPVTOOLS}/spvtools_build
make install
# To rebuild Mesa
cd ${PATH_TO_MESA}/mesa_build
make install
Last Author
Last Edited
Dec 2 2017, 4:58 PM

Event Timeline

pmoreau edited the content of this document. (Show Details)
pmoreau changed the title from Testing OpenCL Through Spirv to Testing OpenCL Through SPIR-V.Dec 31 2015, 8:37 PM
pmoreau edited the content of this document. (Show Details)
pmoreau edited the content of this document. (Show Details)
pmoreau added a project: Mesa.
pmoreau edited the content of this document. (Show Details)