Page MenuHomePhabricator

Testing OpenCL Through SPIR-V
Updated 380 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:
cd ${PATH_TO_LLVM}
git clone -b khronos/spirv-3.6.1 https://github.com/pierremoreau/SPIRV-LLVM.git llvm
  1. Now we need clang:
cd ${PATH_TO_LLVM}/llvm/tools
git clone -b spirv-1.0 https://github.com/KhronosGroup/SPIR clang
  1. Let's compile LLVM and clang.
cd ${PATH_TO_LLVM}
mkdir llvm_build
cd llvm_build
cmake -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_PREFIX}" -DBUILD_SHARED_LIBS=On -DLLVM_TARGETS_TO_BUILD="X86" -DSPIRV_USE_LLVM_API=On  ../llvm
make install
  1. Rather than reimplement a SPIR-V linker as well as a SPIR-V validator, let’s use those from SPIRV-Tools:
cd ${PATH_TO_SPVTOOLS}
git clone  -b for_nouveau https://github.com/pierremoreau/SPIRV-Tools.git spvtools
cd spvtools/external
git clone https://github.com/google/googletest.git
git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
  1. To build SPIRV-Tools, run:
cd ${PATH_TO_SPVTOOLS}
mkdir spvtools_build
cd spvtools_build
cmake -DCMAKE_INSTALL_PREFIX="${SPVTOOLS_INSTALL_PREFIX}" -DCMAKE_BUILD_TYPE=Release -DSPIRV_BUILD_COMPRESSION=ON ../spvtools
make install
  1. To get Mesa, run:
cd ${PATH_TO_MESA}
git clone -b nouveau_spirv_support https://phabricator.pmoreau.org/diffusion/MESA/mesa.git mesa
  1. Compile Mesa by running:
cd ${PATH_TO_MESA}
mkdir mesa_build
cd mesa_build
../mesa/autogen.sh --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/autogen.sh --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
pmoreau
Last Edited
Dec 2 2017, 4:58 PM

Event Timeline

pmoreau created this document.Dec 31 2015, 8:00 PM
pmoreau edited the content of this document. (Show Details)
pmoreau edited the content of this document. (Show Details)Dec 31 2015, 8:17 PM
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)Jan 9 2016, 6:47 PM
pmoreau edited the content of this document. (Show Details)Jan 10 2016, 1:04 PM
pmoreau edited the content of this document. (Show Details)Jan 13 2016, 3:08 PM
pmoreau edited the content of this document. (Show Details)Jan 13 2016, 3:29 PM
pmoreau edited the content of this document. (Show Details)Jan 13 2016, 3:36 PM
pmoreau edited the content of this document. (Show Details)Jan 14 2016, 11:32 PM
pmoreau edited the content of this document. (Show Details)Jan 18 2016, 10:51 PM
pmoreau edited the content of this document. (Show Details)Jan 19 2016, 7:18 PM
pmoreau edited the content of this document. (Show Details)
pmoreau edited the content of this document. (Show Details)Jan 19 2016, 7:51 PM
pmoreau edited the content of this document. (Show Details)Jan 19 2016, 7:59 PM
pmoreau edited the content of this document. (Show Details)Jan 19 2016, 8:11 PM
pmoreau edited the content of this document. (Show Details)Jan 19 2016, 8:36 PM
pmoreau edited the content of this document. (Show Details)Feb 6 2016, 1:07 PM
pmoreau edited the content of this document. (Show Details)Feb 6 2016, 1:12 PM
pmoreau edited the content of this document. (Show Details)Feb 6 2016, 1:28 PM
pmoreau edited the content of this document. (Show Details)Mar 6 2016, 6:07 PM
pmoreau edited the content of this document. (Show Details)Mar 13 2016, 11:55 PM
pmoreau edited the content of this document. (Show Details)Mar 14 2016, 10:47 PM
pmoreau edited the content of this document. (Show Details)Apr 22 2016, 9:08 PM
pmoreau edited the content of this document. (Show Details)Apr 23 2016, 2:06 AM
pmoreau edited the content of this document. (Show Details)Jul 22 2016, 10:45 PM
pmoreau edited the content of this document. (Show Details)Aug 22 2016, 1:00 AM
pmoreau edited the content of this document. (Show Details)Apr 20 2017, 10:23 AM
pmoreau added a project: Mesa.
pmoreau edited the content of this document. (Show Details)Apr 20 2017, 10:29 AM
pmoreau edited the content of this document. (Show Details)
pmoreau edited the content of this document. (Show Details)Apr 20 2017, 5:25 PM
pmoreau edited the content of this document. (Show Details)May 6 2017, 6:10 PM
pmoreau edited the content of this document. (Show Details)Jun 27 2017, 5:33 PM
pmoreau edited the content of this document. (Show Details)Sep 18 2017, 7:46 PM
pmoreau edited the content of this document. (Show Details)Sep 18 2017, 8:21 PM
pmoreau edited the content of this document. (Show Details)Sep 19 2017, 12:42 AM
pmoreau edited the content of this document. (Show Details)Sep 20 2017, 11:41 PM
pmoreau edited the content of this document. (Show Details)Oct 22 2017, 8:56 PM
pmoreau edited the content of this document. (Show Details)Nov 6 2017, 1:40 AM
pmoreau edited the content of this document. (Show Details)Dec 2 2017, 4:58 PM