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

Exercise 2 #2

Open
Duxon opened this issue Jun 26, 2019 · 2 comments
Open

Exercise 2 #2

Duxon opened this issue Jun 26, 2019 · 2 comments

Comments

@Duxon
Copy link

Duxon commented Jun 26, 2019

Hi,

I am struggling with exercise 2. My implementation looks like this:

def zero_suppress(waveform_value, threshold):
    for i in range(n)
        if waveform_value[i] < threshold: waveform_value[i] = 0
    return waveform_value

Somehow, that is not possible in CUDA and I don't understand why (if and for statements should be supported). Can someone elaborate?

@Duxon
Copy link
Author

Duxon commented Jun 26, 2019

Okay, it seems like I was missing a fundamental concept in vectorization.
If I understand correctly, the function is executed n-times on a GPU device even though we call it with an array of dimension n. A correct implementation would, therefore, look like this:

if abs(waveform_value) > threshold:
    return waveform_value
else:
    return 0.0

@seibert
Copy link
Collaborator

seibert commented Jun 26, 2019

Correct. The @vectorize decorator handles the looping, which also means it generalizes to multidimensional arrays (not just 1D) as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants