Simulator.py with hip-python

This commit is contained in:
Hicham Agueny 2024-02-26 12:39:56 +01:00
parent 655913021c
commit ca9171a5bf

View File

@ -25,16 +25,15 @@ import numpy as np
import logging import logging
from enum import IntEnum from enum import IntEnum
import pycuda.compiler as cuda_compiler #import pycuda.compiler as cuda_compiler
import pycuda.gpuarray #import pycuda.gpuarray
import pycuda.driver as cuda #import pycuda.driver as cuda
from hip import hip, hiprtc
from GPUSimulators import Common from GPUSimulators import Common
class BoundaryCondition(object): class BoundaryCondition(object):
""" """
Class for holding boundary conditions for global boundaries Class for holding boundary conditions for global boundaries
@ -101,13 +100,17 @@ class BoundaryCondition(object):
class BaseSimulator(object): class BaseSimulator(object):
def hip_check(call_result):
err = call_result[0]
result = call_result[1:]
if len(result) == 1:
result = result[0]
if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess:
raise RuntimeError(str(err))
return result
def __init__(self, def __init__(self,
context, context,
nx, ny, nx, ny,
@ -161,9 +164,11 @@ class BaseSimulator(object):
) )
#Create a CUDA stream #Create a CUDA stream
self.stream = cuda.Stream() #self.stream = cuda.Stream()
self.internal_stream = cuda.Stream() #self.internal_stream = cuda.Stream()
self.stream = hip_check(hip.hipStreamCreate())
self.internal_stream = hip_check(hip.hipStreamCreate())
#Keep track of simulation time and number of timesteps #Keep track of simulation time and number of timesteps
self.t = 0.0 self.t = 0.0
self.nt = 0 self.nt = 0
@ -231,7 +236,9 @@ class BaseSimulator(object):
return self.getOutput().download(self.stream, variables) return self.getOutput().download(self.stream, variables)
def synchronize(self): def synchronize(self):
self.stream.synchronize() #self.stream.synchronize()
#Synchronize the stream to ensure operations in the stream is complete
hip_check(hip.hipStreamSynchronize(self.stream))
def simTime(self): def simTime(self):
return self.t return self.t
@ -268,15 +275,6 @@ class BaseSimulator(object):
def stepOrderToCodedInt(step, order): def stepOrderToCodedInt(step, order):
""" """
Helper function which packs the step and order into a single integer Helper function which packs the step and order into a single integer
@ -285,4 +283,4 @@ def stepOrderToCodedInt(step, order):
#print("Step: {0:032b}".format(step)) #print("Step: {0:032b}".format(step))
#print("Order: {0:032b}".format(order)) #print("Order: {0:032b}".format(order))
#print("Mix: {0:032b}".format(step_order)) #print("Mix: {0:032b}".format(step_order))
return np.int32(step_order) return np.int32(step_order)