<div class="gmail_quote">On Fri, Nov 18, 2011 at 8:52 PM, Jonathan Ragan-Kelley <span dir="ltr"><<a href="mailto:jrk@csail.mit.edu">jrk@csail.mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Looking further during down time at the dev meeting today, it actually<br>
seems that PTX atom.* and red.* intrinsics map extremely naturally<br>
onto the LLVM atomicrmw and cmpxchg instructions. The biggest issue is<br>
that a subset of things expressible with these LLVM instructions do<br>
not trivially map to PTX, and the range of things naturally supported<br>
depends on the features of a given target. With sufficient effort, all<br>
possible uses of these instructions could be emulated on all targets,<br>
at the cost of efficiency, but this would significantly complicate the<br>
codegen and probably produce steep performance cliffs.<br>
<br>
The basic model:<br>
<br>
  %d = cmpxchg {T}* %a, {T} %b, {T} %c<br>
  --> atom.{space of %a}.cas.{T} d, [a], b, c<br>
<br>
  %d = atomicrmw {OP} {T}* %a, {T} b<br>
  --> atom.{space of %a}.{OP}.{T} d, [a], b<br>
  for op in { add, and, or, xor, min, max, xchg }<br>
<br>
with the special cases:<br>
<br>
  %d is unused --> red.{space of %a}.{OP}.{T} d, [a], b   # i.e. use<br>
the reduce instr instead of the atom instr<br>
<br>
  {OP} == {add, sub} && b == 1 --> use PTX inc/dec op<br>
<br>
I think the right answer for the indefinite future is to map exactly<br>
those operations and types which trivially map to the given PTX and<br>
processor versions, leaving other cases as unsupported. (Even on the<br>
SSE and NEON backends, after all, select with a vector condition has<br>
barfed for years.) In the longer run, it could be quite useful for<br>
portability to map the full range of atomicrmw behaviors to all PTX<br>
targets using emulation when necessary, but relative to the current<br>
state of the art (manually writing different CUDA code paths with<br>
different sync strategies for different machine generations), only<br>
supporting what maps trivially is not a regression.<br>
<br>
Thoughts?<br>
</blockquote></div><br>For the short term, I definitely agree that implementing the trivial maps is most important.  I'm not too concerned about the corner cases at the moment.<div><br></div><div>As for emulating atomics when they are not available, this is probably just something we have to live with.  To be complete, we should support all intrinsics on all targets and leave it up to the front-end to determine how best to implement source-level functionality.  I'm not particularly troubled by steep performance curves for emulated atomics.  It's ultimately the job of the LLVM IR generator to decide how best to map to target intrinsics given a target.<br clear="all">
<div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>
</div>