mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-23 21:28:17 +08:00
Add and update samples for cuda 10.1 update 2 support
This commit is contained in:
197
Common/UtilNPP/Exceptions.h
Normal file
197
Common/UtilNPP/Exceptions.h
Normal file
@@ -0,0 +1,197 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NV_UTIL_NPP_EXCEPTIONS_H
|
||||
#define NV_UTIL_NPP_EXCEPTIONS_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
/// All npp related C++ classes are put into the npp namespace.
|
||||
namespace npp
|
||||
{
|
||||
|
||||
/// Exception base class.
|
||||
/// This exception base class will be used for everything C++ throught
|
||||
/// the NPP project.
|
||||
/// The exception contains a string message, as well as data fields for a string
|
||||
/// containing the name of the file as well as the line number where the exception was thrown.
|
||||
/// The easiest way of throwing exceptions and providing filename and line number is
|
||||
/// to use one of the ASSERT macros defined for that purpose.
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
/// \param rMessage A message with information as to why the exception was thrown.
|
||||
/// \param rFileName The name of the file where the exception was thrown.
|
||||
/// \param nLineNumber Line number in the file where the exception was thrown.
|
||||
explicit
|
||||
Exception(const std::string &rMessage = "", const std::string &rFileName = "", unsigned int nLineNumber = 0)
|
||||
: sMessage_(rMessage), sFileName_(rFileName), nLineNumber_(nLineNumber)
|
||||
{ };
|
||||
|
||||
Exception(const Exception &rException)
|
||||
: sMessage_(rException.sMessage_), sFileName_(rException.sFileName_), nLineNumber_(rException.nLineNumber_)
|
||||
{ };
|
||||
|
||||
virtual
|
||||
~Exception()
|
||||
{ };
|
||||
|
||||
/// Get the exception's message.
|
||||
const
|
||||
std::string &
|
||||
message()
|
||||
const
|
||||
{
|
||||
return sMessage_;
|
||||
}
|
||||
|
||||
/// Get the exception's file info.
|
||||
const
|
||||
std::string &
|
||||
fileName()
|
||||
const
|
||||
{
|
||||
return sFileName_;
|
||||
}
|
||||
|
||||
/// Get the exceptions's line info.
|
||||
unsigned int
|
||||
lineNumber()
|
||||
const
|
||||
{
|
||||
return nLineNumber_;
|
||||
}
|
||||
|
||||
|
||||
/// Create a clone of this exception.
|
||||
/// This creates a new Exception object on the heap. It is
|
||||
/// the responsibility of the user of this function to free this memory
|
||||
/// (delete x).
|
||||
virtual
|
||||
Exception *
|
||||
clone()
|
||||
const
|
||||
{
|
||||
return new Exception(*this);
|
||||
}
|
||||
|
||||
/// Create a single string with all the exceptions information.
|
||||
/// The virtual toString() method is used by the operator<<()
|
||||
/// so that all exceptions derived from this base-class can print
|
||||
/// their full information correctly even if a reference to their
|
||||
/// exact type is not had at the time of printing (i.e. the basic
|
||||
/// operator<<() is used).
|
||||
virtual
|
||||
std::string
|
||||
toString()
|
||||
const
|
||||
{
|
||||
std::ostringstream oOutputString;
|
||||
oOutputString << fileName() << ":" << lineNumber() << ": " << message();
|
||||
return oOutputString.str();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string sMessage_; ///< Message regarding the cause of the exception.
|
||||
std::string sFileName_; ///< Name of the file where the exception was thrown.
|
||||
unsigned int nLineNumber_; ///< Line number in the file where the exception was thrown
|
||||
};
|
||||
|
||||
/// Output stream inserter for Exception.
|
||||
/// \param rOutputStream The stream the exception information is written to.
|
||||
/// \param rException The exception that's being written.
|
||||
/// \return Reference to the output stream being used.
|
||||
std::ostream &
|
||||
operator << (std::ostream &rOutputStream, const Exception &rException)
|
||||
{
|
||||
rOutputStream << rException.toString();
|
||||
return rOutputStream;
|
||||
}
|
||||
|
||||
/// Basic assert macro.
|
||||
/// This macro should be used to enforce any kind of pre or post conditions.
|
||||
/// Unlike the C-runtime assert macro, this macro does not abort execution, but throws
|
||||
/// a C++ exception. The exception is automatically filled with information about the failing
|
||||
/// condition, the filename and line number where the exception was thrown.
|
||||
/// \note The macro is written in such a way that omitting a semicolon after its usage
|
||||
/// causes a compiler error. The correct way to invoke this macro is:
|
||||
/// NPP_ASSERT(n < MAX);
|
||||
#define NPP_ASSERT(C) do {if (!(C)) throw npp::Exception(#C " assertion faild!", __FILE__, __LINE__);} while(false)
|
||||
|
||||
// ASSERT macro.
|
||||
// Same functionality as the basic assert macro with the added ability to pass
|
||||
// a message M. M should be a string literal.
|
||||
// Note: Never use code inside ASSERT() that causes a side-effect ASSERT macros may get compiled
|
||||
// out in release mode.
|
||||
#define NPP_ASSERT_MSG(C, M) do {if (!(C)) throw npp::Exception(#C " assertion faild! Message: " M, __FILE__, __LINE__);} while(false)
|
||||
|
||||
#ifdef _DEBUG
|
||||
/// Basic debug assert macro.
|
||||
/// This macro is identical in every respect to NPP_ASSERT(C) but it does get compiled to a
|
||||
/// no-op in release builds. It is therefor of utmost importance to not put statements into
|
||||
/// this macro that cause side effects required for correct program execution.
|
||||
#define NPP_DEBUG_ASSERT(C) do {if (!(C)) throw npp::Exception(#C " debug assertion faild!", __FILE__, __LINE__);} while(false)
|
||||
#else
|
||||
#define NPP_DEBUG_ASSERT(C)
|
||||
#endif
|
||||
|
||||
/// ASSERT for null-pointer test.
|
||||
/// It is safe to put code with side effects into this macro. Also: This macro never
|
||||
/// gets compiled to a no-op because resource allocation may fail based on external causes not under
|
||||
/// control of a software developer.
|
||||
#define NPP_ASSERT_NOT_NULL(P) do {if ((P) == 0) throw npp::Exception(#P " not null assertion faild!", __FILE__, __LINE__);} while(false)
|
||||
|
||||
/// Macro for flagging methods as not implemented.
|
||||
/// The macro throws an exception with a message that an implementation was missing
|
||||
#define NPP_NOT_IMPLEMENTED() do {throw npp::Exception("Implementation missing!", __FILE__, __LINE__);} while(false)
|
||||
|
||||
/// Macro for checking error return code of CUDA (runtime) calls.
|
||||
/// This macro never gets disabled.
|
||||
#define NPP_CHECK_CUDA(S) do {cudaError_t eCUDAResult; \
|
||||
eCUDAResult = S; \
|
||||
if (eCUDAResult != cudaSuccess) std::cout << "NPP_CHECK_CUDA - eCUDAResult = " << eCUDAResult << std::endl; \
|
||||
NPP_ASSERT(eCUDAResult == cudaSuccess);} while (false)
|
||||
|
||||
/// Macro for checking error return code for NPP calls.
|
||||
#define NPP_CHECK_NPP(S) do {NppStatus eStatusNPP; \
|
||||
eStatusNPP = S; \
|
||||
if (eStatusNPP != NPP_SUCCESS) std::cout << "NPP_CHECK_NPP - eStatusNPP = " << _cudaGetErrorEnum(eStatusNPP) << "("<< eStatusNPP << ")" << std::endl; \
|
||||
NPP_ASSERT(eStatusNPP == NPP_SUCCESS);} while (false)
|
||||
|
||||
/// Macro for checking error return codes from cuFFT calls.
|
||||
#define NPP_CHECK_CUFFT(S) do {cufftResult eCUFFTResult; \
|
||||
eCUFFTResult = S; \
|
||||
if (eCUFFTResult != NPP_SUCCESS) std::cout << "NPP_CHECK_CUFFT - eCUFFTResult = " << eCUFFTResult << std::endl; \
|
||||
NPP_ASSERT(eCUFFTResult == CUFFT_SUCCESS);} while (false)
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_EXCEPTIONS_H
|
||||
155
Common/UtilNPP/Image.h
Normal file
155
Common/UtilNPP/Image.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NV_UTIL_NPP_IMAGE_H
|
||||
#define NV_UTIL_NPP_IMAGE_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace npp
|
||||
{
|
||||
|
||||
class Image
|
||||
{
|
||||
public:
|
||||
struct Size
|
||||
{
|
||||
unsigned int nWidth;
|
||||
unsigned int nHeight;
|
||||
|
||||
Size() : nWidth(0), nHeight(0)
|
||||
{ };
|
||||
|
||||
Size(unsigned int nWidthNew, unsigned nHeightNew) : nWidth(nWidthNew), nHeight(nHeightNew)
|
||||
{ };
|
||||
|
||||
Size(const Size &rSize) : nWidth(rSize.nWidth), nHeight(rSize.nHeight)
|
||||
{ };
|
||||
|
||||
Size &
|
||||
operator= (const Size &rSize)
|
||||
{
|
||||
if (&rSize == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
nWidth = rSize.nWidth;
|
||||
nHeight = rSize.nHeight;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
swap(Size &rSize)
|
||||
{
|
||||
unsigned int nTemp;
|
||||
nTemp = nWidth;
|
||||
nWidth = rSize.nWidth;
|
||||
rSize.nWidth = nTemp;
|
||||
|
||||
nTemp = nHeight;
|
||||
nHeight = rSize.nHeight;
|
||||
rSize.nHeight = nTemp;
|
||||
}
|
||||
};
|
||||
|
||||
Image()
|
||||
{ };
|
||||
|
||||
Image(unsigned int nWidth, unsigned int nHeight) : oSize_(nWidth, nHeight)
|
||||
{ };
|
||||
|
||||
Image(const Image::Size &rSize) : oSize_(rSize)
|
||||
{ };
|
||||
|
||||
Image(const Image &rImage) : oSize_(rImage.oSize_)
|
||||
{ };
|
||||
|
||||
virtual
|
||||
~Image()
|
||||
{ };
|
||||
|
||||
Image &
|
||||
operator= (const Image &rImage)
|
||||
{
|
||||
if (&rImage == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
oSize_ = rImage.oSize_;
|
||||
return *this;
|
||||
};
|
||||
|
||||
unsigned int
|
||||
width()
|
||||
const
|
||||
{
|
||||
return oSize_.nWidth;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
height()
|
||||
const
|
||||
{
|
||||
return oSize_.nHeight;
|
||||
}
|
||||
|
||||
Size
|
||||
size()
|
||||
const
|
||||
{
|
||||
return oSize_;
|
||||
}
|
||||
|
||||
void
|
||||
swap(Image &rImage)
|
||||
{
|
||||
oSize_.swap(rImage.oSize_);
|
||||
}
|
||||
|
||||
private:
|
||||
Size oSize_;
|
||||
};
|
||||
|
||||
bool
|
||||
operator== (const Image::Size &rFirst, const Image::Size &rSecond)
|
||||
{
|
||||
return rFirst.nWidth == rSecond.nWidth && rFirst.nHeight == rSecond.nHeight;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!= (const Image::Size &rFirst, const Image::Size &rSecond)
|
||||
{
|
||||
return rFirst.nWidth != rSecond.nWidth || rFirst.nHeight != rSecond.nHeight;
|
||||
}
|
||||
|
||||
} // npp namespace
|
||||
|
||||
|
||||
#endif // NV_UTIL_NPP_IMAGE_H
|
||||
80
Common/UtilNPP/ImageAllocatorsCPU.h
Normal file
80
Common/UtilNPP/ImageAllocatorsCPU.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NV_UTIL_NPP_IMAGE_ALLOCATORS_CPU_H
|
||||
#define NV_UTIL_NPP_IMAGE_ALLOCATORS_CPU_H
|
||||
|
||||
#include "Exceptions.h"
|
||||
|
||||
namespace npp
|
||||
{
|
||||
|
||||
template <typename D, size_t N>
|
||||
class ImageAllocatorCPU
|
||||
{
|
||||
public:
|
||||
static
|
||||
D *
|
||||
Malloc2D(unsigned int nWidth, unsigned int nHeight, unsigned int *pPitch)
|
||||
{
|
||||
NPP_ASSERT(nWidth * nHeight > 0);
|
||||
|
||||
D *pResult = new D[nWidth * N * nHeight];
|
||||
*pPitch = nWidth * sizeof(D) * N;
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free2D(D *pPixels)
|
||||
{
|
||||
delete[] pPixels;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy2D(D *pDst, size_t nDstPitch, const D *pSrc, size_t nSrcPitch, size_t nWidth, size_t nHeight)
|
||||
{
|
||||
const void *pSrcLine = pSrc;
|
||||
void *pDstLine = pDst;
|
||||
|
||||
for (size_t iLine = 0; iLine < nHeight; ++iLine)
|
||||
{
|
||||
// copy one line worth of data
|
||||
memcpy(pDst, pSrc, nWidth * N * sizeof(D));
|
||||
// move data pointers to next line
|
||||
pDst += nDstPitch;
|
||||
pSrc += nSrcPitch;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_IMAGE_ALLOCATORS_CPU_H
|
||||
1139
Common/UtilNPP/ImageAllocatorsNPP.h
Normal file
1139
Common/UtilNPP/ImageAllocatorsNPP.h
Normal file
File diff suppressed because it is too large
Load Diff
149
Common/UtilNPP/ImageIO.h
Normal file
149
Common/UtilNPP/ImageIO.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NV_UTIL_NPP_IMAGE_IO_H
|
||||
#define NV_UTIL_NPP_IMAGE_IO_H
|
||||
|
||||
#include "ImagesCPU.h"
|
||||
#include "ImagesNPP.h"
|
||||
|
||||
#include "FreeImage.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
#include <string>
|
||||
#include "string.h"
|
||||
|
||||
|
||||
// Error handler for FreeImage library.
|
||||
// In case this handler is invoked, it throws an NPP exception.
|
||||
void
|
||||
FreeImageErrorHandler(FREE_IMAGE_FORMAT oFif, const char *zMessage)
|
||||
{
|
||||
throw npp::Exception(zMessage);
|
||||
}
|
||||
|
||||
namespace npp
|
||||
{
|
||||
// Load a gray-scale image from disk.
|
||||
void
|
||||
loadImage(const std::string &rFileName, ImageCPU_8u_C1 &rImage)
|
||||
{
|
||||
// set your own FreeImage error handler
|
||||
FreeImage_SetOutputMessage(FreeImageErrorHandler);
|
||||
|
||||
FREE_IMAGE_FORMAT eFormat = FreeImage_GetFileType(rFileName.c_str());
|
||||
|
||||
// no signature? try to guess the file format from the file extension
|
||||
if (eFormat == FIF_UNKNOWN)
|
||||
{
|
||||
eFormat = FreeImage_GetFIFFromFilename(rFileName.c_str());
|
||||
}
|
||||
|
||||
NPP_ASSERT(eFormat != FIF_UNKNOWN);
|
||||
// check that the plugin has reading capabilities ...
|
||||
FIBITMAP *pBitmap;
|
||||
|
||||
if (FreeImage_FIFSupportsReading(eFormat))
|
||||
{
|
||||
pBitmap = FreeImage_Load(eFormat, rFileName.c_str());
|
||||
}
|
||||
|
||||
NPP_ASSERT(pBitmap != 0);
|
||||
// make sure this is an 8-bit single channel image
|
||||
NPP_ASSERT(FreeImage_GetColorType(pBitmap) == FIC_MINISBLACK);
|
||||
NPP_ASSERT(FreeImage_GetBPP(pBitmap) == 8);
|
||||
|
||||
// create an ImageCPU to receive the loaded image data
|
||||
ImageCPU_8u_C1 oImage(FreeImage_GetWidth(pBitmap), FreeImage_GetHeight(pBitmap));
|
||||
|
||||
// Copy the FreeImage data into the new ImageCPU
|
||||
unsigned int nSrcPitch = FreeImage_GetPitch(pBitmap);
|
||||
const Npp8u *pSrcLine = FreeImage_GetBits(pBitmap) + nSrcPitch * (FreeImage_GetHeight(pBitmap) -1);
|
||||
Npp8u *pDstLine = oImage.data();
|
||||
unsigned int nDstPitch = oImage.pitch();
|
||||
|
||||
for (size_t iLine = 0; iLine < oImage.height(); ++iLine)
|
||||
{
|
||||
memcpy(pDstLine, pSrcLine, oImage.width() * sizeof(Npp8u));
|
||||
pSrcLine -= nSrcPitch;
|
||||
pDstLine += nDstPitch;
|
||||
}
|
||||
|
||||
// swap the user given image with our result image, effecively
|
||||
// moving our newly loaded image data into the user provided shell
|
||||
oImage.swap(rImage);
|
||||
}
|
||||
|
||||
// Save an gray-scale image to disk.
|
||||
void
|
||||
saveImage(const std::string &rFileName, const ImageCPU_8u_C1 &rImage)
|
||||
{
|
||||
// create the result image storage using FreeImage so we can easily
|
||||
// save
|
||||
FIBITMAP *pResultBitmap = FreeImage_Allocate(rImage.width(), rImage.height(), 8 /* bits per pixel */);
|
||||
NPP_ASSERT_NOT_NULL(pResultBitmap);
|
||||
unsigned int nDstPitch = FreeImage_GetPitch(pResultBitmap);
|
||||
Npp8u *pDstLine = FreeImage_GetBits(pResultBitmap) + nDstPitch * (rImage.height()-1);
|
||||
const Npp8u *pSrcLine = rImage.data();
|
||||
unsigned int nSrcPitch = rImage.pitch();
|
||||
|
||||
for (size_t iLine = 0; iLine < rImage.height(); ++iLine)
|
||||
{
|
||||
memcpy(pDstLine, pSrcLine, rImage.width() * sizeof(Npp8u));
|
||||
pSrcLine += nSrcPitch;
|
||||
pDstLine -= nDstPitch;
|
||||
}
|
||||
|
||||
// now save the result image
|
||||
bool bSuccess;
|
||||
bSuccess = FreeImage_Save(FIF_PGM, pResultBitmap, rFileName.c_str(), 0) == TRUE;
|
||||
NPP_ASSERT_MSG(bSuccess, "Failed to save result image.");
|
||||
}
|
||||
|
||||
// Load a gray-scale image from disk.
|
||||
void
|
||||
loadImage(const std::string &rFileName, ImageNPP_8u_C1 &rImage)
|
||||
{
|
||||
ImageCPU_8u_C1 oImage;
|
||||
loadImage(rFileName, oImage);
|
||||
ImageNPP_8u_C1 oResult(oImage);
|
||||
rImage.swap(oResult);
|
||||
}
|
||||
|
||||
// Save an gray-scale image to disk.
|
||||
void
|
||||
saveImage(const std::string &rFileName, const ImageNPP_8u_C1 &rImage)
|
||||
{
|
||||
ImageCPU_8u_C1 oHostImage(rImage.size());
|
||||
// copy the device result data
|
||||
rImage.copyTo(oHostImage.data(), oHostImage.pitch());
|
||||
saveImage(rFileName, oHostImage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // NV_UTIL_NPP_IMAGE_IO_H
|
||||
171
Common/UtilNPP/ImagePacked.h
Normal file
171
Common/UtilNPP/ImagePacked.h
Normal file
@@ -0,0 +1,171 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NV_UTIL_NPP_IMAGE_PACKED_H
|
||||
#define NV_UTIL_NPP_IMAGE_PACKED_H
|
||||
|
||||
#include "Image.h"
|
||||
#include "Pixel.h"
|
||||
|
||||
namespace npp
|
||||
{
|
||||
template<typename D, size_t N, class A>
|
||||
class ImagePacked: public npp::Image
|
||||
{
|
||||
public:
|
||||
typedef npp::Pixel<D, N> tPixel;
|
||||
typedef D tData;
|
||||
static const size_t gnChannels = N;
|
||||
typedef npp::Image::Size tSize;
|
||||
|
||||
ImagePacked(): aPixels_(0)
|
||||
, nPitch_(0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImagePacked(unsigned int nWidth, unsigned int nHeight): Image(nWidth, nHeight)
|
||||
, aPixels_(0)
|
||||
, nPitch_(0)
|
||||
{
|
||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
||||
}
|
||||
|
||||
ImagePacked(unsigned int nWidth, unsigned int nHeight, bool bTight): Image(nWidth, nHeight)
|
||||
, aPixels_(0)
|
||||
, nPitch_(0)
|
||||
{
|
||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_, bTight);
|
||||
}
|
||||
|
||||
ImagePacked(const tSize &rSize): Image(rSize)
|
||||
, aPixels_(0)
|
||||
, nPitch_(0)
|
||||
{
|
||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
||||
}
|
||||
|
||||
ImagePacked(const ImagePacked<D, N, A> &rImage): Image(rImage)
|
||||
, aPixels_(0)
|
||||
, nPitch_(rImage.pitch())
|
||||
{
|
||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
||||
A::Copy2D(aPixels_, nPitch_, rImage.pixels(), rImage.pitch(), width(), height());
|
||||
}
|
||||
|
||||
virtual
|
||||
~ImagePacked()
|
||||
{
|
||||
A::Free2D(aPixels_);
|
||||
}
|
||||
|
||||
ImagePacked &
|
||||
operator= (const ImagePacked<D, N, A> &rImage)
|
||||
{
|
||||
// in case of self-assignment
|
||||
if (&rImage == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
A::Free2D(aPixels_);
|
||||
aPixels_ = 0;
|
||||
nPitch_ = 0;
|
||||
|
||||
// assign parent class's data fields (width, height)
|
||||
Image::operator =(rImage);
|
||||
|
||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
||||
A::Copy2D(aPixels_, nPitch_, rImage.data(), rImage.pitch(), width(), height());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
pitch()
|
||||
const
|
||||
{
|
||||
return nPitch_;
|
||||
}
|
||||
|
||||
/// Get a pointer to the pixel array.
|
||||
/// The result pointer can be offset to pixel at position (x, y) and
|
||||
/// even negative offsets are allowed.
|
||||
/// \param nX Horizontal pointer/array offset.
|
||||
/// \param nY Vertical pointer/array offset.
|
||||
/// \return Pointer to the pixel array (or first pixel in array with coordinates (nX, nY).
|
||||
tPixel *
|
||||
pixels(int nX = 0, int nY = 0)
|
||||
{
|
||||
return reinterpret_cast<tPixel *>(reinterpret_cast<unsigned char *>(aPixels_) + nY * pitch() + nX * gnChannels * sizeof(D));
|
||||
}
|
||||
|
||||
const
|
||||
tPixel *
|
||||
pixels(int nX = 0, int nY = 0)
|
||||
const
|
||||
{
|
||||
return reinterpret_cast<const tPixel *>(reinterpret_cast<unsigned char *>(aPixels_) + nY * pitch() + nX * gnChannels * sizeof(D));
|
||||
}
|
||||
|
||||
D *
|
||||
data(int nX = 0, int nY = 0)
|
||||
{
|
||||
return reinterpret_cast<D *>(pixels(nX, nY));
|
||||
}
|
||||
|
||||
const
|
||||
D *
|
||||
data(int nX = 0, int nY = 0)
|
||||
const
|
||||
{
|
||||
return reinterpret_cast<const D *>(pixels(nX, nY));
|
||||
}
|
||||
|
||||
void
|
||||
swap(ImagePacked<D, N, A> &rImage)
|
||||
{
|
||||
Image::swap(rImage);
|
||||
|
||||
tData *aTemp = aPixels_;
|
||||
aPixels_ = rImage.aPixels_;
|
||||
rImage.aPixels_ = aTemp;
|
||||
|
||||
unsigned int nTemp = nPitch_;
|
||||
nPitch_ = rImage.nPitch_;
|
||||
rImage.nPitch_ = nTemp;
|
||||
}
|
||||
|
||||
private:
|
||||
D *aPixels_;
|
||||
unsigned int nPitch_;
|
||||
};
|
||||
|
||||
} // npp namespace
|
||||
|
||||
|
||||
#endif // NV_IMAGE_IPP_H
|
||||
121
Common/UtilNPP/ImagesCPU.h
Normal file
121
Common/UtilNPP/ImagesCPU.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NV_UTIL_NPP_IMAGES_CPU_H
|
||||
#define NV_UTIL_NPP_IMAGES_CPU_H
|
||||
|
||||
#include "ImagePacked.h"
|
||||
|
||||
#include "ImageAllocatorsCPU.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
#include <npp.h>
|
||||
|
||||
|
||||
namespace npp
|
||||
{
|
||||
|
||||
template<typename D, unsigned int N, class A>
|
||||
class ImageCPU: public npp::ImagePacked<D, N, A>
|
||||
{
|
||||
public:
|
||||
|
||||
ImageCPU()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageCPU(unsigned int nWidth, unsigned int nHeight): ImagePacked<D, N, A>(nWidth, nHeight)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
explicit
|
||||
ImageCPU(const npp::Image::Size &rSize): ImagePacked<D, N, A>(rSize)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageCPU(const ImageCPU<D, N, A> &rImage): Image(rImage)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual
|
||||
~ImageCPU()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageCPU &
|
||||
operator= (const ImageCPU<D, N, A> &rImage)
|
||||
{
|
||||
ImagePacked<D, N, A>::operator= (rImage);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
npp::Pixel<D, N> &
|
||||
operator()(unsigned int iX, unsigned int iY)
|
||||
{
|
||||
return *ImagePacked<D, N, A>::pixels(iX, iY);
|
||||
}
|
||||
|
||||
npp::Pixel<D, N>
|
||||
operator()(unsigned int iX, unsigned int iY)
|
||||
const
|
||||
{
|
||||
return *ImagePacked<D, N, A>::pixels(iX, iY);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
typedef ImageCPU<Npp8u, 1, npp::ImageAllocatorCPU<Npp8u, 1> > ImageCPU_8u_C1;
|
||||
typedef ImageCPU<Npp8u, 2, npp::ImageAllocatorCPU<Npp8u, 2> > ImageCPU_8u_C2;
|
||||
typedef ImageCPU<Npp8u, 3, npp::ImageAllocatorCPU<Npp8u, 3> > ImageCPU_8u_C3;
|
||||
typedef ImageCPU<Npp8u, 4, npp::ImageAllocatorCPU<Npp8u, 4> > ImageCPU_8u_C4;
|
||||
|
||||
typedef ImageCPU<Npp16u, 1, npp::ImageAllocatorCPU<Npp16u, 1> > ImageCPU_16u_C1;
|
||||
typedef ImageCPU<Npp16u, 3, npp::ImageAllocatorCPU<Npp16u, 3> > ImageCPU_16u_C3;
|
||||
typedef ImageCPU<Npp16u, 4, npp::ImageAllocatorCPU<Npp16u, 4> > ImageCPU_16u_C4;
|
||||
|
||||
typedef ImageCPU<Npp16s, 1, npp::ImageAllocatorCPU<Npp16s, 1> > ImageCPU_16s_C1;
|
||||
typedef ImageCPU<Npp16s, 3, npp::ImageAllocatorCPU<Npp16s, 3> > ImageCPU_16s_C3;
|
||||
typedef ImageCPU<Npp16s, 4, npp::ImageAllocatorCPU<Npp16s, 4> > ImageCPU_16s_C4;
|
||||
|
||||
typedef ImageCPU<Npp32s, 1, npp::ImageAllocatorCPU<Npp32s, 1> > ImageCPU_32s_C1;
|
||||
typedef ImageCPU<Npp32s, 3, npp::ImageAllocatorCPU<Npp32s, 3> > ImageCPU_32s_C3;
|
||||
typedef ImageCPU<Npp32s, 4, npp::ImageAllocatorCPU<Npp32s, 4> > ImageCPU_32s_C4;
|
||||
|
||||
typedef ImageCPU<Npp32f, 1, npp::ImageAllocatorCPU<Npp32f, 1> > ImageCPU_32f_C1;
|
||||
typedef ImageCPU<Npp32f, 3, npp::ImageAllocatorCPU<Npp32f, 3> > ImageCPU_32f_C3;
|
||||
typedef ImageCPU<Npp32f, 4, npp::ImageAllocatorCPU<Npp32f, 4> > ImageCPU_32f_C4;
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_IMAGE_IPP_H
|
||||
149
Common/UtilNPP/ImagesNPP.h
Normal file
149
Common/UtilNPP/ImagesNPP.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_NPP_IMAGES_NPP_H
|
||||
#define NV_UTIL_NPP_IMAGES_NPP_H
|
||||
|
||||
#include "Exceptions.h"
|
||||
#include "ImagePacked.h"
|
||||
|
||||
#include "ImageAllocatorsNPP.h"
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
namespace npp
|
||||
{
|
||||
// forward declaration
|
||||
template<typename D, unsigned int N, class A> class ImageCPU;
|
||||
|
||||
template<typename D, unsigned int N>
|
||||
class ImageNPP: public npp::ImagePacked<D, N, npp::ImageAllocator<D, N> >
|
||||
{
|
||||
public:
|
||||
ImageNPP()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageNPP(unsigned int nWidth, unsigned int nHeight, bool bTight = false): ImagePacked<D, N, npp::ImageAllocator<D, N> >(nWidth, nHeight, bTight)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageNPP(const npp::Image::Size &rSize): ImagePacked<D, N, npp::ImageAllocator<D, N> >(rSize)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageNPP(const ImageNPP<D, N> &rImage): Image(rImage)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
template<class X>
|
||||
explicit
|
||||
ImageNPP(const ImageCPU<D, N, X> &rImage, bool bTight = false): ImagePacked<D, N, npp::ImageAllocator<D, N> >(rImage.width(), rImage.height(), bTight)
|
||||
{
|
||||
npp::ImageAllocator<D, N>::HostToDeviceCopy2D(ImagePacked<D, N, npp::ImageAllocator<D, N> >::data(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::pitch(),
|
||||
rImage.data(),
|
||||
rImage.pitch(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::width(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::height());
|
||||
}
|
||||
|
||||
virtual
|
||||
~ImageNPP()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ImageNPP &
|
||||
operator= (const ImageNPP<D, N> &rImage)
|
||||
{
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::operator= (rImage);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
copyTo(D *pData, unsigned int nPitch)
|
||||
const
|
||||
{
|
||||
NPP_ASSERT((ImagePacked<D, N, npp::ImageAllocator<D, N> >::width() * sizeof(npp::Pixel<D, N>) <= nPitch));
|
||||
npp::ImageAllocator<D, N>::DeviceToHostCopy2D(pData,
|
||||
nPitch,
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::data(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::pitch(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::width(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::height());
|
||||
}
|
||||
|
||||
void
|
||||
copyFrom(D *pData, unsigned int nPitch)
|
||||
{
|
||||
NPP_ASSERT((ImagePacked<D, N, npp::ImageAllocator<D, N> >::width() * sizeof(npp::Pixel<D, N>) <= nPitch));
|
||||
npp::ImageAllocator<D, N>::HostToDeviceCopy2D(ImagePacked<D, N, npp::ImageAllocator<D, N> >::data(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::pitch(),
|
||||
pData,
|
||||
nPitch,
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::width(),
|
||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::height());
|
||||
}
|
||||
};
|
||||
|
||||
typedef ImageNPP<Npp8u, 1> ImageNPP_8u_C1;
|
||||
typedef ImageNPP<Npp8u, 2> ImageNPP_8u_C2;
|
||||
typedef ImageNPP<Npp8u, 3> ImageNPP_8u_C3;
|
||||
typedef ImageNPP<Npp8u, 4> ImageNPP_8u_C4;
|
||||
|
||||
typedef ImageNPP<Npp16u, 1> ImageNPP_16u_C1;
|
||||
typedef ImageNPP<Npp16u, 2> ImageNPP_16u_C2;
|
||||
typedef ImageNPP<Npp16u, 3> ImageNPP_16u_C3;
|
||||
typedef ImageNPP<Npp16u, 4> ImageNPP_16u_C4;
|
||||
|
||||
typedef ImageNPP<Npp16s, 1> ImageNPP_16s_C1;
|
||||
typedef ImageNPP<Npp16s, 3> ImageNPP_16s_C3;
|
||||
typedef ImageNPP<Npp16s, 4> ImageNPP_16s_C4;
|
||||
|
||||
typedef ImageNPP<Npp32s, 1> ImageNPP_32s_C1;
|
||||
typedef ImageNPP<Npp32s, 3> ImageNPP_32s_C3;
|
||||
typedef ImageNPP<Npp32s, 4> ImageNPP_32s_C4;
|
||||
|
||||
typedef ImageNPP<Npp32f, 1> ImageNPP_32f_C1;
|
||||
typedef ImageNPP<Npp32f, 2> ImageNPP_32f_C2;
|
||||
typedef ImageNPP<Npp32f, 3> ImageNPP_32f_C3;
|
||||
typedef ImageNPP<Npp32f, 4> ImageNPP_32f_C4;
|
||||
|
||||
typedef ImageNPP<Npp64f, 1> ImageNPP_64f_C1;
|
||||
typedef ImageNPP<Npp64f, 2> ImageNPP_64f_C2;
|
||||
typedef ImageNPP<Npp64f, 3> ImageNPP_64f_C3;
|
||||
typedef ImageNPP<Npp64f, 4> ImageNPP_64f_C4;
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_IMAGES_NPP_H
|
||||
126
Common/UtilNPP/Pixel.h
Normal file
126
Common/UtilNPP/Pixel.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_PIXEL_H
|
||||
#define NV_UTIL_PIXEL_H
|
||||
|
||||
#include "Exceptions.h"
|
||||
|
||||
namespace npp
|
||||
{
|
||||
template <typename D, size_t N>
|
||||
struct Pixel
|
||||
{ };
|
||||
|
||||
template <typename D>
|
||||
struct Pixel<D, 1>
|
||||
{
|
||||
D x;
|
||||
|
||||
const D &
|
||||
operator[](size_t iChannel)
|
||||
const
|
||||
{
|
||||
NPP_ASSERT(iChannel < 1);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
|
||||
D &
|
||||
operator[](size_t iChannel)
|
||||
{
|
||||
NPP_ASSERT(iChannel < 1);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
};
|
||||
|
||||
template <typename D>
|
||||
struct Pixel<D, 2>
|
||||
{
|
||||
D x,y;
|
||||
|
||||
const D &
|
||||
operator[](size_t iChannel)
|
||||
const
|
||||
{
|
||||
NPP_ASSERT(iChannel < 2);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
|
||||
D &
|
||||
operator[](size_t iChannel)
|
||||
{
|
||||
NPP_ASSERT(iChannel < 2);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
};
|
||||
|
||||
template <typename D>
|
||||
struct Pixel<D, 3>
|
||||
{
|
||||
D x,y,z;
|
||||
|
||||
const D &
|
||||
operator[](size_t iChannel)
|
||||
const
|
||||
{
|
||||
NPP_ASSERT(iChannel < 3);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
|
||||
D &
|
||||
operator[](size_t iChannel)
|
||||
{
|
||||
NPP_ASSERT(iChannel < 3);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
};
|
||||
|
||||
template <typename D>
|
||||
struct Pixel<D, 4>
|
||||
{
|
||||
D x, y, z, w;
|
||||
|
||||
const D &
|
||||
operator[](size_t iChannel)
|
||||
const
|
||||
{
|
||||
NPP_ASSERT(iChannel < 4);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
|
||||
D &
|
||||
operator[](size_t iChannel)
|
||||
{
|
||||
NPP_ASSERT(iChannel < 4);
|
||||
return (&x)[iChannel];
|
||||
}
|
||||
};
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_PIXEL_H
|
||||
168
Common/UtilNPP/Signal.h
Normal file
168
Common/UtilNPP/Signal.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_NPP_SIGNAL_H
|
||||
#define NV_UTIL_NPP_SIGNAL_H
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace npp
|
||||
{
|
||||
class Signal
|
||||
{
|
||||
public:
|
||||
Signal() : nSize_(0)
|
||||
{ };
|
||||
|
||||
explicit
|
||||
Signal(size_t nSize) : nSize_(nSize)
|
||||
{ };
|
||||
|
||||
Signal(const Signal &rSignal) : nSize_(rSignal.nSize_)
|
||||
{ };
|
||||
|
||||
virtual
|
||||
~Signal()
|
||||
{ }
|
||||
|
||||
Signal &
|
||||
operator= (const Signal &rSignal)
|
||||
{
|
||||
nSize_ = rSignal.nSize_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
size_t
|
||||
size()
|
||||
const
|
||||
{
|
||||
return nSize_;
|
||||
}
|
||||
|
||||
void
|
||||
swap(Signal &rSignal)
|
||||
{
|
||||
size_t nTemp = nSize_;
|
||||
nSize_ = rSignal.nSize_;
|
||||
rSignal.nSize_ = nTemp;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
size_t nSize_;
|
||||
};
|
||||
|
||||
template<typename D, class A>
|
||||
class SignalTemplate: public Signal
|
||||
{
|
||||
public:
|
||||
typedef D tData;
|
||||
|
||||
SignalTemplate(): aValues_(0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SignalTemplate(size_t nSize): Signal(nSize)
|
||||
, aValues_(0)
|
||||
{
|
||||
aValues_ = A::Malloc1D(size());
|
||||
}
|
||||
|
||||
SignalTemplate(const SignalTemplate<D, A> &rSignal): Signal(rSignal)
|
||||
, aValues_(0)
|
||||
{
|
||||
aValues_ = A::Malloc1D(size());
|
||||
A::Copy1D(aValues_, rSignal.values(), size());
|
||||
}
|
||||
|
||||
virtual
|
||||
~SignalTemplate()
|
||||
{
|
||||
A::Free1D(aValues_);
|
||||
}
|
||||
|
||||
SignalTemplate &
|
||||
operator= (const SignalTemplate<D, A> &rSignal)
|
||||
{
|
||||
// in case of self-assignment
|
||||
if (&rSignal == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
A::Free1D(aValues_);
|
||||
this->aPixels_ = 0;
|
||||
|
||||
// assign parent class's data fields (width, height)
|
||||
Signal::operator =(rSignal);
|
||||
|
||||
aValues_ = A::Malloc1D(size());
|
||||
A::Copy1D(aValues_, rSignal.value(), size());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get a pointer to the pixel array.
|
||||
/// The result pointer can be offset to pixel at position (x, y) and
|
||||
/// even negative offsets are allowed.
|
||||
/// \param nX Horizontal pointer/array offset.
|
||||
/// \param nY Vertical pointer/array offset.
|
||||
/// \return Pointer to the pixel array (or first pixel in array with coordinates (nX, nY).
|
||||
tData *
|
||||
values(int i = 0)
|
||||
{
|
||||
return aValues_ + i;
|
||||
}
|
||||
|
||||
const
|
||||
tData *
|
||||
values(int i = 0)
|
||||
const
|
||||
{
|
||||
return aValues_ + i;
|
||||
}
|
||||
|
||||
void
|
||||
swap(SignalTemplate<D, A> &rSignal)
|
||||
{
|
||||
Signal::swap(rSignal);
|
||||
|
||||
tData *aTemp = this->aValues_;
|
||||
this->aValues_ = rSignal.aValues_;
|
||||
rSignal.aValues_ = aTemp;
|
||||
}
|
||||
|
||||
private:
|
||||
D *aValues_;
|
||||
};
|
||||
|
||||
} // npp namespace
|
||||
|
||||
|
||||
#endif // NV_UTIL_NPP_SIGNAL_H
|
||||
66
Common/UtilNPP/SignalAllocatorsCPU.h
Normal file
66
Common/UtilNPP/SignalAllocatorsCPU.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_NPP_SIGNAL_ALLOCATORS_CPU_H
|
||||
#define NV_UTIL_NPP_SIGNAL_ALLOCATORS_CPU_H
|
||||
|
||||
#include "Exceptions.h"
|
||||
|
||||
namespace npp
|
||||
{
|
||||
|
||||
template <typename D>
|
||||
class SignalAllocatorCPU
|
||||
{
|
||||
public:
|
||||
static
|
||||
D *
|
||||
Malloc1D(unsigned int nSize)
|
||||
{
|
||||
return new D[nSize];;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(D *pPixels)
|
||||
{
|
||||
delete[] pPixels;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(D *pDst, const D *pSrc, size_t nSize)
|
||||
{
|
||||
memcpy(pDst, pSrc, nSize * sizeof(D));
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_SIGNAL_ALLOCATORS_CPU_H
|
||||
684
Common/UtilNPP/SignalAllocatorsNPP.h
Normal file
684
Common/UtilNPP/SignalAllocatorsNPP.h
Normal file
@@ -0,0 +1,684 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_NPP_SIGNAL_ALLOCATORS_NPP_H
|
||||
#define NV_UTIL_NPP_SIGNAL_ALLOCATORS_NPP_H
|
||||
|
||||
|
||||
#include "Exceptions.h"
|
||||
|
||||
#include <npps.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
namespace npp
|
||||
{
|
||||
|
||||
template <typename D>
|
||||
class SignalAllocator
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp8u>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp8u *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp8u *pResult = nppsMalloc_8u(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp8u *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp8u *pDst, const Npp8u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp8u),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp8u *pDst, const Npp8u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp8u), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp8u *pDst, const Npp8u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp8u), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp16s>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp16s *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp16s *pResult = nppsMalloc_16s(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp16s *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp16s *pDst, const Npp16s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16s),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp16s *pDst, const Npp16s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16s), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp16s *pDst, const Npp16s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16s), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp16u>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp16u *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp16u *pResult = nppsMalloc_16u(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp16u *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp16u *pDst, const Npp16u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16u),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp16u *pDst, const Npp16u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16u), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp16u *pDst, const Npp16u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16u), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp16sc>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp16sc *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp16sc *pResult = nppsMalloc_16sc(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp16sc *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp16sc *pDst, const Npp16sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16sc),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp16sc *pDst, const Npp16sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16sc), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp16sc *pDst, const Npp16sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16sc), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp32u>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp32u *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp32u *pResult = nppsMalloc_32u(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp32u *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp32u *pDst, const Npp32u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32u),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp32u *pDst, const Npp32u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32u), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp32u *pDst, const Npp32u *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32u), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp32s>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp32s *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp32s *pResult = nppsMalloc_32s(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp32s *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp32s *pDst, const Npp32s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32s),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp32s *pDst, const Npp32s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32s), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp32s *pDst, const Npp32s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32s), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp32sc>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp32sc *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp32sc *pResult = nppsMalloc_32sc(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp32sc *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp32sc *pDst, const Npp32sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32sc),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp32sc *pDst, const Npp32sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32sc), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp32sc *pDst, const Npp32sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32sc), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp32f>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp32f *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp32f *pResult = nppsMalloc_32f(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp32f *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp32f *pDst, const Npp32f *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32f),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp32f *pDst, const Npp32f *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32f), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp32f *pDst, const Npp32f *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32f), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp32fc>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp32fc *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp32fc *pResult = nppsMalloc_32fc(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp32fc *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp32fc *pDst, const Npp32fc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32fc),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp32fc *pDst, const Npp32fc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32fc), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp32fc *pDst, const Npp32fc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32fc), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp64s>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp64s *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp64s *pResult = nppsMalloc_64s(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp64s *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp64s *pDst, const Npp64s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64s),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp64s *pDst, const Npp64s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64s), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp64s *pDst, const Npp64s *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64s), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp64sc>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp64sc *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp64sc *pResult = nppsMalloc_64sc(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp64sc *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp64sc *pDst, const Npp64sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64sc),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp64sc *pDst, const Npp64sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64sc), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp64sc *pDst, const Npp64sc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64sc), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp64f>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp64f *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp64f *pResult = nppsMalloc_64f(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp64f *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp64f *pDst, const Npp64f *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64f),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp64f *pDst, const Npp64f *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64f), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp64f *pDst, const Npp64f *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64f), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class SignalAllocator<Npp64fc>
|
||||
{
|
||||
public:
|
||||
static
|
||||
Npp64fc *
|
||||
Malloc1D(size_t nSize)
|
||||
{
|
||||
Npp64fc *pResult = nppsMalloc_64fc(static_cast<int>(nSize));
|
||||
NPP_ASSERT(pResult != 0);
|
||||
|
||||
return pResult;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Free1D(Npp64fc *pValues)
|
||||
{
|
||||
nppsFree(pValues);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
Copy1D(Npp64fc *pDst, const Npp64fc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64fc),cudaMemcpyDeviceToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
HostToDeviceCopy1D(Npp64fc *pDst, const Npp64fc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64fc), cudaMemcpyHostToDevice);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
DeviceToHostCopy1D(Npp64fc *pDst, const Npp64fc *pSrc, size_t nSize)
|
||||
{
|
||||
cudaError_t eResult;
|
||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64fc), cudaMemcpyDeviceToHost);
|
||||
NPP_ASSERT(cudaSuccess == eResult);
|
||||
};
|
||||
};
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_SIGNAL_ALLOCATORS_NPP_H
|
||||
107
Common/UtilNPP/SignalsCPU.h
Normal file
107
Common/UtilNPP/SignalsCPU.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_NPP_SIGNALS_CPU_H
|
||||
#define NV_UTIL_NPP_SIGNALS_CPU_H
|
||||
|
||||
#include "Signal.h"
|
||||
|
||||
#include "SignalAllocatorsCPU.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
#include <npp.h>
|
||||
|
||||
|
||||
namespace npp
|
||||
{
|
||||
|
||||
template<typename D, class A>
|
||||
class SignalCPU: public npp::SignalTemplate<D, A>
|
||||
{
|
||||
public:
|
||||
typedef typename npp::SignalTemplate<D, A>::tData tData;
|
||||
|
||||
SignalCPU()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SignalCPU(size_t nSize): SignalTemplate<D, A>(nSize)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SignalCPU(const SignalCPU<D, A> &rSignal): SignalTemplate<D, A>(rSignal)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual
|
||||
~SignalCPU()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SignalCPU &
|
||||
operator= (const SignalCPU<D,A> &rSignal)
|
||||
{
|
||||
SignalTemplate<D, A>::operator= (rSignal);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
tData &
|
||||
operator [](unsigned int i)
|
||||
{
|
||||
return *SignalTemplate<D, A>::values(i);
|
||||
}
|
||||
|
||||
tData
|
||||
operator [](unsigned int i)
|
||||
const
|
||||
{
|
||||
return *SignalTemplate<D, A>::values(i);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef SignalCPU<Npp8u, npp::SignalAllocatorCPU<Npp8u> > SignalCPU_8u;
|
||||
typedef SignalCPU<Npp32s, npp::SignalAllocatorCPU<Npp32s> > SignalCPU_32s;
|
||||
typedef SignalCPU<Npp16s, npp::SignalAllocatorCPU<Npp16s> > SignalCPU_16s;
|
||||
typedef SignalCPU<Npp16sc, npp::SignalAllocatorCPU<Npp16sc> > SignalCPU_16sc;
|
||||
typedef SignalCPU<Npp32sc, npp::SignalAllocatorCPU<Npp32sc> > SignalCPU_32sc;
|
||||
typedef SignalCPU<Npp32f, npp::SignalAllocatorCPU<Npp32f> > SignalCPU_32f;
|
||||
typedef SignalCPU<Npp32fc, npp::SignalAllocatorCPU<Npp32fc> > SignalCPU_32fc;
|
||||
typedef SignalCPU<Npp64s, npp::SignalAllocatorCPU<Npp64s> > SignalCPU_64s;
|
||||
typedef SignalCPU<Npp64sc, npp::SignalAllocatorCPU<Npp64sc> > SignalCPU_64sc;
|
||||
typedef SignalCPU<Npp64f, npp::SignalAllocatorCPU<Npp64f> > SignalCPU_64f;
|
||||
typedef SignalCPU<Npp64fc, npp::SignalAllocatorCPU<Npp64fc> > SignalCPU_64fc;
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_SIGNALS_CPU_H
|
||||
113
Common/UtilNPP/SignalsNPP.h
Normal file
113
Common/UtilNPP/SignalsNPP.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_UTIL_NPP_SIGNALS_NPP_H
|
||||
#define NV_UTIL_NPP_SIGNALS_NPP_H
|
||||
|
||||
#include "Exceptions.h"
|
||||
#include "Signal.h"
|
||||
|
||||
#include "SignalAllocatorsNPP.h"
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
namespace npp
|
||||
{
|
||||
// forward declaration
|
||||
template<typename D, class A> class SignalCPU;
|
||||
|
||||
template<typename D>
|
||||
class SignalNPP: public npp::SignalTemplate<D, npp::SignalAllocator<D> >
|
||||
{
|
||||
public:
|
||||
SignalNPP()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
explicit
|
||||
SignalNPP(size_t nSize): SignalTemplate<D, npp::SignalAllocator<D> >(nSize)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SignalNPP(const SignalNPP<D> &rSignal): SignalTemplate<D, npp::SignalAllocator<D> >(rSignal)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
template<class X>
|
||||
explicit
|
||||
SignalNPP(const SignalCPU<D, X> &rSignal): SignalTemplate<D, npp::SignalAllocator<D> >(rSignal.size())
|
||||
{
|
||||
npp::SignalAllocator<D>::HostToDeviceCopy1D(SignalTemplate<D, npp::SignalAllocator<D> >::values(),
|
||||
rSignal.values(), SignalTemplate<D, npp::SignalAllocator<D> >::size());
|
||||
}
|
||||
|
||||
virtual
|
||||
~SignalNPP()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SignalNPP &
|
||||
operator= (const SignalNPP<D> &rSignal)
|
||||
{
|
||||
SignalTemplate<D, npp::SignalAllocator<D> >::operator= (rSignal);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
copyTo(D *pValues)
|
||||
const
|
||||
{
|
||||
npp::SignalAllocator<D>::DeviceToHostCopy1D(pValues, SignalTemplate<D, npp::SignalAllocator<D> >::values(), SignalTemplate<D, npp::SignalAllocator<D> >::size());
|
||||
}
|
||||
|
||||
void
|
||||
copyFrom(D *pValues)
|
||||
{
|
||||
npp::SignalAllocator<D>::HostToDeviceCopy1D(SignalTemplate<D, npp::SignalAllocator<D> >::values(), pValues, SignalTemplate<D, npp::SignalAllocator<D> >::size());
|
||||
}
|
||||
};
|
||||
|
||||
typedef SignalNPP<Npp8u> SignalNPP_8u;
|
||||
typedef SignalNPP<Npp16s> SignalNPP_16s;
|
||||
typedef SignalNPP<Npp16sc> SignalNPP_16sc;
|
||||
typedef SignalNPP<Npp32s> SignalNPP_32s;
|
||||
typedef SignalNPP<Npp32sc> SignalNPP_32sc;
|
||||
typedef SignalNPP<Npp32f> SignalNPP_32f;
|
||||
typedef SignalNPP<Npp32fc> SignalNPP_32fc;
|
||||
typedef SignalNPP<Npp64s> SignalNPP_64s;
|
||||
typedef SignalNPP<Npp64sc> SignalNPP_64sc;
|
||||
typedef SignalNPP<Npp64f> SignalNPP_64f;
|
||||
typedef SignalNPP<Npp64fc> SignalNPP_64fc;
|
||||
|
||||
} // npp namespace
|
||||
|
||||
#endif // NV_UTIL_NPP_SIGNALS_NPP_H
|
||||
Reference in New Issue
Block a user