Let's just assume that I have implemented two different versions of the same class with Numba:
class cpu_foo(object):
def init(self, data):
# initialize the class...
def compute(self, parameters):
call_to_parallel_cpu_function(parameters)
class gpu_foo(object):
def init(self, data):
# initialize the class...
# ...with some fine tunings for the gpu computation
def compute(self, parameters):
call_to_parallel_cuda_function(parameters)
And then, depending on the machine I'm working on, I call either one version or another.
I know that it's an horrible practice to have 2 separate versions of the same code, but I'm unsure on what would be the most "standard" way to implement a class capable of:
- detect if there is a CUDA capable device
- if yes, initialize as a gpu class
- if not, initialize as a cpu class
In general, I was unable to find any design indication for any language about this topic... am I missing something?
Aucun commentaire:
Enregistrer un commentaire