Skip to content

Commit

Permalink
llvm/execution: Make parameter and state writeback private
Browse files Browse the repository at this point in the history
Writeback in test execution is no longer necessary.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
  • Loading branch information
jvesely committed May 23, 2024
1 parent d3302f9 commit ad3b5cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 55 deletions.
37 changes: 5 additions & 32 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,10 @@ def cuda_param(val):
@pytest.helpers.register
def get_func_execution(func, func_mode):
if func_mode == 'LLVM':
ex = pnlvm.execution.FuncExecution(func)

# Calling writeback here will replace parameter values
# with numpy instances that share memory with the binary
# structure used by the compiled function
ex.writeback_state_to_pnl()

return ex.execute
return pnlvm.execution.FuncExecution(func).execute

elif func_mode == 'PTX':
ex = pnlvm.execution.FuncExecution(func)

# Calling writeback here will replace parameter values
# with numpy instances that share memory with the binary
# structure used by the compiled function
ex.writeback_state_to_pnl()

return ex.cuda_execute
return pnlvm.execution.FuncExecution(func).cuda_execute

elif func_mode == 'Python':
return func.function
Expand All @@ -232,29 +218,16 @@ def get_func_execution(func, func_mode):
@pytest.helpers.register
def get_mech_execution(mech, mech_mode):
if mech_mode == 'LLVM':
ex = pnlvm.execution.MechExecution(mech)

# Calling writeback here will replace parameter values
# with numpy instances that share memory with the binary
# structure used by the compiled function
ex.writeback_state_to_pnl()

return ex.execute
return pnlvm.execution.MechExecution(mech).execute

elif mech_mode == 'PTX':
ex = pnlvm.execution.MechExecution(mech)

# Calling writeback here will replace parameter values
# with numpy instances that share memory with the binary
# structure used by the compiled function
ex.writeback_state_to_pnl()

return ex.cuda_execute
return pnlvm.execution.MechExecution(mech).cuda_execute

elif mech_mode == 'Python':
def mech_wrapper(x):
mech.execute(x)
return mech.output_values

return mech_wrapper
else:
assert False, "Unknown mechanism mode: {}".format(mech_mode)
Expand Down
33 changes: 10 additions & 23 deletions psyneulink/core/llvm/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,21 @@ def _get_compilation_param(self, name, init_method, arg):
_pretty_size(ctypes.sizeof(struct_ty)), ")",
"for", self._obj.name)


if len(self._execution_contexts) == 1:
if name == '_state':
self.writeback_state_to_pnl()
self._copy_params_to_pnl(self._execution_contexts[0],
self._obj,
self._state_struct,
"llvm_state_ids")

elif name == '_param':
self.writeback_params_to_pnl()
self._copy_params_to_pnl(self._execution_contexts[0],
self._obj,
self._param_struct,
"llvm_param_ids")

return struct

def writeback_state_to_pnl(self):

self._copy_params_to_pnl(self._execution_contexts[0],
self._obj,
self._state_struct,
"llvm_state_ids")

def writeback_params_to_pnl(self):

self._copy_params_to_pnl(self._execution_contexts[0],
self._obj,
self._param_struct,
"llvm_param_ids")

def _copy_params_to_pnl(self, context, component, params, ids:str):

for idx, attribute in enumerate(getattr(component, ids)):
Expand Down Expand Up @@ -222,12 +214,7 @@ def _enumerate_recurse(elements):
except ValueError:
pass

pnl_param.set(
value,
context=context,
override=True,
compilation_sync=True,
)
pnl_param.set(value, context=context, override=True, compilation_sync=True)


class CUDAExecution(Execution):
Expand Down

0 comments on commit ad3b5cd

Please sign in to comment.