Skip to content

Instantly share code, notes, and snippets.

@VibhuJawa
Last active May 6, 2021 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VibhuJawa/76a626fdcb4f9b14876d457dcd921415 to your computer and use it in GitHub Desktop.
Save VibhuJawa/76a626fdcb4f9b14876d457dcd921415 to your computer and use it in GitHub Desktop.
# UDF-2:
#if session change flag
#. set session id to x
#. set all other clicks to x until next session_change_flag
#else
#. do nothing
@cuda.jit
def populate_session_ids_kernel(session_boundary):
gid = cuda.grid(1)
# don't loop if we're off the edge
if gid < len(session_boundary):
# if this is a session boundary...
if session_boundary[gid] == 1:
# this thread marks the start of a session
session_boundary[gid] = gid
look_ahead = 1
# check elements 'forward' of this one
# until a new session boundary is found
while session_boundary[gid + look_ahead] == 0:
session_boundary[gid + look_ahead] = gid
look_ahead += 1
# don't segfault if I'm the last thread
if gid + look_ahead == len(session_boundary) - 1:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment