Commit 3cc83187 authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Allow switch between 8/32 bit from cmdline

parent 75dfadc4
......@@ -30,12 +30,12 @@ namespace edd {
bit set in side channel data.
*/
template <class HandlerType> class GatedSpectrometer {
template <class HandlerType, typename IntegratedPowerType> class GatedSpectrometer {
public:
typedef uint64_t RawVoltageType;
typedef float UnpackedVoltageType;
typedef float2 ChannelisedVoltageType;
typedef float IntegratedPowerType;
// typedef float IntegratedPowerType;
//typedef int8_t IntegratedPowerType;
public:
......
......@@ -103,8 +103,8 @@ __global__ void array_sum(float *in, size_t N, float *out) {
}
template <class HandlerType>
GatedSpectrometer<HandlerType>::GatedSpectrometer(
template <class HandlerType, typename IntegratedPowerType>
GatedSpectrometer<HandlerType, IntegratedPowerType>::GatedSpectrometer(
std::size_t buffer_bytes, std::size_t nSideChannels,
std::size_t selectedSideChannel, std::size_t selectedBit,
std::size_t speadHeapSize, std::size_t fft_length, std::size_t naccumulate,
......@@ -196,8 +196,8 @@ GatedSpectrometer<HandlerType>::GatedSpectrometer(
} // constructor
template <class HandlerType>
GatedSpectrometer<HandlerType>::~GatedSpectrometer() {
template <class HandlerType, typename IntegratedPowerType>
GatedSpectrometer<HandlerType, IntegratedPowerType>::~GatedSpectrometer() {
BOOST_LOG_TRIVIAL(debug) << "Destroying GatedSpectrometer";
if (!_fft_plan)
cufftDestroy(_fft_plan);
......@@ -207,15 +207,15 @@ GatedSpectrometer<HandlerType>::~GatedSpectrometer() {
}
template <class HandlerType>
void GatedSpectrometer<HandlerType>::init(RawBytes &block) {
template <class HandlerType, typename IntegratedPowerType>
void GatedSpectrometer<HandlerType, IntegratedPowerType>::init(RawBytes &block) {
BOOST_LOG_TRIVIAL(debug) << "GatedSpectrometer init called";
_handler.init(block);
}
template <class HandlerType>
void GatedSpectrometer<HandlerType>::process(
template <class HandlerType, typename IntegratedPowerType>
void GatedSpectrometer<HandlerType, IntegratedPowerType>::process(
thrust::device_vector<RawVoltageType> const &digitiser_raw,
thrust::device_vector<int64_t> const &sideChannelData,
thrust::device_vector<IntegratedPowerType> &detected_G0,
......@@ -270,8 +270,8 @@ void GatedSpectrometer<HandlerType>::process(
} // process
template <class HandlerType>
bool GatedSpectrometer<HandlerType>::operator()(RawBytes &block) {
template <class HandlerType, typename IntegratedPowerType>
bool GatedSpectrometer<HandlerType, IntegratedPowerType>::operator()(RawBytes &block) {
++_call_count;
BOOST_LOG_TRIVIAL(debug) << "GatedSpectrometer operator() called (count = "
<< _call_count << ")";
......
......@@ -25,13 +25,56 @@ const size_t ERROR_UNHANDLED_EXCEPTION = 2;
} // namespace
template<typename T>
void launchSpectrometer(std::string const &output_type, key_t input_key, std::string const &filename, size_t nSideChannels, size_t selectedSideChannel, size_t selectedBit, size_t speadHeapSize, size_t fft_length, size_t naccumulate, unsigned int nbits, float input_level, float output_level)
{
MultiLog log("edd::GatedSpectrometer");
DadaClientBase client(input_key, log);
//client.cuda_register_memory();
std::size_t buffer_bytes = client.data_buffer_size();
std::cout << "Running with output_type: " << output_type << std::endl;
if (output_type == "file")
{
SimpleFileWriter sink(filename);
effelsberg::edd::GatedSpectrometer<decltype(sink), T> spectrometer(
buffer_bytes, nSideChannels, selectedSideChannel, selectedBit,
speadHeapSize, fft_length, naccumulate, nbits, input_level,
output_level, sink);
DadaInputStream<decltype(spectrometer)> istream(input_key, log,
spectrometer);
istream.start();
}
else if (output_type == "dada")
{
DadaOutputStream sink(string_to_key(filename), log);
effelsberg::edd::GatedSpectrometer<decltype(sink), T> spectrometer(
buffer_bytes, nSideChannels, selectedSideChannel, selectedBit,
speadHeapSize, fft_length, naccumulate, nbits, input_level,
output_level, sink);
DadaInputStream<decltype(spectrometer)> istream(input_key, log,
spectrometer);
istream.start();
}
else
{
throw std::runtime_error("Unknown oputput-type");
}
}
int main(int argc, char **argv) {
try {
key_t input_key;
int fft_length;
int naccumulate;
int nbits;
unsigned int nbits;
size_t nSideChannels;
size_t selectedSideChannel;
size_t selectedBit;
......@@ -44,7 +87,7 @@ int main(int argc, char **argv) {
std::strftime(buffer, 32, "%Y-%m-%d-%H:%M:%S.bp", ptm);
std::string filename(buffer);
std::string output_type = "file";
unsigned int output_bit_depth;
/** Define and parse the program options
*/
namespace po = boost::program_options;
......@@ -61,6 +104,10 @@ int main(int argc, char **argv) {
"output_type", po::value<std::string>(&output_type)->default_value(output_type),
"output type [dada, file]. Default is file."
);
desc.add_options()(
"output_bit_depth", po::value<unsigned int>(&output_bit_depth)->default_value(8),
"output_bit_depth [8, 32]. Default is 32."
);
desc.add_options()(
"output_key,o", po::value<std::string>(&filename)->default_value(filename),
"The key of the output bnuffer / name of the output file to write spectra "
......@@ -85,7 +132,7 @@ int main(int argc, char **argv) {
"size of the spead data heaps. The number of the "
"heaps in the dada block depends on the number of "
"side channel items.");
desc.add_options()("nbits,b", po::value<int>(&nbits)->required(),
desc.add_options()("nbits,b", po::value<unsigned int>(&nbits)->required(),
"The number of bits per sample in the "
"packetiser output (8 or 12)");
......@@ -145,39 +192,24 @@ int main(int argc, char **argv) {
/**
* All the application code goes here
*/
MultiLog log("edd::GatedSpectrometer");
DadaClientBase client(input_key, log);
//client.cuda_register_memory();
std::size_t buffer_bytes = client.data_buffer_size();
if (output_bit_depth == 8)
{
launchSpectrometer<int8_t>(output_type, input_key, filename, nSideChannels, selectedSideChannel, selectedBit, speadHeapSize,
fft_length, naccumulate,
nbits, input_level, output_level);
}
else if (output_bit_depth == 32)
{
launchSpectrometer<float>(output_type, input_key, filename, nSideChannels, selectedSideChannel, selectedBit, speadHeapSize,
fft_length, naccumulate,
nbits, input_level, output_level);
}
else
{
throw po::validation_error(po::validation_error::invalid_option_value, "Output bit depth must be 8 or 32");
}
std::cout << "Running with output_type: " << output_type << std::endl;
if (output_type == "file")
{
SimpleFileWriter sink(filename);
effelsberg::edd::GatedSpectrometer<decltype(sink)> spectrometer(
buffer_bytes, nSideChannels, selectedSideChannel, selectedBit,
speadHeapSize, fft_length, naccumulate, nbits, input_level,
output_level, sink);
DadaInputStream<decltype(spectrometer)> istream(input_key, log,
spectrometer);
istream.start();
}
else if (output_type == "dada")
{
DadaOutputStream sink(string_to_key(filename), log);
effelsberg::edd::GatedSpectrometer<decltype(sink)> spectrometer(
buffer_bytes, nSideChannels, selectedSideChannel, selectedBit,
speadHeapSize, fft_length, naccumulate, nbits, input_level,
output_level, sink);
DadaInputStream<decltype(spectrometer)> istream(input_key, log,
spectrometer);
istream.start();
}
else
{
throw std::runtime_error("Unknown oputput-type");
}
/**
......
......@@ -23,34 +23,30 @@ TEST(GatedSpectrometer, BitManipulationMacros) {
}
}
TEST(GatedSpectrometer, ParameterSanity) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
psrdada_cpp::NullSink sink;
// 8 or 12 bit sampling
EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink)>(
0, 0, 0, 0, 4096, 0, 0, 0, 0, 0, sink),
"_nbits == 8");
// naccumulate > 0
EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink)>(
0, 0, 0, 0, 4096, 0, 0, 8, 0, 0, sink),
"_naccumulate");
// selected side channel
EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink)>(
0, 1, 2, 0, 4096, 0, 1, 8, 0, 0, sink),
"nSideChannels");
// selected bit
EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink)>(
0, 2, 1, 65, 4096, 0, 1, 8, 0, 0, sink),
"selectedBit");
// valid construction
psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink)> a(
4096 * 4096, 2, 1, 63, 4096, 1024, 1, 8, 100., 100., sink);
}
//
//TEST(GatedSpectrometer, ParameterSanity) {
// ::testing::FLAGS_gtest_death_test_style = "threadsafe";
// psrdada_cpp::NullSink sink;
//
// // 8 or 12 bit sampling
// EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink),int8_t > (0, 0, 0, 0, 4096, 0, 0, 0, 0, 0, sink),
// "_nbits == 8");
// // naccumulate > 0
// EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink),int8_t > (0, 0, 0, 0, 4096, 0, 0, 8, 0, 0, sink),
// "_naccumulate");
//
// // selected side channel
// EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink),int8_t > (0, 1, 2, 0, 4096, 0, 1, 8, 0, 0, sink),
// "nSideChannels");
//
// // selected bit
// EXPECT_DEATH(psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink),int8_t > (0, 2, 1, 65, 4096, 0, 1, 8, 0, 0, sink),
// "selectedBit");
//
// // valid construction
// psrdada_cpp::effelsberg::edd::GatedSpectrometer<decltype(sink), int8_t> a(
// 4096 * 4096, 2, 1, 63, 4096, 1024, 1, 8, 100., 100., sink);
//}
} // namespace
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment