Skip to content

Instantly share code, notes, and snippets.

@vincentisambart
vincentisambart / gpu-control-flow.md
Created February 1, 2023 11:48
GPU control flow

GPU control flow

As I was trying to understand compute shaders, I had trouble grasping how the control flow was handled but I think I finally got it, so in case my understanding might help someone here it is. That should be mostly API agnostic.

For me it clicked when I tried to think about how I would write what a single wave/warp does with pseudo SIMD instructions and execution masks.

If you need some refresher on the confusing vocabulary, I'd recommend the Compute Shader 101 Glossary.

Condition

# Warning: BUILD_DIRECTORY must be an absolute path for this script to work properly
rm -rf $BUILD_DIRECTORY
ARCHIVE_PATH=$BUILD_DIRECTORY/$TARGET.xcarchive
IPA_PATH=$BUILD_DIRECTORY/$TARGET.ipa
xcodebuild -workspace $WORKSPACE -scheme $SCHEME -derivedDataPath $BUILD_DIRECTORY -archivePath $ARCHIVE_PATH archive
# As xcodebuild -exportArchive doesn't seem to work properly with WatchKit apps, I ended up making the IPA file by hand.
# https://devforums.apple.com/message/1120211#1120211 has some information about doing that.
" vim: fileencoding=utf8
set termencoding=utf-8
scriptencoding utf8
set nocompatible
set backspace=indent,eol,start
set ru showcmd showmatch
set incsearch
set nowrap
set iminsert=0 imsearch=0
set expandtab softtabstop=2 shiftwidth=2
#!/usr/bin/env ruby
USR_LOCAL_INCLUDE = '/usr/local/include'
def include_paths(language)
include_paths = []
in_list = false
# LANG=C is forces cpp to output messages in English
cpp_output = `LANG=C cpp -x #{language} -v < /dev/null 2>&1`
cpp_output.each_line do |line|
line.strip!
if in_list
Problem 1:
Code:
class A; def to_ary; [1, 2, 3, 4]; end; end
a, b, *, c = A.new
p [a, b, c]
Arch: default
Command: jruby --1.9
Expectation: [1, 2, 4]
Output: [#<A:0x2f2295>, nil, #<A:0x2f2295>]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>test</title>
<script src="http://maps.google.co.jp/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript">
function init() {
var latLng = new google.maps.LatLng(35.660617498849, 139.72924947738647);
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>test</title>
<script src="http://maps.google.co.jp/maps?file=api&amp;hl=ja&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAaGrpYL1xB0gxisU-6UlcSRT6suOry0oJYFaXw8CSwv7fUN3XBxSly8NKZzOwK3Ypuaq7h2eHx9UNCg" type="text/javascript"></script>
<script type="text/javascript">
function init() {
var div = document.getElementById('mydiv');
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>test</title>
<script src="http://maps.google.co.jp/maps?file=api&amp;hl=ja&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAaGrpYL1xB0gxisU-6UlcSRT6suOry0oJYFaXw8CSwv7fUN3XBxSly8NKZzOwK3Ypuaq7h2eHx9UNCg" type="text/javascript"></script>
<script type="text/javascript">
function init() {
var div = document.getElementById('mydiv');