Igor Ostrovsky, a software engineer, writes explanatory posts on CPU caches, branch prediction, RAID, GPUs, and the C# memory model.
HN commenters call the whole blog a nice read and link its processor cache effects gallery, RAID-6 explanation, and volatile keyword memory model post.
Long time ago, I've did some experiments with luajit and branching (well more like the CPU). It was based on this article: http://igoro.com/archive/fast-and-slow-if-statements-branch-prediction-in-modern-processors/
https://raw.githubusercontent.com/malkia/ufo/master/samples/bench/badif.lua
local ffi = require("ffi")
local band = bit.band
local function test(n, m)
local count = 0; for i=1, n do if band(i, m)==0 then count = count + 1 end end return count
end
local function timeit(m)
local t = os.clock()
test(0xFFFFFFF,m)
local t = os.clock() - t
print(string.format("%08X",m),t)
end
timeit(0x80000000)
timeit(0xffffffff)
timeit(1)
timeit(3)
timeit(2)
timeit(4)
timeit(8)
timeit(16)
--[[
-- This is on OSX 10.7.2 MBP 2008 Jan build
./luajit samples/badif.lua
80000000 14.067395
FFFFFFFF 20.252955
00000001 13.497108
00000003 17.337942
00000002 14.142266
00000004 14.221376
00000008 14.42377
00000010 14.708237
--]]
Results now - 2015 (again Macbook OSX, much better than before and also luajit 2.0.4):
80000000 0.247822
FFFFFFFF 1.253168
00000001 0.664586
00000003 0.974336
00000002 0.676823
00000004 0.679609
00000008 0.675207
00000010 0.673961
without jit, just interpretter (pretty much the same results):
$ src/luajit -joff ~/badif.lua
80000000 3.329909
FFFFFFFF 3.553143
00000001 3.440378
00000003 3.484646
00000002 3.424834
00000004 3.424539
00000008 3.616981
…
Good question.
I can't find a single SPIR-V AXPY (a*X+y) example which is the Hello World of linear algebra in Vulkan/SPIR-V so I'm not optimistic on ease of use.
You can probably do texture hacks like what people did in 2006 when they realized that GPU were fast for linear algebra and OpenCL/Cuda did not exist (https://igoro.com/archive/how-gpu-came-to-be-used-for-general-computation/)
The best would probably be to follow this Halide issue and the corresponding branches: https://github.com/halide/Halide/issues/2296. Note that Halide is a compiler so it automates lots of the boilerplate that is probably needed to Vulkan for compute compared to Cuda.
Do you have some more detaile about your app?
I use perf, sysprof, trace32, visual studio profiler for profiling, but this highly depends on your environment.
These assorted links might be interesting to you:
- https://github.com/Kobzol/hardware-effects
- https://www.youtube.com/watch?v=FJJTYQYB1JQ
- https://godbolt.org/
- http://igoro.com/archive/gallery-of-processor-cache-effects/
This is a nice read too (the whole blog actually)
http://igoro.com/archive/volatile-keyword-in-c-memory-model-explained/
It's a bit old by now (2010), but I always remembered the mental model Igor created.
On a related node, this page also has an interesting visualisation of the effects of cache misses on program performance: http://igoro.com/archive/gallery-of-processor-cache-effects
Link below with more info, for those who were interested like me!
http://igoro.com/archive/how-raid-6-dual-parity-calculation-works/