This webpage contains the appendices and additional material for the paper entitled Taming the complexities of the C11 and OpenCL memory models by John Wickerson and Mark Batty.
We provide copies of the OpenCL 2.0 specification documents for the convenience of reviewers. The documents in the Khronos registry have been slightly revised recently, which may invalidate the line and page numbers that we refer to in our paper.
The source code of herd is available to download from a github repository.
To build the herd executable, simply runmake in the
herd directory. To instruct herd to exhaustively
simulate a given litmus test (say, foo.litmus)
according to a given model definition (say, bar.cat),
issue the following command:
./herd -model path/to/bar.cat path/to/foo.litmusTo display the executions in graphical form, issue the following command, which launches Ghostview in an X11 session and sets some reasonable configuration options:
./herd -model path/to/bar.cat -show all -gv -graph columns ↵ -initwrites true -showinitwrites false -squished true ↵ -scale 2 -symetric dr path/to/foo.litmusThe sections below provide links to download our
.cat
models and some .litmus
tests for experimenting with our models.
The following .cat file describes the C11 memory
model and uses a partial order over SC operations:
The following .cat file describes a simpler and
slightly stronger version of the C11 memory model:
Those definitions that are common to both
c11_partialSC.cat and c11_simp.cat are
factored out into a separate .cat file that is then
imported by both:
cppmem' are ported directly from examples
distributed with the CppMem
tool.
mp_relacq.litmus
mp_relaxed.litmusx.mp_fences.litmusmp_relacq_rs.litmusy that appears in the
release sequence.mp_sc.litmuscppmem_iriw_relacq.litmusP2) and
(P3) can observe the writes to x and
y in different orders.iriw_sc.litmuscppmem_partial_sb.litmuscppmem_sc_atomics.litmuscppmem_unsequencedrace.litmusc11_partialSC.cat and Batty's
original formalisation in Lem.
.cat file describes the OpenCL 2.0 memory
model:
We provide several litmus tests for exploring the model:
MP_ra_dev.litmusy prevents reading a
stale value of x. The use of device scope is sufficient
here because the two threads are executing on the same device.MP_ra_wg.litmusy. This is insufficient because the two threads are in
different work-groups, and causes the program to be faulty.MP_ra_dev_broken.litmusMP_ra_dev.litmus
test above, but the two threads are in different devices. This means
that the release/acquire
synchronisation at device scope is no longer sufficient. Hence, the
program is faulty.MP_sc_dev.litmusMP_ra_dev.litmus test above,
but it uses SC atomics to access the atomic flag
y. This is sufficient to induce synchronisation because
the SC memory order subsumes both the release and the acquire memory
orders.MP_ra_dev_localflag.litmusMP_ra_dev.litmus test above, but puts the atomic flag
y in local rather than global memory. This inhibits the
global happens-before edges that are necessary to separate the
non-atomic accesses to x, thus causing a data race,
which renders the whole program faulty.MP_ra_sc_global_local.litmusMP_ra_dev_localflag.litmus test above, but it inserts
global-and-local fences in order to avoid the data race on
x. Thanks to the global-and-local fences, the
release/acquire synchronisation on the local flag
y induces a global happens-before edge.ISA2.litmusx from
thread P0 to thread P2. This is achieved
by release/acquire synchronisation between P0 and
thread P1 in the same work-group, on the atomic flag
y using work-group scope, followed by release/acquire
synchronisation between P1 and P2 in a
different work-group, on the atomic flag z using device
scope. ISA2_broken.litmusy in local rather than global memory. This inhibits the
global happens-before edges that are necessary to separate the
non-atomic accesses to x, thus causing a data race,
which renders the whole program faulty.
IRIW_sc_wg.litmusiriw_sc.litmus test given in C11 above, but the SC
operations are annotated with work-group scope. This prevents the SC
operations from being chained into a total order, and thus allows
the reading threads to see the writes to x and
y in two different orders.IRIW_sc_dev.litmusIRIW_sc_wg.litmus test above, except
that the SC operations are now upgraded to device scope. This means
that the SC operations are now chained into a total order,
and the relaxed behaviour exhibited in the previous test is no
longer permitted.