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

Floating point support #58

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions rawspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "OBSNCHAN = %d\n", raw_hdr.obsnchan);
fprintf(stderr, "NANTS = %d\n", raw_hdr.nants);
fprintf(stderr, "NBITS = %d\n", raw_hdr.nbits);
fprintf(stderr, "DATATYPE = %s\n", raw_hdr.float_data ? "FLOAT" : "INTEGER");
fprintf(stderr, "NPOL = %d\n", raw_hdr.npol);
fprintf(stderr, "OBSFREQ = %g\n", raw_hdr.obsfreq);
fprintf(stderr, "OBSBW = %g\n", raw_hdr.obsbw);
Expand Down Expand Up @@ -749,6 +750,7 @@ int main(int argc, char *argv[])
ctx.Ntpb = Ntpb;
ctx.Nbps = Nbps;
ctx.input_conjugated = input_conjugated;
ctx.float_data = raw_hdr.float_data;

// Initialize for new dimensions and/or conjugation
ctx.Nb = 0; // auto-calculate
Expand Down
3 changes: 3 additions & 0 deletions rawspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ struct rawspec_context_s {
// the next call to rawspec_initialize().
int input_conjugated;

// Flag indicating that the input data is floating point data (not integer).
int float_data;

// Flag indicating the concurrent output of the output data's incoherent-sum.
int incoherently_sum;
int Naws;
Expand Down
13 changes: 10 additions & 3 deletions rawspec_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,16 @@ int rawspec_initialize(rawspec_context * ctx)
// NbpsIsExpanded = 1 (true) if Nbps==4 else 0 (false).
if(ctx->Nbps == 0)
ctx->Nbps = 8;
if(ctx->Nbps != 4 && ctx->Nbps != 8 && ctx->Nbps != 16) {
if(!ctx->float_data && ctx->Nbps != 4 && ctx->Nbps != 8 && ctx->Nbps != 16) {
fprintf(stderr, "Number of bits per sample in raw header must be 4, 0/8, or 16\n");
fprintf(stderr, "Observed a value of %d\n", ctx->Nbps);
fflush(stderr);
return 1;
} else if(ctx->float_data && ctx->Nbps != 16 && ctx->Nbps != 32) {
fprintf(stderr, "Number of bits per float sample in raw header must be 16 or 32\n");
fprintf(stderr, "Observed a value of %d\n", ctx->Nbps);
fflush(stderr);
return 1;
}
NbpsIsExpanded = ctx->Nbps == 4;
if(ctx->Nbps == 4)
Expand Down Expand Up @@ -831,13 +836,15 @@ int rawspec_initialize(rawspec_context * ctx)
}
fflush(stderr);

fprintf(stdout, "Detected %s data.\n", ctx->float_data ? "Float" : "Integer");

// Create texture object for device input buffer
// res_desc describes input resource
// Width is 32K elements, height is buf_size/32K elements, pitch is 32K elements
memset(&res_desc, 0, sizeof(res_desc));
res_desc.resType = cudaResourceTypePitch2D;
res_desc.res.pitch2D.devPtr = gpu_ctx->d_fft_in;
res_desc.res.pitch2D.desc.f = cudaChannelFormatKindSigned;
res_desc.res.pitch2D.desc.f = ctx->float_data ? cudaChannelFormatKindFloat : cudaChannelFormatKindSigned;
res_desc.res.pitch2D.desc.x = ctx->Nbps; // bits per sample
res_desc.res.pitch2D.width = 1<<LOAD_TEXTURE_WIDTH_POWER; // elements
res_desc.res.pitch2D.height = buf_size>>LOAD_TEXTURE_WIDTH_POWER; // elements
Expand All @@ -852,7 +859,7 @@ int rawspec_initialize(rawspec_context * ctx)
// Not sure whether filter_mode matters for cudaReadModeNormalizedFloat
tex_desc.filter_mode = cudaFilterModePoint;
#endif // 0
tex_desc.readMode = cudaReadModeNormalizedFloat;
tex_desc.readMode = ctx->float_data ? cudaReadModeElementType : cudaReadModeNormalizedFloat;

cuda_rc = cudaCreateTextureObject(&gpu_ctx->tex_obj,
&res_desc, &tex_desc, NULL);
Expand Down
3 changes: 3 additions & 0 deletions rawspec_rawutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ void rawspec_raw_parse_header(const char * buf, rawspec_raw_hdr_t * raw_hdr)
raw_hdr->nbeam = rawspec_raw_get_s32(buf, "NBEAM", -1);
raw_hdr->nants = rawspec_raw_get_u32(buf, "NANTS", 1);

rawspec_raw_get_str(buf, "DATATYPE", "INTEGER", tmp, 80);
raw_hdr->float_data = strncmp(tmp, "FLOAT", 5) == 0;

rawspec_raw_get_str(buf, "RA_STR", "0.0", tmp, 80);
raw_hdr->ra = rawspec_raw_hmsstr_to_h(tmp);

Expand Down
1 change: 1 addition & 0 deletions rawspec_rawutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct {
char telescop[81];
off_t hdr_pos; // Offset of start of header
size_t hdr_size; // Size of header in bytes (not including DIRECTIO padding)
int float_data; // flag float (not integer) data
} rawspec_raw_hdr_t;

// Multiple of 80 and 512
Expand Down