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
from enum import IntEnum
import pycuda.compiler as cuda_compiler
import pycuda.gpuarray
import pycuda.driver as cuda
#import pycuda.compiler as cuda_compiler
#import pycuda.gpuarray
#import pycuda.driver as cuda
from hip import hip, hiprtc
from GPUSimulators import Common
class BoundaryCondition(object):
"""
Class for holding boundary conditions for global boundaries
@ -101,13 +100,17 @@ class BoundaryCondition(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,
context,
nx, ny,
@ -161,8 +164,10 @@ class BaseSimulator(object):
)
#Create a CUDA stream
self.stream = cuda.Stream()
self.internal_stream = cuda.Stream()
#self.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
self.t = 0.0
@ -231,7 +236,9 @@ class BaseSimulator(object):
return self.getOutput().download(self.stream, variables)
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):
return self.t
@ -268,15 +275,6 @@ class BaseSimulator(object):
def stepOrderToCodedInt(step, order):
"""
Helper function which packs the step and order into a single integer