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

Provide utility to downsample in time/frequency before output #23

Open
bwmeyers opened this issue Dec 13, 2022 · 1 comment
Open

Provide utility to downsample in time/frequency before output #23

bwmeyers opened this issue Dec 13, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@bwmeyers
Copy link
Contributor

Being able to specify the desired output time and/or frequency resolution could be really helpful in terms of managing data rates, since not all VCS science needs 100us/10kHz.

@bwmeyers bwmeyers added the enhancement New feature or request label Dec 13, 2022
@bwmeyers bwmeyers self-assigned this Oct 10, 2023
@bwmeyers
Copy link
Contributor Author

bwmeyers commented Nov 3, 2023

At least in the case where we just want to downsample a 2D array along 1 axis, something like this should work as a kernel, I think.

#include <stdio.h>

__global__ void downsample2D_mean(float *input, float *output, int inputWidth, int outputWidth, int factor) {
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    int j = blockIdx.y * blockDim.y + threadIdx.y;

    if (i < outputWidth && j < inputWidth) {
        int start_idx = j * factor;
        double  sum = 0.0d;
        for (int k = 0; k < factor; k++) {
            sum += (double)input[start_idx + k];
        }
        output[i * inputWidth + j] = (float)(sum / (double)factor);
    }
}

and to launch it would look something like

// inputHeight = nchan
// inputWidth = nsamps
// outputWidth = inputWidth/dsfact

dim3 threadsPerBlock(16, 16);
dim3 numBlocks(
    (outputWidth + threadsPerBlock.x - 1) / threadsPerBlock.x,
    (inputHeight + threadsPerBlock.y - 1) / threadsPerBlock.y
);

// Launch the kernel
downsample2D_mean<<<numBlocks, threadsPerBlock>>>(d_input, d_output, inputWidth, outputWidth, dsfact);

Sensible factors (given our "inputWidth" will likely be 10000 samples = 1 second) are:
1, 2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 625, 1000, 1250, 2000, 2500, 5000, and 10000

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
None yet
Development

No branches or pull requests

2 participants