Skip to content
Snippets Groups Projects
Commit 0f7e5849 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

COB-60: moved reamining cuda files up one level to the one-and-only implementation dir.

parent 8cdd86a6
No related branches found
No related tags found
1 merge request!6Import cobalt2 into lofar4
Showing
with 791 additions and 1016 deletions
......@@ -30,7 +30,7 @@
#include <Common/LofarLogger.h>
#include <CoInterface/Parset.h>
#include <GPUProc/Pipelines/Pipeline.h>
#include <GPUProc/cuda/SubbandProcs/SubbandProcOutputData.h>
#include <GPUProc/SubbandProcs/SubbandProcOutputData.h>
#include <GPUProc/Station/StationInput.h>
#include <GPUProc/Storage/StorageProcesses.h>
......
......@@ -30,7 +30,7 @@
#include <Common/LofarLogger.h>
#include <CoInterface/Parset.h>
#include <GPUProc/Pipelines/Pipeline.h>
#include <GPUProc/cuda/SubbandProcs/SubbandProcOutputData.h>
#include <GPUProc/SubbandProcs/SubbandProcOutputData.h>
#include <GPUProc/Station/StationInput.h>
#include <GPUProc/Storage/StorageProcesses.h>
......
......@@ -7,6 +7,11 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/include/${PACKAGE_NAME})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cuda_config.h.in"
"${CMAKE_BINARY_DIR}/include/cuda_config.h" # internal, no need to install
)
set(_gpuproc_sources
#Package__Version.cc
BandPass.cc
......@@ -26,10 +31,10 @@ set(_gpuproc_sources
)
list(APPEND _gpuproc_sources
cuda/gpu_wrapper.cc
cuda/gpu_utils.cc
cuda/KernelFactory.cc
cuda/PerformanceCounter.cc
gpu_wrapper.cc
gpu_utils.cc
KernelFactory.cc
PerformanceCounter.cc
Kernels/Kernel.cc
Kernels/BeamFormerKernel.cc
Kernels/BeamFormerTransposeKernel.cc
......@@ -67,7 +72,6 @@ list(APPEND _gpuproc_sources
# SubbandProcs/UHEP_SubbandProc.cc
)
add_subdirectory(cuda)
lofar_add_library(gpuproc ${_gpuproc_sources})
if(CUDA_cufft_LIBRARY)
......
//# KernelFactory.h: Factory for Kernel objects.
//# KernelFactory.h
//#
//# Copyright (C) 2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
......@@ -19,23 +19,122 @@
//#
//# $Id$
// \file
// Factory for Kernel objects.
#ifndef LOFAR_GPUPROC_CUDA_KERNELFACTORY_H
#define LOFAR_GPUPROC_CUDA_KERNELFACTORY_H
#ifndef LOFAR_GPUPROC_KERNELFACTORY_H
#define LOFAR_GPUPROC_KERNELFACTORY_H
#include <string>
#include <CoInterface/Parset.h>
#include <GPUProc/Kernels/Kernel.h>
#include <GPUProc/gpu_wrapper.h>
#include <GPUProc/gpu_utils.h>
#if defined (USE_CUDA) && defined (USE_OPENCL)
# error "Either CUDA or OpenCL must be enabled, not both"
#endif
namespace LOFAR
{
namespace Cobalt
{
// Abstract base class of the templated KernelFactory class.
class KernelFactoryBase
{
public:
// Pure virtual destructor, because this is an abstract base class.
virtual ~KernelFactoryBase() = 0;
#if defined (USE_CUDA)
# include "cuda/KernelFactory.h"
#elif defined (USE_OPENCL)
# include "opencl/KernelFactory.h"
#else
# error "Either CUDA or OpenCL must be enabled, not neither"
#endif
protected:
// Return compile definitions to use when creating PTX code for any
// Kernel.
CompileDefinitions
compileDefinitions(const Kernel::Parameters& param) const;
#endif
// Return compile flags to use when creating PTX code for any Kernel.
CompileFlags
compileFlags(const Kernel::Parameters& param) const;
};
// Declaration of a generic factory class. For each concrete Kernel class
// (e.g. FIR_FilterKernel), a specialization must exist of the constructor
// and of the bufferSize() method.
template<typename T> class KernelFactory : public KernelFactoryBase
{
public:
// typedef typename T::Parameters Parameters;
typedef typename T::BufferType BufferType;
typedef typename T::Buffers Buffers;
// Construct a factory for creating Kernel objects of type \c T, using the
// settings provided by \a params.
KernelFactory(const typename T::Parameters &params) :
itsParameters(params),
itsPTX(_createPTX())
{
}
// Create a new Kernel object of type \c T.
T* create(const gpu::Stream& stream,
gpu::DeviceMemory &inputBuffer,
gpu::DeviceMemory &outputBuffer) const
{
const typename T::Buffers buffers(inputBuffer, outputBuffer);
return create(stream, buffers);
}
// Return required buffer size for \a bufferType
size_t bufferSize(BufferType bufferType) const
{
return itsParameters.bufferSize(bufferType);
}
private:
// Used by the constructors to construct the PTX from the other
// members.
std::string _createPTX() const {
return createPTX(T::theirSourceFile,
compileDefinitions(),
compileFlags());
}
// Create a new Kernel object of type \c T.
T* create(const gpu::Stream& stream,
const typename T::Buffers& buffers) const
{
// Since we use overlapping input/output buffers, their size
// could be larger than we need.
ASSERTSTR(buffers.input.size() >= bufferSize(T::INPUT_DATA),
"Require " << bufferSize(T::INPUT_DATA) << " bytes for input, "
"but buffer is only " << buffers.input.size() << " bytes.");
ASSERTSTR(buffers.output.size() >= bufferSize(T::OUTPUT_DATA),
"Require " << bufferSize(T::OUTPUT_DATA) << " bytes for output, "
"but buffer is only " << buffers.output.size() << " bytes.");
return new T(
stream, createModule(stream.getContext(),
T::theirSourceFile,
itsPTX),
buffers, itsParameters);
}
// Return compile definitions to use when creating PTX code for kernels of
// type \c T, using the parameters stored in \c itsParameters.
CompileDefinitions compileDefinitions() const {
return KernelFactoryBase::compileDefinitions(itsParameters);
}
// Return compile flags to use when creating PTX code for kernels of type
// \c T.
CompileFlags compileFlags() const {
return KernelFactoryBase::compileFlags(itsParameters);
}
// Additional parameters needed to create a Kernel object of type \c T.
typename T::Parameters itsParameters;
// PTX code, generated for kernels of type \c T, using information in the
// Parset that was passed to the constructor.
std::string itsPTX;
};
} // namespace Cobalt
} // namespace LOFAR
#endif
//# MultiDimArrayHostBuffer.h
//#
//# Copyright (C) 2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
......@@ -19,23 +18,45 @@
//#
//# $Id$
// \file
// Support for our multi-dim array-ed GPU host buffer.
#ifndef LOFAR_GPUPROC_CUDA_MULTI_DIM_ARRAY_HOST_BUFFER_H
#define LOFAR_GPUPROC_CUDA_MULTI_DIM_ARRAY_HOST_BUFFER_H
#ifndef LOFAR_GPUPROC_MULTI_DIM_ARRAY_HOST_BUFFER_H
#define LOFAR_GPUPROC_MULTI_DIM_ARRAY_HOST_BUFFER_H
#include <CoInterface/MultiDimArray.h>
#if defined (USE_CUDA) && defined (USE_OPENCL)
# error "Either CUDA or OpenCL must be enabled, not both"
#endif
#include "gpu_wrapper.h"
#if defined (USE_CUDA)
# include "cuda/MultiDimArrayHostBuffer.h"
#elif defined (USE_OPENCL)
# include "opencl/MultiDimArrayHostBuffer.h"
#else
# error "Either CUDA or OpenCL must be enabled, not neither"
#endif
namespace LOFAR
{
namespace Cobalt
{
// A MultiDimArray allocated as a HostBuffer
// Note: Elements are not constructed/destructed.
template <typename T, unsigned DIM>
class MultiDimArrayHostBuffer : public gpu::HostMemory,
public MultiDimArray<T, DIM>
{
public:
template <typename ExtentList>
MultiDimArrayHostBuffer(const ExtentList &extents, const gpu::Context &context,
unsigned int flags = 0)
:
HostMemory(context, MultiDimArray<T, DIM>::nrElements(extents) * sizeof(T), flags),
MultiDimArray<T, DIM>(extents, gpu::HostMemory::get<T>(), false)
{
}
using HostMemory::size;
private:
MultiDimArrayHostBuffer(); // don't use
MultiDimArrayHostBuffer(const MultiDimArrayHostBuffer<T, DIM> &rhs); // don't use
MultiDimArrayHostBuffer<T, DIM> &operator=(const MultiDimArrayHostBuffer<T, DIM> &rhs); // don't use
using MultiDimArray<T, DIM>::resize; // don't use
};
} // namespace Cobalt
} // namespace LOFAR
#endif
//# PerformanceCounter.h
//#
//# Copyright (C) 2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
......@@ -19,23 +18,48 @@
//#
//# $Id$
// \file
// Support GPU kernel performance timing.
#ifndef LOFAR_GPUPROC_CUDA_PERFORMANCECOUNTER_H
#define LOFAR_GPUPROC_CUDA_PERFORMANCECOUNTER_H
#ifndef LOFAR_PERFORMANCE_COUNTER_H
#define LOFAR_PERFORMANCE_COUNTER_H
#if defined (USE_CUDA) && defined (USE_OPENCL)
# error "Either CUDA or OpenCL must be enabled, not both"
#endif
#include <GPUProc/gpu_wrapper.h>
#include <CoInterface/RunningStatistics.h>
#if defined (USE_CUDA)
# include "cuda/PerformanceCounter.h"
#elif defined (USE_OPENCL)
# include "opencl/PerformanceCounter.h"
#else
# error "Either CUDA or OpenCL must be enabled, not neither"
#endif
namespace LOFAR
{
namespace Cobalt
{
class PerformanceCounter
{
public:
PerformanceCounter(const gpu::Context &context, const std::string &name);
~PerformanceCounter();
void recordStart(const gpu::Stream &stream);
void recordStop(const gpu::Stream &stream);
// Warning: user must make sure that the counter is not running!
RunningStatistics getStats() { logTime(); return stats; }
private:
const std::string name;
// Public event: it needs to be inserted into a stream.
// @{
gpu::Event start;
gpu::Event stop;
// @}
// Whether we have posted events that still need to be
// processed in logTime()
bool recording;
RunningStatistics stats;
void logTime();
};
}
}
#endif
# $Id$
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cuda_config.h.in"
"${CMAKE_BINARY_DIR}/include/cuda_config.h" # internal, no need to install
)
//# KernelFactory.h
//#
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
//# The LOFAR software suite 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.
//#
//# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
//#
//# $Id$
#ifndef LOFAR_GPUPROC_CUDA_KERNELFACTORY_H
#define LOFAR_GPUPROC_CUDA_KERNELFACTORY_H
#include <string>
#include <CoInterface/Parset.h>
#include <GPUProc/Kernels/Kernel.h>
#include <GPUProc/gpu_wrapper.h>
#include <GPUProc/gpu_utils.h>
namespace LOFAR
{
namespace Cobalt
{
// Abstract base class of the templated KernelFactory class.
class KernelFactoryBase
{
public:
// Pure virtual destructor, because this is an abstract base class.
virtual ~KernelFactoryBase() = 0;
protected:
// Return compile definitions to use when creating PTX code for any
// Kernel.
CompileDefinitions
compileDefinitions(const Kernel::Parameters& param) const;
// Return compile flags to use when creating PTX code for any Kernel.
CompileFlags
compileFlags(const Kernel::Parameters& param) const;
};
// Declaration of a generic factory class. For each concrete Kernel class
// (e.g. FIR_FilterKernel), a specialization must exist of the constructor
// and of the bufferSize() method.
template<typename T> class KernelFactory : public KernelFactoryBase
{
public:
// typedef typename T::Parameters Parameters;
typedef typename T::BufferType BufferType;
typedef typename T::Buffers Buffers;
// Construct a factory for creating Kernel objects of type \c T, using the
// settings provided by \a params.
KernelFactory(const typename T::Parameters &params) :
itsParameters(params),
itsPTX(_createPTX())
{
}
// Create a new Kernel object of type \c T.
T* create(const gpu::Stream& stream,
gpu::DeviceMemory &inputBuffer,
gpu::DeviceMemory &outputBuffer) const
{
const typename T::Buffers buffers(inputBuffer, outputBuffer);
return create(stream, buffers);
}
// Return required buffer size for \a bufferType
size_t bufferSize(BufferType bufferType) const
{
return itsParameters.bufferSize(bufferType);
}
private:
// Used by the constructors to construct the PTX from the other
// members.
std::string _createPTX() const {
return createPTX(T::theirSourceFile,
compileDefinitions(),
compileFlags());
}
// Create a new Kernel object of type \c T.
T* create(const gpu::Stream& stream,
const typename T::Buffers& buffers) const
{
// Since we use overlapping input/output buffers, their size
// could be larger than we need.
ASSERTSTR(buffers.input.size() >= bufferSize(T::INPUT_DATA),
"Require " << bufferSize(T::INPUT_DATA) << " bytes for input, "
"but buffer is only " << buffers.input.size() << " bytes.");
ASSERTSTR(buffers.output.size() >= bufferSize(T::OUTPUT_DATA),
"Require " << bufferSize(T::OUTPUT_DATA) << " bytes for output, "
"but buffer is only " << buffers.output.size() << " bytes.");
return new T(
stream, createModule(stream.getContext(),
T::theirSourceFile,
itsPTX),
buffers, itsParameters);
}
// Return compile definitions to use when creating PTX code for kernels of
// type \c T, using the parameters stored in \c itsParameters.
CompileDefinitions compileDefinitions() const {
return KernelFactoryBase::compileDefinitions(itsParameters);
}
// Return compile flags to use when creating PTX code for kernels of type
// \c T.
CompileFlags compileFlags() const {
return KernelFactoryBase::compileFlags(itsParameters);
}
// Additional parameters needed to create a Kernel object of type \c T.
typename T::Parameters itsParameters;
// PTX code, generated for kernels of type \c T, using information in the
// Parset that was passed to the constructor.
std::string itsPTX;
};
} // namespace Cobalt
} // namespace LOFAR
#endif
//# MultiDimArrayHostBuffer.h
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
//# The LOFAR software suite 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.
//#
//# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
//#
//# $Id$
#ifndef LOFAR_GPUPROC_CUDA_MULTI_DIM_ARRAY_HOST_BUFFER_H
#define LOFAR_GPUPROC_CUDA_MULTI_DIM_ARRAY_HOST_BUFFER_H
#include <CoInterface/MultiDimArray.h>
#include "gpu_wrapper.h"
namespace LOFAR
{
namespace Cobalt
{
// A MultiDimArray allocated as a HostBuffer
// Note: Elements are not constructed/destructed.
template <typename T, unsigned DIM>
class MultiDimArrayHostBuffer : public gpu::HostMemory,
public MultiDimArray<T, DIM>
{
public:
template <typename ExtentList>
MultiDimArrayHostBuffer(const ExtentList &extents, const gpu::Context &context,
unsigned int flags = 0)
:
HostMemory(context, MultiDimArray<T, DIM>::nrElements(extents) * sizeof(T), flags),
MultiDimArray<T, DIM>(extents, gpu::HostMemory::get<T>(), false)
{
}
using HostMemory::size;
private:
MultiDimArrayHostBuffer(); // don't use
MultiDimArrayHostBuffer(const MultiDimArrayHostBuffer<T, DIM> &rhs); // don't use
MultiDimArrayHostBuffer<T, DIM> &operator=(const MultiDimArrayHostBuffer<T, DIM> &rhs); // don't use
using MultiDimArray<T, DIM>::resize; // don't use
};
} // namespace Cobalt
} // namespace LOFAR
#endif
//# PerformanceCounter.h
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
//# The LOFAR software suite 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.
//#
//# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
//#
//# $Id$
#ifndef LOFAR_GPUPROC_CUDA_PERFORMANCECOUNTER_H
#define LOFAR_GPUPROC_CUDA_PERFORMANCECOUNTER_H
#include <GPUProc/gpu_wrapper.h>
#include <CoInterface/RunningStatistics.h>
namespace LOFAR
{
namespace Cobalt
{
class PerformanceCounter
{
public:
PerformanceCounter(const gpu::Context &context, const std::string &name);
~PerformanceCounter();
void recordStart(const gpu::Stream &stream);
void recordStop(const gpu::Stream &stream);
// Warning: user must make sure that the counter is not running!
RunningStatistics getStats() { logTime(); return stats; }
private:
const std::string name;
// Public event: it needs to be inserted into a stream.
// @{
gpu::Event start;
gpu::Event stop;
// @}
// Whether we have posted events that still need to be
// processed in logTime()
bool recording;
RunningStatistics stats;
void logTime();
};
}
}
#endif
//# gpu_incl.h: portable CUDA header to mirror OpenCL sources
//# Copyright (C) 2012-2013 ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
//#
//# This file is part of the LOFAR software suite.
//# The LOFAR software suite 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.
//#
//# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
//#
//# $Id$
#ifndef LOFAR_GPUPROC_CUDA_GPU_INCL_H
#define LOFAR_GPUPROC_CUDA_GPU_INCL_H
// Pointless in itself; to mirror the OpenCL sources
// Note: nvcc automatically includes cuda.h, but for most code we don't need it.
// CUDA include option(s)
//<none>
#include <cuda.h>
#endif
This diff is collapsed.
......@@ -25,17 +25,7 @@
#ifndef LOFAR_GPUPROC_GPU_INCL_H
#define LOFAR_GPUPROC_GPU_INCL_H
#if defined (USE_CUDA) && defined (USE_OPENCL)
# error "Either CUDA or OpenCL must be enabled, not both"
#endif
#if defined (USE_CUDA)
# include "cuda/gpu_incl.h"
#elif defined (USE_OPENCL)
# include "opencl/gpu_incl.h"
#else
# error "Either CUDA or OpenCL must be enabled, not neither"
#endif
#include <cuda.h>
#endif
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment