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

Make CuPy optional dependency #39

Closed
gvanhoy opened this issue Mar 22, 2023 · 5 comments · Fixed by #86
Closed

Make CuPy optional dependency #39

gvanhoy opened this issue Mar 22, 2023 · 5 comments · Fixed by #86
Assignees
Labels
enhancement New feature or request

Comments

@gvanhoy
Copy link
Collaborator

gvanhoy commented Mar 22, 2023

No description provided.

@MattCarrickPL
Copy link
Collaborator

Remove cusignal.firwin() in synthetic.py, https://github.com/TorchDSP/torchsig/blob/main/torchsig/datasets/synthetic.py#L1017

        if self.use_gpu:
            taps = cusignal.firwin(
                num_taps,
                cutoff_frequency,
                width=transition_bandwidth,
                window=sp.get_window("blackman", num_taps),
                scale=True,
                fs=sample_rate,
            )

@MattCarrickPL
Copy link
Collaborator

Replace cupy convolve: https://github.com/TorchDSP/torchsig/blob/main/torchsig/datasets/synthetic.py#L391

    filtered = xp.convolve(
        xp.array(zero_padded), xp.array(self.pulse_shape_filter), "same"
    )

@MattCarrickPL
Copy link
Collaborator

Cupy in OFDM modulator: https://github.com/TorchDSP/torchsig/blob/main/torchsig/datasets/synthetic.py

Line 390:

    xp = cp if self.use_gpu else np
    ofdm_symbols = xp.fft.ifft(xp.fft.ifftshift(zero_pad, axes=0), axis=0)
    symbol_dur = ofdm_symbols.shape[0]
    cyclic_prefixed = xp.pad(
        ofdm_symbols, ((int(cyclic_prefix_len), 0), (0, 0)), "wrap"
    )

Line 751:
output = xp.convolve(xp.array(flattened), xp.array(self.taps), mode="same")[

Line 770:
output = xp.convolve(xp.array(flattened), xp.array(taps), mode="same")[

Line 779:

            windowed = xp.pad(
                cyclic_prefixed,
                ((half_window_len, half_window_len), (0, 0)),
                "constant",
                constant_values=0,
            )

Line 802:
windowed = xp.pad(
cyclic_prefixed,
((0, int(window_len)), (0, 0)),
"constant",
constant_values=0,
)

Line 819:
front_window = xp.blackman(int(window_len * 2))[: int(window_len)].reshape(

Line 822:
tail_window = xp.blackman(int(window_len * 2))[-int(window_len) :].reshape(

Line 832:
combined = xp.zeros((windowed.shape[0] * windowed.shape[1],), dtype=complex)

Line 843:
output = xp.asnumpy(output) if self.use_gpu else output

@MattCarrickPL
Copy link
Collaborator

Cupy in FSK modulator in synthetic.py:

Line 976:
xp = cp if self.use_gpu else np

Line 979:
symbols_repeat = xp.repeat(symbols, samples_per_symbol_recalculated)

Line 985:
filtered = xp.convolve(xp.array(symbols_repeat), xp.array(taps), "same")

Line 994:
phase = xp.cumsum(xp.array(filtered) * 1j * mod_idx * np.pi)
modulated = xp.exp(phase)

Line 1035:
modulated = xp.convolve(xp.array(modulated), xp.array(taps), mode="same")

Line 1037:
modulated = xp.asnumpy(modulated) if self.use_gpu else modulated

Line 1044:
def _gaussian_taps(self, samples_per_symbol, BT: float = 0.35) -> np.ndarray:
xp = cp if self.use_gpu else np
# pre-modulation Bb*T product which sets the bandwidth of the Gaussian lowpass filter
M = 4 # duration in symbols
n = xp.arange(-M * samples_per_symbol, M * samples_per_symbol + 1)
p = xp.exp(
-2 * np.pi2 * BT2 / np.log(2) * (n / float(samples_per_symbol)) ** 2
)
p = p / xp.sum(p)
return p

@MattCarrickPL
Copy link
Collaborator

Following is a summary of the cupy and cusignal calls. However, all functions may not need to be done on GPU. Most likely candidates for GPU acceleration are:

  • cupy.convolve()
  • cupy.fft.ifft()

The following may be able to be run on CPU, unclear if GPU acceleration needed:

  • cupy.cumsum()
  • cusignal.firwin()
  • cupy.asarray()
  • cupy.fft.ifftshift()
  • cupy.pad()
  • cupy.blackman()
  • cupy.zeros()
  • cupy.repeat()
  • cupy.arange()
  • cupy.exp()
  • cupy.sum()

@gvanhoy gvanhoy linked a pull request May 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants