1

Got error for code below:

@vectorize(["float32(float32, float32, float32, float32)"], target='cuda')
def fuzz_comp(A_row, B_col, X, Y):
    for i in range(A_row):
        for j in range(B_col):
            pvc_sim.input['ipv'] = float(X[i,j])
            pvc_sim.compute()
            Y[i,j] = pvc_sim.output['opv']
    return Y

Error:

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'pvc_sim': cannot determine Numba type of <class 'skfuzzy.control.controlsystem.ControlSystemSimulation'>

File "<ipython-input-13-4fe6c3f24f69>", line 5:
def fuzz_comp(A_row, B_col, X, Y):
    <source elided>
        for j in range(B_col):
            pvc_sim.input['ipv'] = float(X[i,j])
            ^

Read through a number of articles, however, unable to fix the problem. The code is working in Python, however; error returned when decorator is used. I am trying to implement fuzzy computation in GPU.

2 Answers2

1

Thanks to @JoshAdel. I am able to develop following code using jitclass for input and output membership functions.

spec = [
    ('value', int64),               # a simple scalar field
    ('array', float64[:]),          # an array field
]

@jitclass(spec)
class io_mf(object):
    def __init__(self, value, array):
        self.value = value
        self.array = array

    @property
    def triangular(self):
        if (self.array[0] - self.array[1]) <= self.value and self.value < self.array[0]:
            return 1. - (self.array[0] - self.value) / self.array[1]
        if self.array[0] <= self.value and self.value <= (self.array[0] + self.array[2]):
            return 1. - (self.value - self.array[0]) / self.array[2]
        return 0.

    @property
    def trapezoidal(self):
        if (self.array[0] - self.array[2]) <= self.value and self.value < self.array[0]:
            return 1. - (self.array[0] - self.value) / self.array[2]
        if self.array[0] <= self.value and self.value < self.array[1]: 
            return 1.
        if self.array[1] <= self.value and self.value <= (self.array[1] + self.array[3]):
            return 1. - (self.value - self.array[1]) / self.array[3]
        return 0
0

What the error is telling you is that numba does not know how to type the global variable pvc_sim. It appears to be a python class, so numba cannot automatically convert it into low-level code. You can write a specialized jitclass, but otherwise, this code will fail. Additionally, it is not clear to me from the implementation that it would actually benefit from a cuda target. Remember that @vectorize functions are written to operate over scalars, and then numba handles array inputs correctly, applying the function to each element.

JoshAdel
  • 66,734
  • 27
  • 141
  • 140