1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-11-05 09:43:04 +00:00

Merge branch 'odrisci-fix_pcps_threshold' into next. Fixes: #331

This commit is contained in:
Carles Fernandez
2019-11-24 21:24:16 +01:00
36 changed files with 1158 additions and 1099 deletions

View File

@@ -40,6 +40,7 @@ set(GNSS_SPLIBS_SOURCES
conjugate_ic.cc
gnss_sdr_create_directory.cc
geofunctions.cc
item_type_helpers.cc
)
set(GNSS_SPLIBS_HEADERS
@@ -65,6 +66,7 @@ set(GNSS_SPLIBS_HEADERS
gnss_sdr_create_directory.h
gnss_circular_deque.h
geofunctions.h
item_type_helpers.h
)
if(ENABLE_OPENCL)
@@ -133,6 +135,30 @@ target_compile_definitions(algorithms_libs
PUBLIC -DGNSSSDR_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}"
)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND NOT WIN32)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1")
target_compile_definitions(algorithms_libs
PRIVATE -DOLDCOMPILER=1
)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CLANG_VERSION VERSION_LESS "600")
target_compile_definitions(algorithms_libs
PRIVATE -DOLDCOMPILER=1
)
endif()
else()
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0")
target_compile_definitions(algorithms_libs
PRIVATE -DOLDCOMPILER=1
)
endif()
endif()
endif()
set_property(TARGET algorithms_libs
APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>

View File

@@ -0,0 +1,409 @@
/*!
* \file item_type_helpers.cc
* \brief Utility functions for converting between item types
* \authors <ul>
* <li> Cillian O'Driscoll, 2019. cillian.odriscoll(at)gmail.com
* </ul>
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "item_type_helpers.h"
#include <volk/volk.h>
#include <volk_gnsssdr/volk_gnsssdr.h>
#include <cstring> // memcpy
bool item_type_valid(const std::string &item_type)
{
if (item_type != "byte" and item_type != "cbyte" and item_type != "ibyte" and
item_type != "short" and item_type != "cshort" and item_type != "ishort" and
item_type != "float" and item_type != "gr_complex")
{
return false;
}
return true;
}
size_t item_type_size(const std::string &item_type)
{
if (item_type == "byte" or item_type == "ibyte")
{
return sizeof(int8_t);
}
else if (item_type == "cbyte")
{
return 2 * sizeof(int8_t);
}
else if (item_type == "short" or item_type == "ishort")
{
return sizeof(int16_t);
}
else if (item_type == "cshort")
{
return 2 * sizeof(int16_t);
}
else if (item_type == "float")
{
return sizeof(float);
}
else if (item_type == "gr_complex")
{
return 2 * sizeof(float);
}
else
{
return 0;
}
}
bool item_type_is_complex(const std::string &item_type)
{
return (item_type == "ibyte") or (item_type == "cbyte") or (item_type == "ishort") or (item_type == "cshort") or (item_type == "gr_complex");
}
void copy_converter(void *dest, const void *src, unsigned int num_items, size_t item_size)
{
std::memcpy(dest, src, num_items * item_size);
}
void convert_8i_16i(void *dest, const void *src, unsigned int num_items)
{
volk_8i_convert_16i(reinterpret_cast<int16_t *>(dest),
reinterpret_cast<const int8_t *>(src), num_items);
}
void convert_8i_32f(void *dest, const void *src, unsigned int num_items)
{
volk_8i_s32f_convert_32f(reinterpret_cast<float *>(dest),
reinterpret_cast<const int8_t *>(src), 1.0F, num_items);
}
void convert_8ic_16ic(void *dest, const void *src, unsigned int num_items)
{
volk_8i_convert_16i(reinterpret_cast<int16_t *>(dest),
reinterpret_cast<const int8_t *>(src), 2 * num_items);
}
void convert_8ic_32fc(void *dest, const void *src, unsigned int num_items)
{
volk_8i_s32f_convert_32f(reinterpret_cast<float *>(dest),
reinterpret_cast<const int8_t *>(src), 1.0F, 2 * num_items);
}
void convert_16i_8i(void *dest, const void *src, unsigned int num_items)
{
volk_16i_convert_8i(reinterpret_cast<int8_t *>(dest),
reinterpret_cast<const int16_t *>(src), num_items);
}
void convert_16i_32f(void *dest, const void *src, unsigned int num_items)
{
volk_16i_s32f_convert_32f(reinterpret_cast<float *>(dest),
reinterpret_cast<const int16_t *>(src), 1.0F, num_items);
}
void convert_16ic_8ic(void *dest, const void *src, unsigned int num_items)
{
volk_16i_convert_8i(reinterpret_cast<int8_t *>(dest),
reinterpret_cast<const int16_t *>(src), 2 * num_items);
}
void convert_16ic_32fc(void *dest, const void *src, unsigned int num_items)
{
volk_16i_s32f_convert_32f(reinterpret_cast<float *>(dest),
reinterpret_cast<const int16_t *>(src), 1.0F, 2 * num_items);
}
void convert_32f_8i(void *dest, const void *src, unsigned int num_items)
{
volk_32f_s32f_convert_8i(reinterpret_cast<int8_t *>(dest),
reinterpret_cast<const float *>(src), 1.0F, num_items);
}
void convert_32f_16i(void *dest, const void *src, unsigned int num_items)
{
volk_32f_s32f_convert_16i(reinterpret_cast<int16_t *>(dest),
reinterpret_cast<const float *>(src), 1.0F, num_items);
}
void convert_32fc_8ic(void *dest, const void *src, unsigned int num_items)
{
volk_32f_s32f_convert_8i(reinterpret_cast<int8_t *>(dest),
reinterpret_cast<const float *>(src), 1.0F, 2 * num_items);
}
void convert_32fc_16ic(void *dest, const void *src, unsigned int num_items)
{
volk_32f_s32f_convert_16i(reinterpret_cast<int16_t *>(dest),
reinterpret_cast<const float *>(src), 1.0F, 2 * num_items);
}
item_type_converter_t make_vector_converter(const std::string &input_type,
const std::string &output_type)
{
if (not item_type_valid(input_type) or not item_type_valid(output_type))
{
throw std::runtime_error("make_vector_converter: invalid item types : " + input_type + " " + output_type);
}
if (input_type == output_type)
{
size_t input_size = item_type_size(input_type);
#ifdef OLDCOMPILER
return std::bind(copy_converter, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, input_size);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return copy_converter(arg1, arg2, arg3, input_size); };
#endif
}
if (input_type == "byte")
{
if (output_type == "short")
{
#ifdef OLDCOMPILER
return std::bind(convert_8i_16i, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_8i_16i(arg1, arg2, arg3); };
#endif
}
else if (output_type == "float")
{
#ifdef OLDCOMPILER
return std::bind(convert_8i_32f, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_8i_32f(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "cbyte")
{
if (output_type == "ibyte")
{
size_t input_size = item_type_size(input_type);
#ifdef OLDCOMPILER
return std::bind(copy_converter, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, input_size);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return copy_converter(arg1, arg2, arg3, input_size); };
#endif
}
if (output_type == "cshort" or output_type == "ishort")
{
#ifdef OLDCOMPILER
return std::bind(convert_8ic_16ic, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_8ic_16ic(arg1, arg2, arg3); };
#endif
}
else if (output_type == "gr_complex")
{
#ifdef OLDCOMPILER
return std::bind(convert_8ic_32fc, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_8ic_32fc(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "ibyte")
{
if (output_type == "cbyte")
{
size_t input_size = item_type_size(input_type);
#ifdef OLDCOMPILER
return std::bind(copy_converter, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, input_size);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return copy_converter(arg1, arg2, arg3, input_size); };
#endif
}
else if (output_type == "cshort" or output_type == "ishort")
{
#ifdef OLDCOMPILER
return std::bind(convert_8i_16i, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_8i_16i(arg1, arg2, arg3); };
#endif
}
else if (output_type == "gr_complex")
{
#ifdef OLDCOMPILER
return std::bind(convert_8i_32f, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_8i_32f(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "short")
{
if (output_type == "byte")
{
#ifdef OLDCOMPILER
return std::bind(convert_16i_8i, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_16i_8i(arg1, arg2, arg3); };
#endif
}
else if (output_type == "float")
{
#ifdef OLDCOMPILER
return std::bind(convert_16i_32f, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_16i_32f(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "cshort")
{
if (output_type == "cbyte" or output_type == "ibyte")
{
#ifdef OLDCOMPILER
return std::bind(convert_16ic_8ic, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_16ic_8ic(arg1, arg2, arg3); };
#endif
}
if (output_type == "ishort")
{
size_t input_size = item_type_size(input_type);
#ifdef OLDCOMPILER
return std::bind(copy_converter, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, input_size);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return copy_converter(arg1, arg2, arg3, input_size); };
#endif
}
else if (output_type == "gr_complex")
{
#ifdef OLDCOMPILER
return std::bind(convert_16ic_32fc, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_16ic_32fc(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "ishort")
{
if (output_type == "cbyte" or output_type == "ibyte")
{
#ifdef OLDCOMPILER
return std::bind(convert_16i_8i, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_16i_8i(arg1, arg2, arg3); };
#endif
}
if (output_type == "cshort")
{
size_t input_size = item_type_size(input_type);
#ifdef OLDCOMPILER
return std::bind(copy_converter, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, input_size);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return copy_converter(arg1, arg2, arg3, input_size); };
#endif
}
else if (output_type == "gr_complex")
{
#ifdef OLDCOMPILER
return std::bind(convert_16i_32f, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_16i_32f(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "float")
{
if (output_type == "byte")
{
#ifdef OLDCOMPILER
return std::bind(convert_32f_8i, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_32f_8i(arg1, arg2, arg3); };
#endif
}
else if (output_type == "short")
{
#ifdef OLDCOMPILER
return std::bind(convert_32f_16i, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_32f_16i(arg1, arg2, arg3); };
#endif
}
}
else if (input_type == "gr_complex")
{
if (output_type == "cbyte" or output_type == "ibyte")
{
#ifdef OLDCOMPILER
return std::bind(convert_32fc_8ic, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_32fc_8ic(arg1, arg2, arg3); };
#endif
}
else if (output_type == "cshort" or output_type == "ishort")
{
#ifdef OLDCOMPILER
return std::bind(convert_32fc_16ic, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
#else
return [=](auto &&arg1, auto &&arg2, auto &&arg3) { return convert_32fc_16ic(arg1, arg2, arg3); };
#endif
}
}
throw std::runtime_error("make_vector_converter: invalid conversion : " + input_type + " to " + output_type);
}

View File

@@ -0,0 +1,88 @@
/*!
* \file item_type_helpers.h
* \brief Utility functions for converting between item types
* \authors <ul>
* <li> Cillian O'Driscoll, 2019. cillian.odriscoll(at)gmail.com
* </ul>
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_ITEM_TYPE_HELPERS_H_
#define GNSS_SDR_ITEM_TYPE_HELPERS_H_
#include <functional>
#include <string>
using item_type_converter_t = std::function<void(void *, const void *, unsigned)>;
/*!
* \brief Check if a string is a valid item type
*
* \description Valid item types include:
* "byte", "short", "float", "ibyte", "ishort", "cbyte", "cshort", "gr_complex"
*
*/
bool item_type_valid(const std::string &item_type);
/*!
* \brief Return the size of the given item type, or zero if unknown
*/
size_t item_type_size(const std::string &item_type);
/*!
* \brief Determine if an item_type is complex
*/
bool item_type_is_complex(const std::string &item_type);
/*!
* \brief Create a function to convert an array of input_type to an array of output_type
*
* \description Provides a generic interface to generate conversion functions for mapping
* arrays of items.
*
* \param input_type - String representation of the input item type
* \param output_type - String representation of the output item type
*
* The item types accepted are:
*
* 1. "byte" for 8 bit integers
* 2. "cbyte" for complex (interleaved) 8 bit integers
* 4. "ibyte" for complex (interleaved) 8 bit integers
* 4. "short" for 16 bit integers
* 5. "cshort" for complex (interleaved) 16 bit integers
* 6. "ishort" for complex (interleaved) 16 bit integers
* 7. "float" for 32 bit floating point values
* 8. "gr_complex" for complex (interleaved) 32 bit floating point values
*
* \returns A function object with the following prototype:
* void convert_fun( void *dest, void *src, int num_items );
*
*/
item_type_converter_t make_vector_converter(const std::string &input_type,
const std::string &output_type);
#endif

View File

@@ -5722,7 +5722,7 @@ inline VECTOR_CLASS<char*> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err
{
VECTOR_CLASS< ::size_t> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
VECTOR_CLASS<char*> binaries;
for (unsigned long & size : sizes)
for (unsigned long& size : sizes)
{
char* ptr = nullptr;
if (size != 0)