diff --git a/Common/UnitTest.h b/Common/UnitTest.h index 6837d318dd117af029870f98454d71da24522211..dc36cecf54eb6fc5260d718ba89ba0ea198b2995 100644 --- a/Common/UnitTest.h +++ b/Common/UnitTest.h @@ -20,16 +20,19 @@ class UnitTest queue = cl::CommandQueue(context, devices[0], CL_QUEUE_PROFILING_ENABLE); if (programName != 0) - program = createProgram(ps, context, devices, programName, extraArgs); + program = createProgram(ps, context, devices, programName, extraArgs); } template <typename T> void check(T actual, T expected) { - if (expected != actual) { - std::cerr << "Test FAILED: expected " << expected << ", computed " << actual << std::endl; - exit(1); - } else { - std::cout << "Test OK" << std::endl; + if (expected != actual) + { + std::cerr << "Test FAILED: expected " << expected << ", computed " << actual << std::endl; + exit(1); + } + else + { + std::cout << "Test OK" << std::endl; } } diff --git a/Correlator/Tests/CorrelatorTest.cc b/Correlator/Tests/CorrelatorTest.cc index 14a08f89b1af91c74f69a6fff8ad7e64dbf241f3..9934c46f478ad4d5ea7f76b66e5d9d5959f2a904 100644 --- a/Correlator/Tests/CorrelatorTest.cc +++ b/Correlator/Tests/CorrelatorTest.cc @@ -8,273 +8,167 @@ #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); { - MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true); + MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true); - mappedInputData[5][99][27][POL_Y] = std::complex<float>(3, 4); - mappedInputData[5][99][63][POL_Y] = std::complex<float>(5, 6); + mappedInputData[5][99][27][POL_Y] = std::complex<float>(3, 4); + mappedInputData[5][99][63][POL_Y] = std::complex<float>(5, 6); } correlator.enqueue(queue, counter); { - MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ); + MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ); - unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor(); - unsigned outputPolarization = ps.nrVisibilityPolarizations() == 2 ? 1 : 3; - check(mappedVisibilities[2043][outputChannel][outputPolarization], std::complex<float>(39, 2)); + unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor(); + unsigned outputPolarization = ps.nrVisibilityPolarizations() == 2 ? 1 : 3; + check(mappedVisibilities[2043][outputChannel][outputPolarization], std::complex<float>(39, 2)); #if 0 - for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++) - for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++) - for (unsigned pol = 0; pol < ps.nrVisibilityPolarizations(); pol ++) - if (visibilities[bl][ch][pol] != std::complex<float>(0, 0)) - std::cout << "vis[" << bl << "][" << ch << "][" << pol << "] = " << visibilities[bl][ch][pol] << std::endl; + for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++) + for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++) + for (unsigned pol = 0; pol < ps.nrVisibilityPolarizations(); pol ++) + if (visibilities[bl][ch][pol] != std::complex<float>(0, 0)) + std::cout << "vis[" << bl << "][" << ch << "][" << pol << "] = " << visibilities[bl][ch][pol] << std::endl; #endif } } } }; - 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); { - MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true); + MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true); - mappedInputData[5][99][27][POL_Y] = std::complex<float>(3, 4); - mappedInputData[5][99][68][POL_Y] = std::complex<float>(5, 6); + mappedInputData[5][99][27][POL_Y] = std::complex<float>(3, 4); + mappedInputData[5][99][68][POL_Y] = std::complex<float>(5, 6); } correlator.enqueue(queue, counter); { - MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ); + MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ); - unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor(); - unsigned outputPolarization = ps.nrVisibilityPolarizations() == 2 ? 1 : 3; - check(mappedVisibilities[2373][outputChannel][outputPolarization], std::complex<float>(39, 2)); + unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor(); + unsigned outputPolarization = ps.nrVisibilityPolarizations() == 2 ? 1 : 3; + check(mappedVisibilities[2373][outputChannel][outputPolarization], std::complex<float>(39, 2)); #if 0 - for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++) - for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++) - for (unsigned pol = 0; pol < ps.nrVisibilityPolarizations(); pol ++) - if (visibilities[bl][ch][pol] != std::complex<float>(0, 0)) - std::cout << "vis[" << bl << "][" << ch << "][" << pol << "] = " << visibilities[bl][ch][pol] << std::endl; + for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++) + for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++) + for (unsigned pol = 0; pol < ps.nrVisibilityPolarizations(); pol ++) + if (visibilities[bl][ch][pol] != std::complex<float>(0, 0)) + std::cout << "vis[" << bl << "][" << ch << "][" << pol << "] = " << visibilities[bl][ch][pol] << std::endl; #endif } } } }; - 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); { - MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true); + MappedBuffer<std::complex<float>, 4> mappedInputData(queue, inputData, CL_MAP_WRITE, true); - mappedInputData[5][99][1][POL_Y] = std::complex<float>(3, 4); - mappedInputData[5][99][3][POL_X] = std::complex<float>(5, 6); + mappedInputData[5][99][1][POL_Y] = std::complex<float>(3, 4); + mappedInputData[5][99][3][POL_X] = std::complex<float>(5, 6); } correlator.enqueue(queue, counter); { - MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ); + MappedBuffer<std::complex<float>, 3> mappedVisibilities(queue, visibilities, CL_MAP_READ); #if 1 - unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor(); - - 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)); - check(mappedVisibilities[ 7][outputChannel][2], std::complex<float>(39, 2)); - check(mappedVisibilities[ 9][outputChannel][0], std::complex<float>(61, 0)); - break; - } + unsigned outputChannel = (5 - 1) / ps.channelIntegrationFactor(); + + 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)); + check(mappedVisibilities[ 7][outputChannel][2], std::complex<float>(39, 2)); + check(mappedVisibilities[ 9][outputChannel][0], std::complex<float>(61, 0)); + break; + } #else - for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++) - for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++) - for (unsigned pol = 0; pol < ps.nrVisibilityPolarizations(); pol ++) - if (visibilities[bl][ch][pol] != std::complex<float>(0, 0)) - std::cout << "vis[" << bl << "][" << ch << "][" << pol << "] = " << visibilities[bl][ch][pol] << std::endl; + for (unsigned bl = 0; bl < ps.nrBaselines(); bl ++) + for (unsigned ch = 0; ch < ps.nrChannelsPerSubband(); ch ++) + for (unsigned pol = 0; pol < ps.nrVisibilityPolarizations(); pol ++) + if (visibilities[bl][ch][pol] != std::complex<float>(0, 0)) + std::cout << "vis[" << bl << "][" << ch << "][" << pol << "] = " << visibilities[bl][ch][pol] << std::endl; #endif } } } }; -#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); diff --git a/README.md b/README.md index aff1e5f9954c545a29ab7aa16856d082478e5832..8e881e82f9dc3dd30c8b77eb67a8b69f468522c6 100644 --- a/README.md +++ b/README.md @@ -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