Skip to content
Snippets Groups Projects
Commit d58227b9 authored by Steven van der Vlugt's avatar Steven van der Vlugt
Browse files

CorrelatorTest

parent fda62780
Branches
No related tags found
1 merge request!1Clean up
......@@ -25,10 +25,13 @@ class UnitTest
template <typename T> void check(T actual, T expected)
{
if (expected != actual) {
if (expected != actual)
{
std::cerr << "Test FAILED: expected " << expected << ", computed " << actual << std::endl;
exit(1);
} else {
}
else
{
std::cout << "Test OK" << std::endl;
}
}
......
......@@ -8,96 +8,16 @@
#include <iostream>
#if defined USE_PHI_CORRELATOR
#if 0
struct CorrelatorTest : public UnitTest
{
CorrelatorTest(const CorrelatorParset &ps)
:
UnitTest(ps, "Correlator/Kernels/PhiCorrelator.cl")
{
if (ps.nrStations() >= 5 && ps.nrChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100) {
MultiArraySharedBuffer<float, 5> visibilities(boost::extents[ps.nrBaselines()][ps.nrPolarizations()][ps.nrPolarizations()][COMPLEX][ps.nrChannelsPerSubband()], queue, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY);
MultiArraySharedBuffer<float, 5> inputData(boost::extents[ps.nrStations()][ps.nrSamplesPerChannel()][ps.nrPolarizations()][COMPLEX][ps.nrChannelsPerSubband()], queue, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY);
CorrelatorKernel correlator(ps, queue, program, visibilities, inputData);
inputData[3][99][POL_Y][REAL][5] = 3; // stat=3,pol=Y,real,time=99,chan=5
inputData[3][99][POL_Y][IMAG][5] = 4; // stat=3,pol=Y,imag,time=99,chan=5
inputData[4][99][POL_Y][REAL][5] = 5; // stat=4,pol=Y,real,time=99,chan=5
inputData[4][99][POL_Y][IMAG][5] = 6; // stat=4,pol=Y,imag,time=99,chan=5
inputData.hostToDevice(CL_FALSE);
correlator.enqueue(queue, counter);
visibilities.deviceToHost(CL_TRUE);
#if 0
check(visibilities[ 9][POL_Y][POL_Y][REAL][5], 25.f);
check(visibilities[ 9][POL_Y][POL_Y][IMAG][5], 0.f);
check(visibilities[13][POL_Y][POL_Y][REAL][5], 39.f);
check(visibilities[13][POL_Y][POL_Y][IMAG][5], 2.f);
check(visibilities[14][POL_Y][POL_Y][REAL][5], 61.f);
check(visibilities[14][POL_Y][POL_Y][IMAG][5], 0.f);
#endif
}
}
};
#else
struct CorrelateRectangleTest : public UnitTest
{
CorrelateRectangleTest(const CorrelatorParset &ps)
:
UnitTest(ps, "Correlator/Kernels/PhiCorrelator.cl")
{
if (ps.nrStations() >= 69 && ps.nrChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() == 1) {
Buffer<float, 4> inputData(boost::extents[ps.nrChannelsPerSubband()][ps.nrSamplesPerChannel()][COMPLEX][align(ps.nrStations() * ps.nrPolarizations(), 16)], context, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY);
Buffer<float, 3> visibilities(boost::extents[ps.nrChannelsPerSubband()][COMPLEX][ps.nrBaselines()], context, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY);
CorrelateRectangleKernel correlator(ps, queue, program, visibilities, inputData);
{
MappedBuffer<float, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true);
mappedInputData[5][99][REAL][0] = 3;
mappedInputData[5][99][IMAG][0] = 4;
mappedInputData[5][99][REAL][15] = 5;
mappedInputData[5][99][IMAG][15] = 6;
}
correlator.enqueue(queue, counter);
{
MappedBuffer<float, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ);
//unsigned outputChannel = 5;
//check(visibilities[outputChannel][2373][outputPolarization], std::complex<float>(39, 2));
#if 1
for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++)
for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++)
if (mappedVisibilities[ch][REAL][bl] != 0 || mappedVisibilities[ch][IMAG][bl] != 0)
std::cout << "vis[" << ch << "][" << bl << "] = (" << mappedVisibilities[ch][REAL][bl] << ',' << mappedVisibilities[ch][IMAG][bl] << ')' << std::endl;
#endif
}
}
}
};
#endif
#elif defined USE_NEW_CORRELATOR
struct CorrelateSquareTest : public CorrelatorUnitTest
{
CorrelateSquareTest(const CorrelatorParset &ps)
:
CorrelatorUnitTest(ps, "Correlator/Kernels/NewCorrelator.cl")
{
if (ps.nrStations() >= 64 && ps.nrOutputChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() >= 2) {
std::cout << ">>> Running CorrelateSquareTest" << std::endl;
if (ps.nrStations() >= 64 && ps.nrOutputChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() >= 2)
{
Buffer<std::complex<float>, 4> inputData(boost::extents[ps.nrChannelsPerSubband()][ps.nrSamplesPerChannel()][ps.nrStations()][ps.nrPolarizations()], context, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY);
Buffer<std::complex<float>, 3> visibilities(boost::extents[ps.nrBaselines()][ps.nrOutputChannelsPerSubband()][ps.nrVisibilityPolarizations()], context, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY);
CorrelateSquareKernel correlator(ps, queue, program, visibilities, inputData);
......@@ -130,14 +50,16 @@ struct CorrelateSquareTest : public CorrelatorUnitTest
}
};
struct CorrelateRectangleTest : public CorrelatorUnitTest
{
CorrelateRectangleTest(const CorrelatorParset &ps)
:
CorrelatorUnitTest(ps, "Correlator/Kernels/NewCorrelator.cl")
{
if (ps.nrStations() >= 69 && ps.nrOutputChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() >= 2) {
std::cout << ">>> Running CorrelateRectangleTest" << std::endl;
if (ps.nrStations() >= 69 && ps.nrOutputChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() >= 2)
{
Buffer<std::complex<float>, 4> inputData(boost::extents[ps.nrChannelsPerSubband()][ps.nrSamplesPerChannel()][ps.nrStations()][ps.nrPolarizations()], context, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY);
Buffer<std::complex<float>, 3> visibilities(boost::extents[ps.nrBaselines()][ps.nrOutputChannelsPerSubband()][ps.nrVisibilityPolarizations()], context, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY);
CorrelateRectangleKernel correlator(ps, queue, program, visibilities, inputData);
......@@ -170,14 +92,16 @@ struct CorrelateRectangleTest : public CorrelatorUnitTest
}
};
struct CorrelateTriangleTest : public CorrelatorUnitTest
{
CorrelateTriangleTest(const CorrelatorParset &ps)
:
CorrelatorUnitTest(ps, "Correlator/Kernels/NewCorrelator.cl")
{
if (ps.nrStations() >= 5 && ps.nrOutputChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() >= 2) {
std::cout << ">>> Running CorrelateTriangleTest" << std::endl;
if (ps.nrStations() >= 5 && ps.nrOutputChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100 && ps.nrVisibilityPolarizations() >= 2)
{
Buffer<std::complex<float>, 4> inputData(boost::extents[ps.nrChannelsPerSubband()][ps.nrSamplesPerChannel()][ps.nrStations()][ps.nrPolarizations()], context, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY);
Buffer<std::complex<float>, 3> visibilities(boost::extents[ps.nrBaselines()][ps.nrOutputChannelsPerSubband()][ps.nrVisibilityPolarizations()], context, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY);
CorrelateTriangleKernel correlator(ps, queue, program, visibilities, inputData);
......@@ -196,12 +120,15 @@ struct CorrelateTriangleTest : public CorrelatorUnitTest
#if 1
unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor();
switch (ps.nrVisibilityPolarizations()) {
case 2 : check(mappedVisibilities[ 2][outputChannel][1], std::complex<float>(25, 0));
switch (ps.nrVisibilityPolarizations())
{
case 2 :
check(mappedVisibilities[ 2][outputChannel][1], std::complex<float>(25, 0));
check(mappedVisibilities[ 9][outputChannel][0], std::complex<float>(61, 0));
break;
case 4 : check(mappedVisibilities[ 2][outputChannel][3], std::complex<float>(25, 0));
case 4 :
check(mappedVisibilities[ 2][outputChannel][3], std::complex<float>(25, 0));
check(mappedVisibilities[ 7][outputChannel][2], std::complex<float>(39, 2));
check(mappedVisibilities[ 9][outputChannel][0], std::complex<float>(61, 0));
break;
......@@ -218,63 +145,30 @@ struct CorrelateTriangleTest : public CorrelatorUnitTest
}
};
#else
struct CorrelatorTest : public UnitTest
{
CorrelatorTest(const CorrelatorParset &ps)
:
UnitTest(ps, "Correlator/Kernels/Correlator.cl")
{
if (ps.nrStations() >= 5 && ps.nrChannelsPerSubband() >= 6 && ps.nrSamplesPerChannel() >= 100) {
Buffer<std::complex<float>, 4> inputData(boost::extents[ps.nrStations()][ps.nrChannelsPerSubband()][ps.nrSamplesPerChannel()][ps.nrPolarizations()], context, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY);
Buffer<std::complex<float>, 4> visibilities(boost::extents[ps.nrBaselines()][ps.nrChannelsPerSubband()][ps.nrPolarizations()][ps.nrPolarizations()], context, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY);
CorrelatorKernel correlator(ps, queue, program, visibilities, inputData);
{
MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true);
mappedInputData[3][5][99][POL_Y] = std::complex<float>(3, 4);
mappedInputData[4][5][99][POL_Y] = std::complex<float>(5, 6);
}
correlator.enqueue(queue, counter);
{
MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ);
check(mappedVisibilities[ 9][5][POL_Y][POL_Y], std::complex<float>(25, 0));
check(mappedVisibilities[13][5][POL_Y][POL_Y], std::complex<float>(39, 2));
check(mappedVisibilities[14][5][POL_Y][POL_Y], std::complex<float>(61, 0));
}
}
}
};
#endif
int main(int argc, char **argv)
{
#if !defined CREATE_BACKTRACE_ON_EXCEPTION
try {
try
{
#endif
std::cout << ">>> Running CorrelatorTest" << std::endl;
CorrelatorParset ps(argc, argv);
#if defined USE_PHI_CORRELATOR
(CorrelateRectangleTest)(ps);
#elif defined USE_NEW_CORRELATOR
std::cout << "With " << ps.nrStations() << " number of stations" << std::endl;
(CorrelateSquareTest)(ps);
if (ps.nrStations() % 32 != 0)
{
(CorrelateRectangleTest)(ps);
}
(CorrelateTriangleTest)(ps);
#else
(CorrelatorTest)(ps);
#endif
#if !defined CREATE_BACKTRACE_ON_EXCEPTION
} catch (cl::Error &ex) {
}
catch (cl::Error &ex)
{
#pragma omp critical (cerr)
std::cerr << "caught cl::Error: " << ex.what() << ": " << errorMessage(ex.err()) << std::endl;
exit(1);
......
......@@ -15,7 +15,15 @@ make -j
```
## Usage
A test program `./Correlator/Correlator`
A test program for the Correlator pipeline `./Correlator/Correlator`
Unit tests in `/Correlator/Tests` :
* `CorrelatorTest`;
Uses 288 stations by default and therefore does not run subtest `CorrelateRectangleTest` (only used when nr of stations is not a multiple of 32)
* `DelayAndBandPassTest`
* `DeviceInstanceTest`
* `Filter_FFT_Test`
* `FIR_FilterTest`
# AARTFAAC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment