Giter Site home page Giter Site logo

Make CuPy optional dependency about torchsig HOT 5 CLOSED

gvanhoy avatar gvanhoy commented on August 27, 2024
Make CuPy optional dependency

from torchsig.

Comments (5)

MattCarrickPL avatar MattCarrickPL commented on August 27, 2024

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,
            )

from torchsig.

MattCarrickPL avatar MattCarrickPL commented on August 27, 2024

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"
    )

from torchsig.

MattCarrickPL avatar MattCarrickPL commented on August 27, 2024

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

from torchsig.

MattCarrickPL avatar MattCarrickPL commented on August 27, 2024

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

from torchsig.

MattCarrickPL avatar MattCarrickPL commented on August 27, 2024

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()

from torchsig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.