Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No implementation of function Function(<built-in function mul>) found for signature: >>> mul(array(float32, 1d, C), array(float32, 1d, C)) #9107

Closed
vrunm opened this issue Jul 28, 2023 · 2 comments
Labels
no action required No action was needed to resolve. question Notes an issue as a question

Comments

@vrunm
Copy link

vrunm commented Jul 28, 2023

I am trying to optimize my face recognition code, so that it executes on GPU. There is a cosine_similarity function in scikit-learn, which was throwing error with numba, so then I created a separate function.

@cuda.jit
def cosine_similarity_numba(u:np.ndarray, v:np.ndarray):
    assert(u.shape[0] == v.shape[0])
    print(u.shape[0])
    print(v.shape[0])
    l = 0
    m = 0
    n = 0
    for i in range(u.shape[0]):
        print(u[i])
        print(v[i])
        l += u[i]*v[i]
        m += u[i]*u[i]
        n += v[i]*v[i]
    cos_theta = 1
    if m!=0 and n!=0:
        cos_theta = l/np.sqrt(m*n)
    return cos_theta

but numba is still throwing error.
The error is:-

Failed in cuda mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function mul>) found for signature:
 
 >>> mul(array(float32, 1d, C), array(float32, 1d, C))
 
There are 12 candidate implementations:
      - Of which 10 did not match due to:
      Overload of function 'mul': File: <numerous>: Line N/A.
        With argument(s): '(array(float32, 1d, C), array(float32, 1d, C))':
       No match.
      - Of which 2 did not match due to:
      Operator Overload in function 'mul': File: unknown: Line unknown.
        With argument(s): '(array(float32, 1d, C), array(float32, 1d, C))':
       No match for registered cases:
        * (int64, int64) -> int64
        * (int64, uint64) -> int64
        * (uint64, int64) -> int64
        * (uint64, uint64) -> uint64
        * (float32, float32) -> float32
        * (float64, float64) -> float64
        * (complex64, complex64) -> complex64
        * (complex128, complex128) -> complex128

During: typing of intrinsic-call at /home/proeffico/Desktop/ProlificCUDA/face_rec.py (92)

File "face_rec.py", line 92:
def cosine_similarity_numba(u:np.ndarray, v:np.ndarray):
    <source elided>
        print(v[i])
        l += u[i]*v[i]
        ^

During: resolving callee type: type(CUDADispatcher(<function cosine_similarity_numba at 0x7f622ce37700>))
During: typing of call at /home/proeffico/Desktop/ProlificCUDA/face_rec.py (59)


File "face_rec.py", line 59:
def ml_search_algorithm(names,feature_column,test_vector,thresh=0.5):
    <source elided>
    # step-3: Cal. cosine similarity
    similar = cosine_similarity_numba(x,test_vector.reshape(1,-1))
    ^
`

Is there any way around this?

@gmarkall
Copy link
Member

Array operations need to be rewritten such that they are performed elementwise for the CUDA target, with elements assigned to threads according to your judgment. For your case you probably want to use the thread index to index into the arrays, as in the Vector Addition example.

@guilhermeleobas guilhermeleobas added question Notes an issue as a question no action required No action was needed to resolve. labels Jul 28, 2023
@sklam sklam changed the title No implementation of function Function(<built-in function mul>) found for signature: >>> mul(array(float32, 1d, C), array(float32, 1d, C)) No implementation of function Function(<built-in function mul>) found for signature: >>> mul(array(float32, 1d, C), array(float32, 1d, C)) Aug 1, 2023
@guilhermeleobas
Copy link
Collaborator

Closing this issue as it seems to be resolved. If this is not the case please re-open with a comment about any item that appears to be unresolved. Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no action required No action was needed to resolve. question Notes an issue as a question
Projects
None yet
Development

No branches or pull requests

3 participants