@hsa.jit(device=True)
def device_scan(tid, data, temp, inclusive):
 lane = (tid & (_WARPSIZE - 1))
 warpid = (tid >> 6)
 temp[tid] = data
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 warp_scan_res = warp_scan(tid, temp, inclusive)
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 if (lane == (_WARPSIZE - 1)):
  temp[warpid] = temp[tid]
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 if (warpid == 0):
  warp_scan(tid, temp, True)
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 if (warpid > 0):
  warp_scan_res += temp[(warpid - 1)]
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 if (tid == (temp.size - 1)):
  if inclusive:
   temp[0] = warp_scan_res
  else:
   temp[0] = (warp_scan_res + data)
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 prefixsum = temp[0]
 hsa.barrier(hsa.CLK_GLOBAL_MEM_FENCE)
 return (warp_scan_res, prefixsum)

@ hsa . jit ( device = True ) def device_scan ( tid , data , temp , inclusive ) : lane = ( tid & ( _WARPSIZE - 1 ) ) warpid = ( tid >> 6 ) temp [ tid ] = data hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) warp_scan_res = warp_scan ( tid , temp , inclusive ) hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) if ( lane == ( _WARPSIZE - 1 ) ) : temp [ warpid ] = temp [ tid ] hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) if ( warpid == 0 ) : warp_scan ( tid , temp , True ) hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) if ( warpid > 0 ) : warp_scan_res += temp [ ( warpid - 1 ) ] hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) if ( tid == ( temp . size - 1 ) ) : if inclusive : temp [ 0 ] = warp_scan_res else : temp [ 0 ] = ( warp_scan_res + data ) hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) prefixsum = temp [ 0 ] hsa . barrier ( hsa . CLK_GLOBAL_MEM_FENCE ) return ( warp_scan_res , prefixsum )
args tid: thread id data: scalar input for tid temp: shared memory for temporary work .