mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-26 06:38:16 +08:00
Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.
This commit is contained in:
@@ -34,11 +34,12 @@
|
||||
* conversions to different representations and memory management routines.
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "BmpUtil.h"
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
#pragma warning(disable : 4996) // disable deprecated warning
|
||||
#pragma warning(disable : 4996) // disable deprecated warning
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -59,11 +60,12 @@ int clamp_0_255(int x) { return (x < 0) ? 0 : ((x > 255) ? 255 : x); }
|
||||
*
|
||||
* \return The closest to the input float integer value
|
||||
*/
|
||||
float round_f(float num) {
|
||||
float NumAbs = fabs(num);
|
||||
int NumAbsI = (int)(NumAbs + 0.5f);
|
||||
float sign = num > 0 ? 1.0f : -1.0f;
|
||||
return sign * NumAbsI;
|
||||
float round_f(float num)
|
||||
{
|
||||
float NumAbs = fabs(num);
|
||||
int NumAbsI = (int)(NumAbs + 0.5f);
|
||||
float sign = num > 0 ? 1.0f : -1.0f;
|
||||
return sign * NumAbsI;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,15 +78,16 @@ float round_f(float num) {
|
||||
*
|
||||
* \return Pointer to the created plane
|
||||
*/
|
||||
byte *MallocPlaneByte(int width, int height, int *pStepBytes) {
|
||||
byte *ptr;
|
||||
*pStepBytes = ((int)ceil(width / 16.0f)) * 16;
|
||||
//#ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// ptr = (byte *)_aligned_malloc(*pStepBytes * height, 16);
|
||||
//#else
|
||||
ptr = (byte *)malloc(*pStepBytes * height);
|
||||
//#endif
|
||||
return ptr;
|
||||
byte *MallocPlaneByte(int width, int height, int *pStepBytes)
|
||||
{
|
||||
byte *ptr;
|
||||
*pStepBytes = ((int)ceil(width / 16.0f)) * 16;
|
||||
// #ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// ptr = (byte *)_aligned_malloc(*pStepBytes * height, 16);
|
||||
// #else
|
||||
ptr = (byte *)malloc(*pStepBytes * height);
|
||||
// #endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,16 +100,17 @@ byte *MallocPlaneByte(int width, int height, int *pStepBytes) {
|
||||
*
|
||||
* \return Pointer to the created plane
|
||||
*/
|
||||
short *MallocPlaneShort(int width, int height, int *pStepBytes) {
|
||||
short *ptr;
|
||||
*pStepBytes = ((int)ceil((width * sizeof(short)) / 16.0f)) * 16;
|
||||
//#ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// ptr = (float *)_aligned_malloc(*pStepBytes * height, 16);
|
||||
//#else
|
||||
ptr = (short *)malloc(*pStepBytes * height);
|
||||
//#endif
|
||||
*pStepBytes = *pStepBytes / sizeof(short);
|
||||
return ptr;
|
||||
short *MallocPlaneShort(int width, int height, int *pStepBytes)
|
||||
{
|
||||
short *ptr;
|
||||
*pStepBytes = ((int)ceil((width * sizeof(short)) / 16.0f)) * 16;
|
||||
// #ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// ptr = (float *)_aligned_malloc(*pStepBytes * height, 16);
|
||||
// #else
|
||||
ptr = (short *)malloc(*pStepBytes * height);
|
||||
// #endif
|
||||
*pStepBytes = *pStepBytes / sizeof(short);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,16 +123,17 @@ short *MallocPlaneShort(int width, int height, int *pStepBytes) {
|
||||
*
|
||||
* \return Pointer to the created plane
|
||||
*/
|
||||
float *MallocPlaneFloat(int width, int height, int *pStepBytes) {
|
||||
float *ptr;
|
||||
*pStepBytes = ((int)ceil((width * sizeof(float)) / 16.0f)) * 16;
|
||||
//#ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// ptr = (float *)_aligned_malloc(*pStepBytes * height, 16);
|
||||
//#else
|
||||
ptr = (float *)malloc(*pStepBytes * height);
|
||||
//#endif
|
||||
*pStepBytes = *pStepBytes / sizeof(float);
|
||||
return ptr;
|
||||
float *MallocPlaneFloat(int width, int height, int *pStepBytes)
|
||||
{
|
||||
float *ptr;
|
||||
*pStepBytes = ((int)ceil((width * sizeof(float)) / 16.0f)) * 16;
|
||||
// #ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// ptr = (float *)_aligned_malloc(*pStepBytes * height, 16);
|
||||
// #else
|
||||
ptr = (float *)malloc(*pStepBytes * height);
|
||||
// #endif
|
||||
*pStepBytes = *pStepBytes / sizeof(float);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,13 +148,13 @@ float *MallocPlaneFloat(int width, int height, int *pStepBytes) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void CopyByte2Float(byte *ImgSrc, int StrideB, float *ImgDst, int StrideF,
|
||||
ROI Size) {
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgDst[i * StrideF + j] = (float)ImgSrc[i * StrideB + j];
|
||||
void CopyByte2Float(byte *ImgSrc, int StrideB, float *ImgDst, int StrideF, ROI Size)
|
||||
{
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgDst[i * StrideF + j] = (float)ImgSrc[i * StrideB + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,14 +169,13 @@ void CopyByte2Float(byte *ImgSrc, int StrideB, float *ImgDst, int StrideF,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB,
|
||||
ROI Size) {
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgDst[i * StrideB + j] =
|
||||
(byte)clamp_0_255((int)(round_f(ImgSrc[i * StrideF + j])));
|
||||
void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB, ROI Size)
|
||||
{
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgDst[i * StrideB + j] = (byte)clamp_0_255((int)(round_f(ImgSrc[i * StrideF + j])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,18 +186,19 @@ void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void FreePlane(void *ptr) {
|
||||
//#ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// if (ptr)
|
||||
// {
|
||||
// _aligned_free(ptr);
|
||||
// }
|
||||
//#else
|
||||
if (ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
void FreePlane(void *ptr)
|
||||
{
|
||||
// #ifdef __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
// if (ptr)
|
||||
// {
|
||||
// _aligned_free(ptr);
|
||||
// }
|
||||
// #else
|
||||
if (ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
//#endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,12 +212,13 @@ void FreePlane(void *ptr) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void AddFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size) {
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgSrcDst[i * StrideF + j] += Value;
|
||||
void AddFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size)
|
||||
{
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgSrcDst[i * StrideF + j] += Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,12 +232,13 @@ void AddFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void MulFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size) {
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgSrcDst[i * StrideF + j] *= Value;
|
||||
void MulFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size)
|
||||
{
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
ImgSrcDst[i * StrideF + j] *= Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,36 +251,37 @@ void MulFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size) {
|
||||
*
|
||||
* \return Status code
|
||||
*/
|
||||
int PreLoadBmp(char *FileName, int *Width, int *Height) {
|
||||
BMPFileHeader FileHeader;
|
||||
BMPInfoHeader InfoHeader;
|
||||
FILE *fh;
|
||||
int PreLoadBmp(char *FileName, int *Width, int *Height)
|
||||
{
|
||||
BMPFileHeader FileHeader;
|
||||
BMPInfoHeader InfoHeader;
|
||||
FILE *fh;
|
||||
|
||||
if (!(fh = fopen(FileName, "rb"))) {
|
||||
return 1; // invalid filename
|
||||
}
|
||||
if (!(fh = fopen(FileName, "rb"))) {
|
||||
return 1; // invalid filename
|
||||
}
|
||||
|
||||
fread(&FileHeader, sizeof(BMPFileHeader), 1, fh);
|
||||
fread(&FileHeader, sizeof(BMPFileHeader), 1, fh);
|
||||
|
||||
if (FileHeader._bm_signature != 0x4D42) {
|
||||
return 2; // invalid file format
|
||||
}
|
||||
if (FileHeader._bm_signature != 0x4D42) {
|
||||
return 2; // invalid file format
|
||||
}
|
||||
|
||||
fread(&InfoHeader, sizeof(BMPInfoHeader), 1, fh);
|
||||
fread(&InfoHeader, sizeof(BMPInfoHeader), 1, fh);
|
||||
|
||||
if (InfoHeader._bm_color_depth != 24) {
|
||||
return 3; // invalid color depth
|
||||
}
|
||||
if (InfoHeader._bm_color_depth != 24) {
|
||||
return 3; // invalid color depth
|
||||
}
|
||||
|
||||
if (InfoHeader._bm_compressed) {
|
||||
return 4; // invalid compression property
|
||||
}
|
||||
if (InfoHeader._bm_compressed) {
|
||||
return 4; // invalid compression property
|
||||
}
|
||||
|
||||
*Width = InfoHeader._bm_image_width;
|
||||
*Height = InfoHeader._bm_image_height;
|
||||
*Width = InfoHeader._bm_image_width;
|
||||
*Height = InfoHeader._bm_image_height;
|
||||
|
||||
fclose(fh);
|
||||
return 0;
|
||||
fclose(fh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,28 +295,29 @@ int PreLoadBmp(char *FileName, int *Width, int *Height) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void LoadBmpAsGray(char *FileName, int Stride, ROI ImSize, byte *Img) {
|
||||
BMPFileHeader FileHeader;
|
||||
BMPInfoHeader InfoHeader;
|
||||
FILE *fh;
|
||||
fh = fopen(FileName, "rb");
|
||||
void LoadBmpAsGray(char *FileName, int Stride, ROI ImSize, byte *Img)
|
||||
{
|
||||
BMPFileHeader FileHeader;
|
||||
BMPInfoHeader InfoHeader;
|
||||
FILE *fh;
|
||||
fh = fopen(FileName, "rb");
|
||||
|
||||
fread(&FileHeader, sizeof(BMPFileHeader), 1, fh);
|
||||
fread(&InfoHeader, sizeof(BMPInfoHeader), 1, fh);
|
||||
fread(&FileHeader, sizeof(BMPFileHeader), 1, fh);
|
||||
fread(&InfoHeader, sizeof(BMPInfoHeader), 1, fh);
|
||||
|
||||
for (int i = ImSize.height - 1; i >= 0; i--) {
|
||||
for (int j = 0; j < ImSize.width; j++) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
fread(&b, 1, 1, fh);
|
||||
fread(&g, 1, 1, fh);
|
||||
fread(&r, 1, 1, fh);
|
||||
int val = (313524 * r + 615514 * g + 119537 * b + 524288) >> 20;
|
||||
Img[i * Stride + j] = (byte)clamp_0_255(val);
|
||||
for (int i = ImSize.height - 1; i >= 0; i--) {
|
||||
for (int j = 0; j < ImSize.width; j++) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
fread(&b, 1, 1, fh);
|
||||
fread(&g, 1, 1, fh);
|
||||
fread(&r, 1, 1, fh);
|
||||
int val = (313524 * r + 615514 * g + 119537 * b + 524288) >> 20;
|
||||
Img[i * Stride + j] = (byte)clamp_0_255(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fh);
|
||||
return;
|
||||
fclose(fh);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,46 +331,47 @@ void LoadBmpAsGray(char *FileName, int Stride, ROI ImSize, byte *Img) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void DumpBmpAsGray(char *FileName, byte *Img, int Stride, ROI ImSize) {
|
||||
FILE *fp = NULL;
|
||||
fp = fopen(FileName, "wb");
|
||||
void DumpBmpAsGray(char *FileName, byte *Img, int Stride, ROI ImSize)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
fp = fopen(FileName, "wb");
|
||||
|
||||
if (fp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
BMPFileHeader FileHeader;
|
||||
BMPInfoHeader InfoHeader;
|
||||
|
||||
// init headers
|
||||
FileHeader._bm_signature = 0x4D42;
|
||||
FileHeader._bm_file_size = 54 + 3 * ImSize.width * ImSize.height;
|
||||
FileHeader._bm_reserved = 0;
|
||||
FileHeader._bm_bitmap_data = 0x36;
|
||||
InfoHeader._bm_bitmap_size = 0;
|
||||
InfoHeader._bm_color_depth = 24;
|
||||
InfoHeader._bm_compressed = 0;
|
||||
InfoHeader._bm_hor_resolution = 0;
|
||||
InfoHeader._bm_image_height = ImSize.height;
|
||||
InfoHeader._bm_image_width = ImSize.width;
|
||||
InfoHeader._bm_info_header_size = 40;
|
||||
InfoHeader._bm_num_colors_used = 0;
|
||||
InfoHeader._bm_num_important_colors = 0;
|
||||
InfoHeader._bm_num_of_planes = 1;
|
||||
InfoHeader._bm_ver_resolution = 0;
|
||||
|
||||
fwrite(&FileHeader, sizeof(BMPFileHeader), 1, fp);
|
||||
fwrite(&InfoHeader, sizeof(BMPInfoHeader), 1, fp);
|
||||
|
||||
for (int i = ImSize.height - 1; i >= 0; i--) {
|
||||
for (int j = 0; j < ImSize.width; j++) {
|
||||
fwrite(&(Img[i * Stride + j]), 1, 1, fp);
|
||||
fwrite(&(Img[i * Stride + j]), 1, 1, fp);
|
||||
fwrite(&(Img[i * Stride + j]), 1, 1, fp);
|
||||
if (fp == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
BMPFileHeader FileHeader;
|
||||
BMPInfoHeader InfoHeader;
|
||||
|
||||
// init headers
|
||||
FileHeader._bm_signature = 0x4D42;
|
||||
FileHeader._bm_file_size = 54 + 3 * ImSize.width * ImSize.height;
|
||||
FileHeader._bm_reserved = 0;
|
||||
FileHeader._bm_bitmap_data = 0x36;
|
||||
InfoHeader._bm_bitmap_size = 0;
|
||||
InfoHeader._bm_color_depth = 24;
|
||||
InfoHeader._bm_compressed = 0;
|
||||
InfoHeader._bm_hor_resolution = 0;
|
||||
InfoHeader._bm_image_height = ImSize.height;
|
||||
InfoHeader._bm_image_width = ImSize.width;
|
||||
InfoHeader._bm_info_header_size = 40;
|
||||
InfoHeader._bm_num_colors_used = 0;
|
||||
InfoHeader._bm_num_important_colors = 0;
|
||||
InfoHeader._bm_num_of_planes = 1;
|
||||
InfoHeader._bm_ver_resolution = 0;
|
||||
|
||||
fwrite(&FileHeader, sizeof(BMPFileHeader), 1, fp);
|
||||
fwrite(&InfoHeader, sizeof(BMPInfoHeader), 1, fp);
|
||||
|
||||
for (int i = ImSize.height - 1; i >= 0; i--) {
|
||||
for (int j = 0; j < ImSize.width; j++) {
|
||||
fwrite(&(Img[i * Stride + j]), 1, 1, fp);
|
||||
fwrite(&(Img[i * Stride + j]), 1, 1, fp);
|
||||
fwrite(&(Img[i * Stride + j]), 1, 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,18 +384,19 @@ void DumpBmpAsGray(char *FileName, byte *Img, int Stride, ROI ImSize) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void DumpBlockF(float *PlaneF, int StrideF, char *Fname) {
|
||||
FILE *fp = fopen(Fname, "wb");
|
||||
void DumpBlockF(float *PlaneF, int StrideF, char *Fname)
|
||||
{
|
||||
FILE *fp = fopen(Fname, "wb");
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
fprintf(fp, "%.*f ", 14, PlaneF[i * StrideF + j]);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
fprintf(fp, "%.*f ", 14, PlaneF[i * StrideF + j]);
|
||||
}
|
||||
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,18 +409,19 @@ void DumpBlockF(float *PlaneF, int StrideF, char *Fname) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void DumpBlock(byte *Plane, int Stride, char *Fname) {
|
||||
FILE *fp = fopen(Fname, "wb");
|
||||
void DumpBlock(byte *Plane, int Stride, char *Fname)
|
||||
{
|
||||
FILE *fp = fopen(Fname, "wb");
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
fprintf(fp, "%.3d ", Plane[i * Stride + j]);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
fprintf(fp, "%.3d ", Plane[i * Stride + j]);
|
||||
}
|
||||
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,18 +435,19 @@ void DumpBlock(byte *Plane, int Stride, char *Fname) {
|
||||
*
|
||||
* \return Mean Square Error between images
|
||||
*/
|
||||
float CalculateMSE(byte *Img1, byte *Img2, int Stride, ROI Size) {
|
||||
uint32 Acc = 0;
|
||||
float CalculateMSE(byte *Img1, byte *Img2, int Stride, ROI Size)
|
||||
{
|
||||
uint32 Acc = 0;
|
||||
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
int TmpDiff = Img1[i * Stride + j] - Img2[i * Stride + j];
|
||||
TmpDiff *= TmpDiff;
|
||||
Acc += TmpDiff;
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
int TmpDiff = Img1[i * Stride + j] - Img2[i * Stride + j];
|
||||
TmpDiff *= TmpDiff;
|
||||
Acc += TmpDiff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ((float)Acc) / (Size.height * Size.width);
|
||||
return ((float)Acc) / (Size.height * Size.width);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -449,7 +462,8 @@ float CalculateMSE(byte *Img1, byte *Img2, int Stride, ROI Size) {
|
||||
*
|
||||
* \return Peak Signal to Noise Ratio between images
|
||||
*/
|
||||
float CalculatePSNR(byte *Img1, byte *Img2, int Stride, ROI Size) {
|
||||
float MSE = CalculateMSE(Img1, Img2, Stride, Size);
|
||||
return 10 * log10(255 * 255 / MSE);
|
||||
float CalculatePSNR(byte *Img1, byte *Img2, int Stride, ROI Size)
|
||||
{
|
||||
float MSE = CalculateMSE(Img1, Img2, Stride, Size);
|
||||
return 10 * log10(255 * 255 / MSE);
|
||||
}
|
||||
|
||||
@@ -42,43 +42,45 @@
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef char int8;
|
||||
typedef short int16;
|
||||
typedef int int32;
|
||||
typedef unsigned char uint8;
|
||||
typedef char int8;
|
||||
typedef short int16;
|
||||
typedef int int32;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
/**
|
||||
* \brief Bitmap file header structure
|
||||
*
|
||||
* Bitmap file header structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint16 _bm_signature; //!< File signature, must be "BM"
|
||||
uint32 _bm_file_size; //!< File size
|
||||
uint32 _bm_reserved; //!< Reserved, must be zero
|
||||
uint32 _bm_bitmap_data; //!< Bitmap data
|
||||
* \brief Bitmap file header structure
|
||||
*
|
||||
* Bitmap file header structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16 _bm_signature; //!< File signature, must be "BM"
|
||||
uint32 _bm_file_size; //!< File size
|
||||
uint32 _bm_reserved; //!< Reserved, must be zero
|
||||
uint32 _bm_bitmap_data; //!< Bitmap data
|
||||
} BMPFileHeader;
|
||||
|
||||
/**
|
||||
* \brief Bitmap info header structure
|
||||
*
|
||||
* Bitmap info header structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32 _bm_info_header_size; //!< Info header size, must be 40
|
||||
uint32 _bm_image_width; //!< Image width
|
||||
uint32 _bm_image_height; //!< Image height
|
||||
uint16 _bm_num_of_planes; //!< Amount of image planes, must be 1
|
||||
uint16 _bm_color_depth; //!< Color depth
|
||||
uint32 _bm_compressed; //!< Image compression, must be none
|
||||
uint32 _bm_bitmap_size; //!< Size of bitmap data
|
||||
uint32 _bm_hor_resolution; //!< Horizontal resolution, assumed to be 0
|
||||
uint32 _bm_ver_resolution; //!< Vertical resolution, assumed to be 0
|
||||
uint32 _bm_num_colors_used; //!< Number of colors used, assumed to be 0
|
||||
uint32 _bm_num_important_colors; //!< Number of important colors, assumed to
|
||||
//!be 0
|
||||
* \brief Bitmap info header structure
|
||||
*
|
||||
* Bitmap info header structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32 _bm_info_header_size; //!< Info header size, must be 40
|
||||
uint32 _bm_image_width; //!< Image width
|
||||
uint32 _bm_image_height; //!< Image height
|
||||
uint16 _bm_num_of_planes; //!< Amount of image planes, must be 1
|
||||
uint16 _bm_color_depth; //!< Color depth
|
||||
uint32 _bm_compressed; //!< Image compression, must be none
|
||||
uint32 _bm_bitmap_size; //!< Size of bitmap data
|
||||
uint32 _bm_hor_resolution; //!< Horizontal resolution, assumed to be 0
|
||||
uint32 _bm_ver_resolution; //!< Vertical resolution, assumed to be 0
|
||||
uint32 _bm_num_colors_used; //!< Number of colors used, assumed to be 0
|
||||
uint32 _bm_num_important_colors; //!< Number of important colors, assumed to
|
||||
//! be 0
|
||||
} BMPInfoHeader;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
@@ -88,38 +90,38 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Simple 2D size / region_of_interest structure
|
||||
*
|
||||
* Simple 2D size / region_of_interest structure
|
||||
*/
|
||||
typedef struct {
|
||||
int width; //!< ROI width
|
||||
int height; //!< ROI height
|
||||
* \brief Simple 2D size / region_of_interest structure
|
||||
*
|
||||
* Simple 2D size / region_of_interest structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int width; //!< ROI width
|
||||
int height; //!< ROI height
|
||||
} ROI;
|
||||
|
||||
/**
|
||||
* One-byte unsigned integer type
|
||||
*/
|
||||
* One-byte unsigned integer type
|
||||
*/
|
||||
typedef unsigned char byte;
|
||||
|
||||
extern "C" {
|
||||
int clamp_0_255(int x);
|
||||
float round_f(float num);
|
||||
byte *MallocPlaneByte(int width, int height, int *pStepBytes);
|
||||
short *MallocPlaneShort(int width, int height, int *pStepBytes);
|
||||
float *MallocPlaneFloat(int width, int height, int *pStepBytes);
|
||||
void CopyByte2Float(byte *ImgSrc, int StrideB, float *ImgDst, int StrideF,
|
||||
ROI Size);
|
||||
void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB,
|
||||
ROI Size);
|
||||
void FreePlane(void *ptr);
|
||||
void AddFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size);
|
||||
void MulFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size);
|
||||
int PreLoadBmp(char *FileName, int *Width, int *Height);
|
||||
void LoadBmpAsGray(char *FileName, int Stride, ROI ImSize, byte *Img);
|
||||
void DumpBmpAsGray(char *FileName, byte *Img, int Stride, ROI ImSize);
|
||||
void DumpBlockF(float *PlaneF, int StrideF, char *Fname);
|
||||
void DumpBlock(byte *Plane, int Stride, char *Fname);
|
||||
float CalculateMSE(byte *Img1, byte *Img2, int Stride, ROI Size);
|
||||
float CalculatePSNR(byte *Img1, byte *Img2, int Stride, ROI Size);
|
||||
extern "C"
|
||||
{
|
||||
int clamp_0_255(int x);
|
||||
float round_f(float num);
|
||||
byte *MallocPlaneByte(int width, int height, int *pStepBytes);
|
||||
short *MallocPlaneShort(int width, int height, int *pStepBytes);
|
||||
float *MallocPlaneFloat(int width, int height, int *pStepBytes);
|
||||
void CopyByte2Float(byte *ImgSrc, int StrideB, float *ImgDst, int StrideF, ROI Size);
|
||||
void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB, ROI Size);
|
||||
void FreePlane(void *ptr);
|
||||
void AddFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size);
|
||||
void MulFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size);
|
||||
int PreLoadBmp(char *FileName, int *Width, int *Height);
|
||||
void LoadBmpAsGray(char *FileName, int Stride, ROI ImSize, byte *Img);
|
||||
void DumpBmpAsGray(char *FileName, byte *Img, int Stride, ROI ImSize);
|
||||
void DumpBlockF(float *PlaneF, int StrideF, char *Fname);
|
||||
void DumpBlock(byte *Plane, int Stride, char *Fname);
|
||||
float CalculateMSE(byte *Img1, byte *Img2, int Stride, ROI Size);
|
||||
float CalculatePSNR(byte *Img1, byte *Img2, int Stride, ROI Size);
|
||||
}
|
||||
|
||||
@@ -35,47 +35,46 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <helper_cuda.h> // helper functions for CUDA timing and initialization
|
||||
#include <helper_functions.h> // helper functions for timing, string parsing
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <helper_cuda.h> // helper functions for CUDA timing and initialization
|
||||
#include <helper_functions.h> // helper functions for timing, string parsing
|
||||
|
||||
/**
|
||||
* The dimension of pixels block
|
||||
*/
|
||||
* The dimension of pixels block
|
||||
*/
|
||||
#define BLOCK_SIZE 8
|
||||
|
||||
/**
|
||||
* Square of dimension of pixels block
|
||||
*/
|
||||
* Square of dimension of pixels block
|
||||
*/
|
||||
#define BLOCK_SIZE2 64
|
||||
|
||||
/**
|
||||
* log_2{BLOCK_SIZE), used for quick multiplication or division by the
|
||||
* pixels block dimension via shifting
|
||||
*/
|
||||
* log_2{BLOCK_SIZE), used for quick multiplication or division by the
|
||||
* pixels block dimension via shifting
|
||||
*/
|
||||
#define BLOCK_SIZE_LOG2 3
|
||||
|
||||
/**
|
||||
* log_2{BLOCK_SIZE*BLOCK_SIZE), used for quick multiplication or division by
|
||||
* the
|
||||
* square of pixels block via shifting
|
||||
*/
|
||||
* log_2{BLOCK_SIZE*BLOCK_SIZE), used for quick multiplication or division by
|
||||
* the
|
||||
* square of pixels block via shifting
|
||||
*/
|
||||
#define BLOCK_SIZE2_LOG2 6
|
||||
|
||||
/**
|
||||
* This macro states that __mul24 operation is performed faster that traditional
|
||||
* multiplication for two integers on CUDA. Please undefine if it appears to be
|
||||
* wrong on your system
|
||||
*/
|
||||
* This macro states that __mul24 operation is performed faster that traditional
|
||||
* multiplication for two integers on CUDA. Please undefine if it appears to be
|
||||
* wrong on your system
|
||||
*/
|
||||
#define __MUL24_FASTER_THAN_ASTERIX
|
||||
|
||||
/**
|
||||
* Wrapper to the fastest integer multiplication function on CUDA
|
||||
*/
|
||||
* Wrapper to the fastest integer multiplication function on CUDA
|
||||
*/
|
||||
#ifdef __MUL24_FASTER_THAN_ASTERIX
|
||||
#define FMUL(x, y) (__mul24(x, y))
|
||||
#else
|
||||
@@ -83,6 +82,6 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This macro allows using aligned memory management
|
||||
*/
|
||||
//#define __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
* This macro allows using aligned memory management
|
||||
*/
|
||||
// #define __ALLOW_ALIGNED_MEMORY_MANAGEMENT
|
||||
|
||||
@@ -38,47 +38,53 @@
|
||||
* The routine that performs quantization of coefficients is also included.
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "BmpUtil.h"
|
||||
#include "Common.h"
|
||||
|
||||
/**
|
||||
* This unitary matrix performs DCT of rows of the matrix to the left
|
||||
*/
|
||||
const float DCTv8matrix[BLOCK_SIZE2] = {
|
||||
0.3535533905932738f, 0.4903926402016152f, 0.4619397662556434f, 0.4157348061512726f, 0.3535533905932738f, 0.2777851165098011f, 0.1913417161825449f, 0.0975451610080642f,
|
||||
0.3535533905932738f, 0.4157348061512726f, 0.1913417161825449f, -0.0975451610080641f, -0.3535533905932737f, -0.4903926402016152f, -0.4619397662556434f, -0.2777851165098011f,
|
||||
0.3535533905932738f, 0.2777851165098011f, -0.1913417161825449f, -0.4903926402016152f, -0.3535533905932738f, 0.0975451610080642f, 0.4619397662556433f, 0.4157348061512727f,
|
||||
0.3535533905932738f, 0.0975451610080642f, -0.4619397662556434f, -0.2777851165098011f, 0.3535533905932737f, 0.4157348061512727f, -0.1913417161825450f, -0.4903926402016153f,
|
||||
0.3535533905932738f, -0.0975451610080641f, -0.4619397662556434f, 0.2777851165098009f, 0.3535533905932738f, -0.4157348061512726f, -0.1913417161825453f, 0.4903926402016152f,
|
||||
0.3535533905932738f, -0.2777851165098010f, -0.1913417161825452f, 0.4903926402016153f, -0.3535533905932733f, -0.0975451610080649f, 0.4619397662556437f, -0.4157348061512720f,
|
||||
0.3535533905932738f, -0.4157348061512727f, 0.1913417161825450f, 0.0975451610080640f, -0.3535533905932736f, 0.4903926402016152f, -0.4619397662556435f, 0.2777851165098022f,
|
||||
0.3535533905932738f, -0.4903926402016152f, 0.4619397662556433f, -0.4157348061512721f, 0.3535533905932733f, -0.2777851165098008f, 0.1913417161825431f, -0.0975451610080625f};
|
||||
0.3535533905932738f, 0.4903926402016152f, 0.4619397662556434f, 0.4157348061512726f, 0.3535533905932738f,
|
||||
0.2777851165098011f, 0.1913417161825449f, 0.0975451610080642f, 0.3535533905932738f, 0.4157348061512726f,
|
||||
0.1913417161825449f, -0.0975451610080641f, -0.3535533905932737f, -0.4903926402016152f, -0.4619397662556434f,
|
||||
-0.2777851165098011f, 0.3535533905932738f, 0.2777851165098011f, -0.1913417161825449f, -0.4903926402016152f,
|
||||
-0.3535533905932738f, 0.0975451610080642f, 0.4619397662556433f, 0.4157348061512727f, 0.3535533905932738f,
|
||||
0.0975451610080642f, -0.4619397662556434f, -0.2777851165098011f, 0.3535533905932737f, 0.4157348061512727f,
|
||||
-0.1913417161825450f, -0.4903926402016153f, 0.3535533905932738f, -0.0975451610080641f, -0.4619397662556434f,
|
||||
0.2777851165098009f, 0.3535533905932738f, -0.4157348061512726f, -0.1913417161825453f, 0.4903926402016152f,
|
||||
0.3535533905932738f, -0.2777851165098010f, -0.1913417161825452f, 0.4903926402016153f, -0.3535533905932733f,
|
||||
-0.0975451610080649f, 0.4619397662556437f, -0.4157348061512720f, 0.3535533905932738f, -0.4157348061512727f,
|
||||
0.1913417161825450f, 0.0975451610080640f, -0.3535533905932736f, 0.4903926402016152f, -0.4619397662556435f,
|
||||
0.2777851165098022f, 0.3535533905932738f, -0.4903926402016152f, 0.4619397662556433f, -0.4157348061512721f,
|
||||
0.3535533905932733f, -0.2777851165098008f, 0.1913417161825431f, -0.0975451610080625f};
|
||||
|
||||
/**
|
||||
* This unitary matrix performs DCT of columns of the matrix to the right
|
||||
*/
|
||||
const float DCTv8matrixT[BLOCK_SIZE2] = {
|
||||
0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f,
|
||||
0.4903926402016152f, 0.4157348061512726f, 0.2777851165098011f, 0.0975451610080642f, -0.0975451610080641f, -0.2777851165098010f, -0.4157348061512727f, -0.4903926402016152f,
|
||||
0.4619397662556434f, 0.1913417161825449f, -0.1913417161825449f, -0.4619397662556434f, -0.4619397662556434f, -0.1913417161825452f, 0.1913417161825450f, 0.4619397662556433f,
|
||||
0.4157348061512726f, -0.0975451610080641f, -0.4903926402016152f, -0.2777851165098011f, 0.2777851165098009f, 0.4903926402016153f, 0.0975451610080640f, -0.4157348061512721f,
|
||||
0.3535533905932738f, -0.3535533905932737f, -0.3535533905932738f, 0.3535533905932737f, 0.3535533905932738f, -0.3535533905932733f, -0.3535533905932736f, 0.3535533905932733f,
|
||||
0.2777851165098011f, -0.4903926402016152f, 0.0975451610080642f, 0.4157348061512727f, -0.4157348061512726f, -0.0975451610080649f, 0.4903926402016152f, -0.2777851165098008f,
|
||||
0.1913417161825449f, -0.4619397662556434f, 0.4619397662556433f, -0.1913417161825450f, -0.1913417161825453f, 0.4619397662556437f, -0.4619397662556435f, 0.1913417161825431f,
|
||||
0.0975451610080642f, -0.2777851165098011f, 0.4157348061512727f, -0.4903926402016153f, 0.4903926402016152f, -0.4157348061512720f, 0.2777851165098022f, -0.0975451610080625f};
|
||||
0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f,
|
||||
0.3535533905932738f, 0.3535533905932738f, 0.3535533905932738f, 0.4903926402016152f, 0.4157348061512726f,
|
||||
0.2777851165098011f, 0.0975451610080642f, -0.0975451610080641f, -0.2777851165098010f, -0.4157348061512727f,
|
||||
-0.4903926402016152f, 0.4619397662556434f, 0.1913417161825449f, -0.1913417161825449f, -0.4619397662556434f,
|
||||
-0.4619397662556434f, -0.1913417161825452f, 0.1913417161825450f, 0.4619397662556433f, 0.4157348061512726f,
|
||||
-0.0975451610080641f, -0.4903926402016152f, -0.2777851165098011f, 0.2777851165098009f, 0.4903926402016153f,
|
||||
0.0975451610080640f, -0.4157348061512721f, 0.3535533905932738f, -0.3535533905932737f, -0.3535533905932738f,
|
||||
0.3535533905932737f, 0.3535533905932738f, -0.3535533905932733f, -0.3535533905932736f, 0.3535533905932733f,
|
||||
0.2777851165098011f, -0.4903926402016152f, 0.0975451610080642f, 0.4157348061512727f, -0.4157348061512726f,
|
||||
-0.0975451610080649f, 0.4903926402016152f, -0.2777851165098008f, 0.1913417161825449f, -0.4619397662556434f,
|
||||
0.4619397662556433f, -0.1913417161825450f, -0.1913417161825453f, 0.4619397662556437f, -0.4619397662556435f,
|
||||
0.1913417161825431f, 0.0975451610080642f, -0.2777851165098011f, 0.4157348061512727f, -0.4903926402016153f,
|
||||
0.4903926402016152f, -0.4157348061512720f, 0.2777851165098022f, -0.0975451610080625f};
|
||||
|
||||
/**
|
||||
* JPEG quality=0_of_12 quantization matrix
|
||||
*/
|
||||
float Q_GOLD[BLOCK_SIZE2] = {
|
||||
32.f, 33.f, 51.f, 81.f, 66.f, 39.f, 34.f, 17.f,
|
||||
33.f, 36.f, 48.f, 47.f, 28.f, 23.f, 12.f, 12.f,
|
||||
51.f, 48.f, 47.f, 28.f, 23.f, 12.f, 12.f, 12.f,
|
||||
81.f, 47.f, 28.f, 23.f, 12.f, 12.f, 12.f, 12.f,
|
||||
66.f, 28.f, 23.f, 12.f, 12.f, 12.f, 12.f, 12.f,
|
||||
39.f, 23.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f,
|
||||
34.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f,
|
||||
17.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f};
|
||||
float Q_GOLD[BLOCK_SIZE2] = {32.f, 33.f, 51.f, 81.f, 66.f, 39.f, 34.f, 17.f, 33.f, 36.f, 48.f, 47.f, 28.f,
|
||||
23.f, 12.f, 12.f, 51.f, 48.f, 47.f, 28.f, 23.f, 12.f, 12.f, 12.f, 81.f, 47.f,
|
||||
28.f, 23.f, 12.f, 12.f, 12.f, 12.f, 66.f, 28.f, 23.f, 12.f, 12.f, 12.f, 12.f,
|
||||
12.f, 39.f, 23.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f, 34.f, 12.f, 12.f, 12.f,
|
||||
12.f, 12.f, 12.f, 12.f, 17.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f, 12.f};
|
||||
|
||||
/**
|
||||
**************************************************************************
|
||||
@@ -93,23 +99,19 @@ float Q_GOLD[BLOCK_SIZE2] = {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void mult8x8(const float *M1, int M1Stride, const float *M2, int M2Stride,
|
||||
float *Mres, int MresStride)
|
||||
void mult8x8(const float *M1, int M1Stride, const float *M2, int M2Stride, float *Mres, int MresStride)
|
||||
{
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
{
|
||||
for (int j = 0; j < BLOCK_SIZE; j++)
|
||||
{
|
||||
float accumul = 0;
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
for (int j = 0; j < BLOCK_SIZE; j++) {
|
||||
float accumul = 0;
|
||||
|
||||
for (int k = 0; k < BLOCK_SIZE; k++)
|
||||
{
|
||||
accumul += M1[i * M1Stride + k] * M2[k * M2Stride + j];
|
||||
}
|
||||
for (int k = 0; k < BLOCK_SIZE; k++) {
|
||||
accumul += M1[i * M1Stride + k] * M2[k * M2Stride + j];
|
||||
}
|
||||
|
||||
Mres[i * MresStride + j] = accumul;
|
||||
Mres[i * MresStride + j] = accumul;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,25 +127,20 @@ void mult8x8(const float *M1, int M1Stride, const float *M2, int M2Stride,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
extern "C" void computeDCT8x8Gold1(const float *fSrc, float *fDst, int Stride,
|
||||
ROI Size)
|
||||
extern "C" void computeDCT8x8Gold1(const float *fSrc, float *fDst, int Stride, ROI Size)
|
||||
{
|
||||
float tmpblock[BLOCK_SIZE2];
|
||||
float tmpblock[BLOCK_SIZE2];
|
||||
|
||||
// perform block wise DCT
|
||||
// DCT(A) = DCTv8matrixT * A * DCTv8matrix
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE)
|
||||
{
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE)
|
||||
{
|
||||
// tmpblock = DCTv8matrixT * A
|
||||
mult8x8(DCTv8matrixT, BLOCK_SIZE, fSrc + i * Stride + j, Stride, tmpblock,
|
||||
BLOCK_SIZE);
|
||||
// DCT(A) = tmpblock * DCTv8matrix
|
||||
mult8x8(tmpblock, BLOCK_SIZE, DCTv8matrix, BLOCK_SIZE,
|
||||
fDst + i * Stride + j, Stride);
|
||||
// perform block wise DCT
|
||||
// DCT(A) = DCTv8matrixT * A * DCTv8matrix
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE) {
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE) {
|
||||
// tmpblock = DCTv8matrixT * A
|
||||
mult8x8(DCTv8matrixT, BLOCK_SIZE, fSrc + i * Stride + j, Stride, tmpblock, BLOCK_SIZE);
|
||||
// DCT(A) = tmpblock * DCTv8matrix
|
||||
mult8x8(tmpblock, BLOCK_SIZE, DCTv8matrix, BLOCK_SIZE, fDst + i * Stride + j, Stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,25 +156,20 @@ extern "C" void computeDCT8x8Gold1(const float *fSrc, float *fDst, int Stride,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
extern "C" void computeIDCT8x8Gold1(const float *fSrc, float *fDst, int Stride,
|
||||
ROI Size)
|
||||
extern "C" void computeIDCT8x8Gold1(const float *fSrc, float *fDst, int Stride, ROI Size)
|
||||
{
|
||||
float tmpblock[BLOCK_SIZE2];
|
||||
float tmpblock[BLOCK_SIZE2];
|
||||
|
||||
// perform block wise IDCT
|
||||
// IDCT(A) = DCTv8matrix * A * DCTv8matrixT
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE)
|
||||
{
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE)
|
||||
{
|
||||
// tmpblock = DCTv8matrix * A
|
||||
mult8x8(DCTv8matrix, BLOCK_SIZE, fSrc + i * Stride + j, Stride, tmpblock,
|
||||
BLOCK_SIZE);
|
||||
// DCT(A) = tmpblock * DCTv8matrixT;
|
||||
mult8x8(tmpblock, BLOCK_SIZE, DCTv8matrixT, BLOCK_SIZE,
|
||||
fDst + i * Stride + j, Stride);
|
||||
// perform block wise IDCT
|
||||
// IDCT(A) = DCTv8matrix * A * DCTv8matrixT
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE) {
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE) {
|
||||
// tmpblock = DCTv8matrix * A
|
||||
mult8x8(DCTv8matrix, BLOCK_SIZE, fSrc + i * Stride + j, Stride, tmpblock, BLOCK_SIZE);
|
||||
// DCT(A) = tmpblock * DCTv8matrixT;
|
||||
mult8x8(tmpblock, BLOCK_SIZE, DCTv8matrixT, BLOCK_SIZE, fDst + i * Stride + j, Stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,19 +185,16 @@ extern "C" void computeIDCT8x8Gold1(const float *fSrc, float *fDst, int Stride,
|
||||
*/
|
||||
extern "C" void quantizeGoldFloat(float *fSrcDst, int Stride, ROI Size)
|
||||
{
|
||||
// perform block wise in-place quantization using Q_GOLD
|
||||
// Q_GOLD(A) = round(A ./ Q_GOLD) .* Q_GOLD;
|
||||
for (int i = 0; i < Size.height; i++)
|
||||
{
|
||||
for (int j = 0; j < Size.width; j++)
|
||||
{
|
||||
int qx = j % BLOCK_SIZE;
|
||||
int qy = i % BLOCK_SIZE;
|
||||
float quantized =
|
||||
round_f(fSrcDst[i * Stride + j] / Q_GOLD[(qy << BLOCK_SIZE_LOG2) + qx]);
|
||||
fSrcDst[i * Stride + j] = quantized * Q_GOLD[(qy << BLOCK_SIZE_LOG2) + qx];
|
||||
// perform block wise in-place quantization using Q_GOLD
|
||||
// Q_GOLD(A) = round(A ./ Q_GOLD) .* Q_GOLD;
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
int qx = j % BLOCK_SIZE;
|
||||
int qy = i % BLOCK_SIZE;
|
||||
float quantized = round_f(fSrcDst[i * Stride + j] / Q_GOLD[(qy << BLOCK_SIZE_LOG2) + qx]);
|
||||
fSrcDst[i * Stride + j] = quantized * Q_GOLD[(qy << BLOCK_SIZE_LOG2) + qx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,33 +210,29 @@ extern "C" void quantizeGoldFloat(float *fSrcDst, int Stride, ROI Size)
|
||||
*/
|
||||
void quantizeGoldShort(short *fSrcDst, int Stride, ROI Size)
|
||||
{
|
||||
// perform block wise in-place quantization using Q_GOLD
|
||||
// Q_GOLD(A) = round(A ./ Q_GOLD) .* Q_GOLD;
|
||||
for (int i = 0; i < Size.height; i++)
|
||||
{
|
||||
for (int j = 0; j < Size.width; j++)
|
||||
{
|
||||
int qx = j % BLOCK_SIZE;
|
||||
int qy = i % BLOCK_SIZE;
|
||||
short temp = fSrcDst[i * Stride + j];
|
||||
short quant = (short)(Q_GOLD[(qy << BLOCK_SIZE_LOG2) + qx]);
|
||||
// perform block wise in-place quantization using Q_GOLD
|
||||
// Q_GOLD(A) = round(A ./ Q_GOLD) .* Q_GOLD;
|
||||
for (int i = 0; i < Size.height; i++) {
|
||||
for (int j = 0; j < Size.width; j++) {
|
||||
int qx = j % BLOCK_SIZE;
|
||||
int qy = i % BLOCK_SIZE;
|
||||
short temp = fSrcDst[i * Stride + j];
|
||||
short quant = (short)(Q_GOLD[(qy << BLOCK_SIZE_LOG2) + qx]);
|
||||
|
||||
if (temp < 0)
|
||||
{
|
||||
temp = -temp;
|
||||
temp += quant >> 1;
|
||||
temp /= quant;
|
||||
temp = -temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp += quant >> 1;
|
||||
temp /= quant;
|
||||
}
|
||||
if (temp < 0) {
|
||||
temp = -temp;
|
||||
temp += quant >> 1;
|
||||
temp /= quant;
|
||||
temp = -temp;
|
||||
}
|
||||
else {
|
||||
temp += quant >> 1;
|
||||
temp /= quant;
|
||||
}
|
||||
|
||||
fSrcDst[i * Stride + j] = temp * quant;
|
||||
fSrcDst[i * Stride + j] = temp * quant;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Used in forward and inverse DCT.
|
||||
@@ -276,37 +261,32 @@ float C_norm = 0.3535533905932737f; // 1 / (8^0.5)
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void SubroutineDCTvector(float *FirstIn, int StepIn, float *FirstOut,
|
||||
int StepOut)
|
||||
void SubroutineDCTvector(float *FirstIn, int StepIn, float *FirstOut, int StepOut)
|
||||
{
|
||||
float X07P = FirstIn[0 * StepIn] + FirstIn[7 * StepIn];
|
||||
float X16P = FirstIn[1 * StepIn] + FirstIn[6 * StepIn];
|
||||
float X25P = FirstIn[2 * StepIn] + FirstIn[5 * StepIn];
|
||||
float X34P = FirstIn[3 * StepIn] + FirstIn[4 * StepIn];
|
||||
float X07P = FirstIn[0 * StepIn] + FirstIn[7 * StepIn];
|
||||
float X16P = FirstIn[1 * StepIn] + FirstIn[6 * StepIn];
|
||||
float X25P = FirstIn[2 * StepIn] + FirstIn[5 * StepIn];
|
||||
float X34P = FirstIn[3 * StepIn] + FirstIn[4 * StepIn];
|
||||
|
||||
float X07M = FirstIn[0 * StepIn] - FirstIn[7 * StepIn];
|
||||
float X61M = FirstIn[6 * StepIn] - FirstIn[1 * StepIn];
|
||||
float X25M = FirstIn[2 * StepIn] - FirstIn[5 * StepIn];
|
||||
float X43M = FirstIn[4 * StepIn] - FirstIn[3 * StepIn];
|
||||
float X07M = FirstIn[0 * StepIn] - FirstIn[7 * StepIn];
|
||||
float X61M = FirstIn[6 * StepIn] - FirstIn[1 * StepIn];
|
||||
float X25M = FirstIn[2 * StepIn] - FirstIn[5 * StepIn];
|
||||
float X43M = FirstIn[4 * StepIn] - FirstIn[3 * StepIn];
|
||||
|
||||
float X07P34PP = X07P + X34P;
|
||||
float X07P34PM = X07P - X34P;
|
||||
float X16P25PP = X16P + X25P;
|
||||
float X16P25PM = X16P - X25P;
|
||||
float X07P34PP = X07P + X34P;
|
||||
float X07P34PM = X07P - X34P;
|
||||
float X16P25PP = X16P + X25P;
|
||||
float X16P25PM = X16P - X25P;
|
||||
|
||||
FirstOut[0 * StepOut] = C_norm * (X07P34PP + X16P25PP);
|
||||
FirstOut[2 * StepOut] = C_norm * (C_b * X07P34PM + C_e * X16P25PM);
|
||||
FirstOut[4 * StepOut] = C_norm * (X07P34PP - X16P25PP);
|
||||
FirstOut[6 * StepOut] = C_norm * (C_e * X07P34PM - C_b * X16P25PM);
|
||||
FirstOut[0 * StepOut] = C_norm * (X07P34PP + X16P25PP);
|
||||
FirstOut[2 * StepOut] = C_norm * (C_b * X07P34PM + C_e * X16P25PM);
|
||||
FirstOut[4 * StepOut] = C_norm * (X07P34PP - X16P25PP);
|
||||
FirstOut[6 * StepOut] = C_norm * (C_e * X07P34PM - C_b * X16P25PM);
|
||||
|
||||
FirstOut[1 * StepOut] =
|
||||
C_norm * (C_a * X07M - C_c * X61M + C_d * X25M - C_f * X43M);
|
||||
FirstOut[3 * StepOut] =
|
||||
C_norm * (C_c * X07M + C_f * X61M - C_a * X25M + C_d * X43M);
|
||||
FirstOut[5 * StepOut] =
|
||||
C_norm * (C_d * X07M + C_a * X61M + C_f * X25M - C_c * X43M);
|
||||
FirstOut[7 * StepOut] =
|
||||
C_norm * (C_f * X07M + C_d * X61M + C_c * X25M + C_a * X43M);
|
||||
FirstOut[1 * StepOut] = C_norm * (C_a * X07M - C_c * X61M + C_d * X25M - C_f * X43M);
|
||||
FirstOut[3 * StepOut] = C_norm * (C_c * X07M + C_f * X61M - C_a * X25M + C_d * X43M);
|
||||
FirstOut[5 * StepOut] = C_norm * (C_d * X07M + C_a * X61M + C_f * X25M - C_c * X43M);
|
||||
FirstOut[7 * StepOut] = C_norm * (C_f * X07M + C_d * X61M + C_c * X25M + C_a * X43M);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,38 +302,37 @@ void SubroutineDCTvector(float *FirstIn, int StepIn, float *FirstOut,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void SubroutineIDCTvector(float *FirstIn, int StepIn, float *FirstOut,
|
||||
int StepOut)
|
||||
void SubroutineIDCTvector(float *FirstIn, int StepIn, float *FirstOut, int StepOut)
|
||||
{
|
||||
float Y04P = FirstIn[0 * StepIn] + FirstIn[4 * StepIn];
|
||||
float Y2b6eP = C_b * FirstIn[2 * StepIn] + C_e * FirstIn[6 * StepIn];
|
||||
float Y04P = FirstIn[0 * StepIn] + FirstIn[4 * StepIn];
|
||||
float Y2b6eP = C_b * FirstIn[2 * StepIn] + C_e * FirstIn[6 * StepIn];
|
||||
|
||||
float Y04P2b6ePP = Y04P + Y2b6eP;
|
||||
float Y04P2b6ePM = Y04P - Y2b6eP;
|
||||
float Y7f1aP3c5dPP = C_f * FirstIn[7 * StepIn] + C_a * FirstIn[1 * StepIn] +
|
||||
C_c * FirstIn[3 * StepIn] + C_d * FirstIn[5 * StepIn];
|
||||
float Y7a1fM3d5cMP = C_a * FirstIn[7 * StepIn] - C_f * FirstIn[1 * StepIn] +
|
||||
C_d * FirstIn[3 * StepIn] - C_c * FirstIn[5 * StepIn];
|
||||
float Y04P2b6ePP = Y04P + Y2b6eP;
|
||||
float Y04P2b6ePM = Y04P - Y2b6eP;
|
||||
float Y7f1aP3c5dPP =
|
||||
C_f * FirstIn[7 * StepIn] + C_a * FirstIn[1 * StepIn] + C_c * FirstIn[3 * StepIn] + C_d * FirstIn[5 * StepIn];
|
||||
float Y7a1fM3d5cMP =
|
||||
C_a * FirstIn[7 * StepIn] - C_f * FirstIn[1 * StepIn] + C_d * FirstIn[3 * StepIn] - C_c * FirstIn[5 * StepIn];
|
||||
|
||||
float Y04M = FirstIn[0 * StepIn] - FirstIn[4 * StepIn];
|
||||
float Y2e6bM = C_e * FirstIn[2 * StepIn] - C_b * FirstIn[6 * StepIn];
|
||||
float Y04M = FirstIn[0 * StepIn] - FirstIn[4 * StepIn];
|
||||
float Y2e6bM = C_e * FirstIn[2 * StepIn] - C_b * FirstIn[6 * StepIn];
|
||||
|
||||
float Y04M2e6bMP = Y04M + Y2e6bM;
|
||||
float Y04M2e6bMM = Y04M - Y2e6bM;
|
||||
float Y1c7dM3f5aPM = C_c * FirstIn[1 * StepIn] - C_d * FirstIn[7 * StepIn] -
|
||||
C_f * FirstIn[3 * StepIn] - C_a * FirstIn[5 * StepIn];
|
||||
float Y1d7cP3a5fMM = C_d * FirstIn[1 * StepIn] + C_c * FirstIn[7 * StepIn] -
|
||||
C_a * FirstIn[3 * StepIn] + C_f * FirstIn[5 * StepIn];
|
||||
float Y04M2e6bMP = Y04M + Y2e6bM;
|
||||
float Y04M2e6bMM = Y04M - Y2e6bM;
|
||||
float Y1c7dM3f5aPM =
|
||||
C_c * FirstIn[1 * StepIn] - C_d * FirstIn[7 * StepIn] - C_f * FirstIn[3 * StepIn] - C_a * FirstIn[5 * StepIn];
|
||||
float Y1d7cP3a5fMM =
|
||||
C_d * FirstIn[1 * StepIn] + C_c * FirstIn[7 * StepIn] - C_a * FirstIn[3 * StepIn] + C_f * FirstIn[5 * StepIn];
|
||||
|
||||
FirstOut[0 * StepOut] = C_norm * (Y04P2b6ePP + Y7f1aP3c5dPP);
|
||||
FirstOut[7 * StepOut] = C_norm * (Y04P2b6ePP - Y7f1aP3c5dPP);
|
||||
FirstOut[4 * StepOut] = C_norm * (Y04P2b6ePM + Y7a1fM3d5cMP);
|
||||
FirstOut[3 * StepOut] = C_norm * (Y04P2b6ePM - Y7a1fM3d5cMP);
|
||||
FirstOut[0 * StepOut] = C_norm * (Y04P2b6ePP + Y7f1aP3c5dPP);
|
||||
FirstOut[7 * StepOut] = C_norm * (Y04P2b6ePP - Y7f1aP3c5dPP);
|
||||
FirstOut[4 * StepOut] = C_norm * (Y04P2b6ePM + Y7a1fM3d5cMP);
|
||||
FirstOut[3 * StepOut] = C_norm * (Y04P2b6ePM - Y7a1fM3d5cMP);
|
||||
|
||||
FirstOut[1 * StepOut] = C_norm * (Y04M2e6bMP + Y1c7dM3f5aPM);
|
||||
FirstOut[5 * StepOut] = C_norm * (Y04M2e6bMM - Y1d7cP3a5fMM);
|
||||
FirstOut[2 * StepOut] = C_norm * (Y04M2e6bMM + Y1d7cP3a5fMM);
|
||||
FirstOut[6 * StepOut] = C_norm * (Y04M2e6bMP - Y1c7dM3f5aPM);
|
||||
FirstOut[1 * StepOut] = C_norm * (Y04M2e6bMP + Y1c7dM3f5aPM);
|
||||
FirstOut[5 * StepOut] = C_norm * (Y04M2e6bMM - Y1d7cP3a5fMM);
|
||||
FirstOut[2 * StepOut] = C_norm * (Y04M2e6bMM + Y1d7cP3a5fMM);
|
||||
FirstOut[6 * StepOut] = C_norm * (Y04M2e6bMP - Y1c7dM3f5aPM);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,28 +348,21 @@ void SubroutineIDCTvector(float *FirstIn, int StepIn, float *FirstOut,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
extern "C" void computeDCT8x8Gold2(const float *fSrc, float *fDst, int Stride,
|
||||
ROI Size)
|
||||
extern "C" void computeDCT8x8Gold2(const float *fSrc, float *fDst, int Stride, ROI Size)
|
||||
{
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE)
|
||||
{
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE)
|
||||
{
|
||||
// process rows
|
||||
for (int k = 0; k < BLOCK_SIZE; k++)
|
||||
{
|
||||
SubroutineDCTvector((float *)fSrc + (i + k) * Stride + j, 1,
|
||||
fDst + (i + k) * Stride + j, 1);
|
||||
}
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE) {
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE) {
|
||||
// process rows
|
||||
for (int k = 0; k < BLOCK_SIZE; k++) {
|
||||
SubroutineDCTvector((float *)fSrc + (i + k) * Stride + j, 1, fDst + (i + k) * Stride + j, 1);
|
||||
}
|
||||
|
||||
// process columns
|
||||
for (int k = 0; k < BLOCK_SIZE; k++)
|
||||
{
|
||||
SubroutineDCTvector(fDst + i * Stride + (j + k), Stride,
|
||||
fDst + i * Stride + (j + k), Stride);
|
||||
}
|
||||
// process columns
|
||||
for (int k = 0; k < BLOCK_SIZE; k++) {
|
||||
SubroutineDCTvector(fDst + i * Stride + (j + k), Stride, fDst + i * Stride + (j + k), Stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,26 +378,19 @@ extern "C" void computeDCT8x8Gold2(const float *fSrc, float *fDst, int Stride,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
extern "C" void computeIDCT8x8Gold2(const float *fSrc, float *fDst, int Stride,
|
||||
ROI Size)
|
||||
extern "C" void computeIDCT8x8Gold2(const float *fSrc, float *fDst, int Stride, ROI Size)
|
||||
{
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE)
|
||||
{
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE)
|
||||
{
|
||||
// process rows
|
||||
for (int k = 0; k < BLOCK_SIZE; k++)
|
||||
{
|
||||
SubroutineIDCTvector((float *)fSrc + (i + k) * Stride + j, 1,
|
||||
fDst + (i + k) * Stride + j, 1);
|
||||
}
|
||||
for (int i = 0; i + BLOCK_SIZE - 1 < Size.height; i += BLOCK_SIZE) {
|
||||
for (int j = 0; j + BLOCK_SIZE - 1 < Size.width; j += BLOCK_SIZE) {
|
||||
// process rows
|
||||
for (int k = 0; k < BLOCK_SIZE; k++) {
|
||||
SubroutineIDCTvector((float *)fSrc + (i + k) * Stride + j, 1, fDst + (i + k) * Stride + j, 1);
|
||||
}
|
||||
|
||||
// process columns
|
||||
for (int k = 0; k < BLOCK_SIZE; k++)
|
||||
{
|
||||
SubroutineIDCTvector(fDst + i * Stride + (j + k), Stride,
|
||||
fDst + i * Stride + (j + k), Stride);
|
||||
}
|
||||
// process columns
|
||||
for (int k = 0; k < BLOCK_SIZE; k++) {
|
||||
SubroutineIDCTvector(fDst + i * Stride + (j + k), Stride, fDst + i * Stride + (j + k), Stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,12 @@
|
||||
|
||||
#include "BmpUtil.h"
|
||||
|
||||
extern "C" {
|
||||
void computeDCT8x8Gold1(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
void computeIDCT8x8Gold1(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
void quantizeGoldFloat(float *fSrcDst, int Stride, ROI Size);
|
||||
void quantizeGoldShort(short *fSrcDst, int Stride, ROI Size);
|
||||
void computeDCT8x8Gold2(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
void computeIDCT8x8Gold2(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
extern "C"
|
||||
{
|
||||
void computeDCT8x8Gold1(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
void computeIDCT8x8Gold1(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
void quantizeGoldFloat(float *fSrcDst, int Stride, ROI Size);
|
||||
void quantizeGoldShort(short *fSrcDst, int Stride, ROI Size);
|
||||
void computeDCT8x8Gold2(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
void computeIDCT8x8Gold2(const float *fSrc, float *fDst, int Stride, ROI Size);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,19 +47,23 @@ namespace cg = cooperative_groups;
|
||||
#include "Common.h"
|
||||
|
||||
/**
|
||||
* This unitary matrix performs discrete cosine transform of rows of the matrix
|
||||
* to the left
|
||||
*/
|
||||
* This unitary matrix performs discrete cosine transform of rows of the matrix
|
||||
* to the left
|
||||
*/
|
||||
__constant__ float DCTv8matrix[] = {
|
||||
0.3535533905932738f, 0.4903926402016152f, 0.4619397662556434f, 0.4157348061512726f, 0.3535533905932738f, 0.2777851165098011f, 0.1913417161825449f, 0.0975451610080642f,
|
||||
0.3535533905932738f, 0.4157348061512726f, 0.1913417161825449f, -0.0975451610080641f, -0.3535533905932737f, -0.4903926402016152f, -0.4619397662556434f, -0.2777851165098011f,
|
||||
0.3535533905932738f, 0.2777851165098011f, -0.1913417161825449f, -0.4903926402016152f, -0.3535533905932738f, 0.0975451610080642f, 0.4619397662556433f, 0.4157348061512727f,
|
||||
0.3535533905932738f, 0.0975451610080642f, -0.4619397662556434f, -0.2777851165098011f, 0.3535533905932737f, 0.4157348061512727f, -0.1913417161825450f, -0.4903926402016153f,
|
||||
0.3535533905932738f, -0.0975451610080641f, -0.4619397662556434f, 0.2777851165098009f, 0.3535533905932738f, -0.4157348061512726f, -0.1913417161825453f, 0.4903926402016152f,
|
||||
0.3535533905932738f, -0.2777851165098010f, -0.1913417161825452f, 0.4903926402016153f, -0.3535533905932733f, -0.0975451610080649f, 0.4619397662556437f, -0.4157348061512720f,
|
||||
0.3535533905932738f, -0.4157348061512727f, 0.1913417161825450f, 0.0975451610080640f, -0.3535533905932736f, 0.4903926402016152f, -0.4619397662556435f, 0.2777851165098022f,
|
||||
0.3535533905932738f, -0.4903926402016152f, 0.4619397662556433f, -0.4157348061512721f, 0.3535533905932733f, -0.2777851165098008f, 0.1913417161825431f, -0.0975451610080625f
|
||||
};
|
||||
0.3535533905932738f, 0.4903926402016152f, 0.4619397662556434f, 0.4157348061512726f, 0.3535533905932738f,
|
||||
0.2777851165098011f, 0.1913417161825449f, 0.0975451610080642f, 0.3535533905932738f, 0.4157348061512726f,
|
||||
0.1913417161825449f, -0.0975451610080641f, -0.3535533905932737f, -0.4903926402016152f, -0.4619397662556434f,
|
||||
-0.2777851165098011f, 0.3535533905932738f, 0.2777851165098011f, -0.1913417161825449f, -0.4903926402016152f,
|
||||
-0.3535533905932738f, 0.0975451610080642f, 0.4619397662556433f, 0.4157348061512727f, 0.3535533905932738f,
|
||||
0.0975451610080642f, -0.4619397662556434f, -0.2777851165098011f, 0.3535533905932737f, 0.4157348061512727f,
|
||||
-0.1913417161825450f, -0.4903926402016153f, 0.3535533905932738f, -0.0975451610080641f, -0.4619397662556434f,
|
||||
0.2777851165098009f, 0.3535533905932738f, -0.4157348061512726f, -0.1913417161825453f, 0.4903926402016152f,
|
||||
0.3535533905932738f, -0.2777851165098010f, -0.1913417161825452f, 0.4903926402016153f, -0.3535533905932733f,
|
||||
-0.0975451610080649f, 0.4619397662556437f, -0.4157348061512720f, 0.3535533905932738f, -0.4157348061512727f,
|
||||
0.1913417161825450f, 0.0975451610080640f, -0.3535533905932736f, 0.4903926402016152f, -0.4619397662556435f,
|
||||
0.2777851165098022f, 0.3535533905932738f, -0.4903926402016152f, 0.4619397662556433f, -0.4157348061512721f,
|
||||
0.3535533905932733f, -0.2777851165098008f, 0.1913417161825431f, -0.0975451610080625f};
|
||||
|
||||
// Temporary blocks
|
||||
__shared__ float CurBlockLocal1[BLOCK_SIZE2];
|
||||
@@ -80,73 +84,70 @@ __shared__ float CurBlockLocal2[BLOCK_SIZE2];
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__global__ void CUDAkernel1DCT(float *Dst, int ImgWidth, int OffsetXBlocks,
|
||||
int OffsetYBlocks, cudaTextureObject_t TexSrc) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
// Block index
|
||||
const int bx = blockIdx.x + OffsetXBlocks;
|
||||
const int by = blockIdx.y + OffsetYBlocks;
|
||||
__global__ void
|
||||
CUDAkernel1DCT(float *Dst, int ImgWidth, int OffsetXBlocks, int OffsetYBlocks, cudaTextureObject_t TexSrc)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
// Block index
|
||||
const int bx = blockIdx.x + OffsetXBlocks;
|
||||
const int by = blockIdx.y + OffsetYBlocks;
|
||||
|
||||
// Thread index (current coefficient)
|
||||
const int tx = threadIdx.x;
|
||||
const int ty = threadIdx.y;
|
||||
// Thread index (current coefficient)
|
||||
const int tx = threadIdx.x;
|
||||
const int ty = threadIdx.y;
|
||||
|
||||
// Texture coordinates
|
||||
const float tex_x = (float)((bx << BLOCK_SIZE_LOG2) + tx) + 0.5f;
|
||||
const float tex_y = (float)((by << BLOCK_SIZE_LOG2) + ty) + 0.5f;
|
||||
// Texture coordinates
|
||||
const float tex_x = (float)((bx << BLOCK_SIZE_LOG2) + tx) + 0.5f;
|
||||
const float tex_y = (float)((by << BLOCK_SIZE_LOG2) + ty) + 0.5f;
|
||||
|
||||
// copy current image pixel to the first block
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] =
|
||||
tex2D<float>(TexSrc, tex_x, tex_y);
|
||||
// copy current image pixel to the first block
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] = tex2D<float>(TexSrc, tex_x, tex_y);
|
||||
|
||||
// synchronize threads to make sure the block is copied
|
||||
cg::sync(cta);
|
||||
// synchronize threads to make sure the block is copied
|
||||
cg::sync(cta);
|
||||
|
||||
// calculate the multiplication of DCTv8matrixT * A and place it in the second
|
||||
// block
|
||||
float curelem = 0;
|
||||
int DCTv8matrixIndex = 0 * BLOCK_SIZE + ty;
|
||||
int CurBlockLocal1Index = 0 * BLOCK_SIZE + tx;
|
||||
// calculate the multiplication of DCTv8matrixT * A and place it in the second
|
||||
// block
|
||||
float curelem = 0;
|
||||
int DCTv8matrixIndex = 0 * BLOCK_SIZE + ty;
|
||||
int CurBlockLocal1Index = 0 * BLOCK_SIZE + tx;
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem +=
|
||||
DCTv8matrix[DCTv8matrixIndex] * CurBlockLocal1[CurBlockLocal1Index];
|
||||
DCTv8matrixIndex += BLOCK_SIZE;
|
||||
CurBlockLocal1Index += BLOCK_SIZE;
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem += DCTv8matrix[DCTv8matrixIndex] * CurBlockLocal1[CurBlockLocal1Index];
|
||||
DCTv8matrixIndex += BLOCK_SIZE;
|
||||
CurBlockLocal1Index += BLOCK_SIZE;
|
||||
}
|
||||
|
||||
CurBlockLocal2[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
CurBlockLocal2[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
|
||||
// synchronize threads to make sure the first 2 matrices are multiplied and
|
||||
// the result is stored in the second block
|
||||
cg::sync(cta);
|
||||
// synchronize threads to make sure the first 2 matrices are multiplied and
|
||||
// the result is stored in the second block
|
||||
cg::sync(cta);
|
||||
|
||||
// calculate the multiplication of (DCTv8matrixT * A) * DCTv8matrix and place
|
||||
// it in the first block
|
||||
curelem = 0;
|
||||
int CurBlockLocal2Index = (ty << BLOCK_SIZE_LOG2) + 0;
|
||||
DCTv8matrixIndex = 0 * BLOCK_SIZE + tx;
|
||||
// calculate the multiplication of (DCTv8matrixT * A) * DCTv8matrix and place
|
||||
// it in the first block
|
||||
curelem = 0;
|
||||
int CurBlockLocal2Index = (ty << BLOCK_SIZE_LOG2) + 0;
|
||||
DCTv8matrixIndex = 0 * BLOCK_SIZE + tx;
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem +=
|
||||
CurBlockLocal2[CurBlockLocal2Index] * DCTv8matrix[DCTv8matrixIndex];
|
||||
CurBlockLocal2Index += 1;
|
||||
DCTv8matrixIndex += BLOCK_SIZE;
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem += CurBlockLocal2[CurBlockLocal2Index] * DCTv8matrix[DCTv8matrixIndex];
|
||||
CurBlockLocal2Index += 1;
|
||||
DCTv8matrixIndex += BLOCK_SIZE;
|
||||
}
|
||||
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
|
||||
// synchronize threads to make sure the matrices are multiplied and the result
|
||||
// is stored back in the first block
|
||||
cg::sync(cta);
|
||||
// synchronize threads to make sure the matrices are multiplied and the result
|
||||
// is stored back in the first block
|
||||
cg::sync(cta);
|
||||
|
||||
// copy current coefficient to its place in the result array
|
||||
Dst[FMUL(((by << BLOCK_SIZE_LOG2) + ty), ImgWidth) +
|
||||
((bx << BLOCK_SIZE_LOG2) + tx)] =
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx];
|
||||
// copy current coefficient to its place in the result array
|
||||
Dst[FMUL(((by << BLOCK_SIZE_LOG2) + ty), ImgWidth) + ((bx << BLOCK_SIZE_LOG2) + tx)] =
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,71 +165,68 @@ __global__ void CUDAkernel1DCT(float *Dst, int ImgWidth, int OffsetXBlocks,
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__global__ void CUDAkernel1IDCT(float *Dst, int ImgWidth, int OffsetXBlocks,
|
||||
int OffsetYBlocks, cudaTextureObject_t TexSrc) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
// Block index
|
||||
int bx = blockIdx.x + OffsetXBlocks;
|
||||
int by = blockIdx.y + OffsetYBlocks;
|
||||
__global__ void
|
||||
CUDAkernel1IDCT(float *Dst, int ImgWidth, int OffsetXBlocks, int OffsetYBlocks, cudaTextureObject_t TexSrc)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
// Block index
|
||||
int bx = blockIdx.x + OffsetXBlocks;
|
||||
int by = blockIdx.y + OffsetYBlocks;
|
||||
|
||||
// Thread index (current image pixel)
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
// Thread index (current image pixel)
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
|
||||
// Texture coordinates
|
||||
const float tex_x = (float)((bx << BLOCK_SIZE_LOG2) + tx) + 0.5f;
|
||||
const float tex_y = (float)((by << BLOCK_SIZE_LOG2) + ty) + 0.5f;
|
||||
// Texture coordinates
|
||||
const float tex_x = (float)((bx << BLOCK_SIZE_LOG2) + tx) + 0.5f;
|
||||
const float tex_y = (float)((by << BLOCK_SIZE_LOG2) + ty) + 0.5f;
|
||||
|
||||
// copy current image pixel to the first block
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] =
|
||||
tex2D<float>(TexSrc, tex_x, tex_y);
|
||||
// copy current image pixel to the first block
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] = tex2D<float>(TexSrc, tex_x, tex_y);
|
||||
|
||||
// synchronize threads to make sure the block is copied
|
||||
cg::sync(cta);
|
||||
// synchronize threads to make sure the block is copied
|
||||
cg::sync(cta);
|
||||
|
||||
// calculate the multiplication of DCTv8matrix * A and place it in the second
|
||||
// block
|
||||
float curelem = 0;
|
||||
int DCTv8matrixIndex = (ty << BLOCK_SIZE_LOG2) + 0;
|
||||
int CurBlockLocal1Index = 0 * BLOCK_SIZE + tx;
|
||||
// calculate the multiplication of DCTv8matrix * A and place it in the second
|
||||
// block
|
||||
float curelem = 0;
|
||||
int DCTv8matrixIndex = (ty << BLOCK_SIZE_LOG2) + 0;
|
||||
int CurBlockLocal1Index = 0 * BLOCK_SIZE + tx;
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem +=
|
||||
DCTv8matrix[DCTv8matrixIndex] * CurBlockLocal1[CurBlockLocal1Index];
|
||||
DCTv8matrixIndex += 1;
|
||||
CurBlockLocal1Index += BLOCK_SIZE;
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem += DCTv8matrix[DCTv8matrixIndex] * CurBlockLocal1[CurBlockLocal1Index];
|
||||
DCTv8matrixIndex += 1;
|
||||
CurBlockLocal1Index += BLOCK_SIZE;
|
||||
}
|
||||
|
||||
CurBlockLocal2[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
CurBlockLocal2[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
|
||||
// synchronize threads to make sure the first 2 matrices are multiplied and
|
||||
// the result is stored in the second block
|
||||
cg::sync(cta);
|
||||
// synchronize threads to make sure the first 2 matrices are multiplied and
|
||||
// the result is stored in the second block
|
||||
cg::sync(cta);
|
||||
|
||||
// calculate the multiplication of (DCTv8matrix * A) * DCTv8matrixT and place
|
||||
// it in the first block
|
||||
curelem = 0;
|
||||
int CurBlockLocal2Index = (ty << BLOCK_SIZE_LOG2) + 0;
|
||||
DCTv8matrixIndex = (tx << BLOCK_SIZE_LOG2) + 0;
|
||||
// calculate the multiplication of (DCTv8matrix * A) * DCTv8matrixT and place
|
||||
// it in the first block
|
||||
curelem = 0;
|
||||
int CurBlockLocal2Index = (ty << BLOCK_SIZE_LOG2) + 0;
|
||||
DCTv8matrixIndex = (tx << BLOCK_SIZE_LOG2) + 0;
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem +=
|
||||
CurBlockLocal2[CurBlockLocal2Index] * DCTv8matrix[DCTv8matrixIndex];
|
||||
CurBlockLocal2Index += 1;
|
||||
DCTv8matrixIndex += 1;
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++) {
|
||||
curelem += CurBlockLocal2[CurBlockLocal2Index] * DCTv8matrix[DCTv8matrixIndex];
|
||||
CurBlockLocal2Index += 1;
|
||||
DCTv8matrixIndex += 1;
|
||||
}
|
||||
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx] = curelem;
|
||||
|
||||
// synchronize threads to make sure the matrices are multiplied and the result
|
||||
// is stored back in the first block
|
||||
cg::sync(cta);
|
||||
// synchronize threads to make sure the matrices are multiplied and the result
|
||||
// is stored back in the first block
|
||||
cg::sync(cta);
|
||||
|
||||
// copy current coefficient to its place in the result array
|
||||
Dst[FMUL(((by << BLOCK_SIZE_LOG2) + ty), ImgWidth) +
|
||||
((bx << BLOCK_SIZE_LOG2) + tx)] =
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx];
|
||||
// copy current coefficient to its place in the result array
|
||||
Dst[FMUL(((by << BLOCK_SIZE_LOG2) + ty), ImgWidth) + ((bx << BLOCK_SIZE_LOG2) + tx)] =
|
||||
CurBlockLocal1[(ty << BLOCK_SIZE_LOG2) + tx];
|
||||
}
|
||||
|
||||
@@ -47,41 +47,41 @@ namespace cg = cooperative_groups;
|
||||
#include "Common.h"
|
||||
|
||||
// Used in forward and inverse DCT
|
||||
#define C_a 1.387039845322148f //!< a = (2^0.5) * cos( pi / 16);
|
||||
#define C_b 1.306562964876377f //!< b = (2^0.5) * cos( pi / 8);
|
||||
#define C_c 1.175875602419359f //!< c = (2^0.5) * cos(3 * pi / 16);
|
||||
#define C_d 0.785694958387102f //!< d = (2^0.5) * cos(5 * pi / 16);
|
||||
#define C_e 0.541196100146197f //!< e = (2^0.5) * cos(3 * pi / 8);
|
||||
#define C_f 0.275899379282943f //!< f = (2^0.5) * cos(7 * pi / 16);
|
||||
#define C_a 1.387039845322148f //!< a = (2^0.5) * cos( pi / 16);
|
||||
#define C_b 1.306562964876377f //!< b = (2^0.5) * cos( pi / 8);
|
||||
#define C_c 1.175875602419359f //!< c = (2^0.5) * cos(3 * pi / 16);
|
||||
#define C_d 0.785694958387102f //!< d = (2^0.5) * cos(5 * pi / 16);
|
||||
#define C_e 0.541196100146197f //!< e = (2^0.5) * cos(3 * pi / 8);
|
||||
#define C_f 0.275899379282943f //!< f = (2^0.5) * cos(7 * pi / 16);
|
||||
|
||||
/**
|
||||
* Normalization constant that is used in forward and inverse DCT
|
||||
*/
|
||||
#define C_norm 0.3535533905932737f // 1 / (8^0.5)
|
||||
* Normalization constant that is used in forward and inverse DCT
|
||||
*/
|
||||
#define C_norm 0.3535533905932737f // 1 / (8^0.5)
|
||||
|
||||
/**
|
||||
* Width of data block (2nd kernel)
|
||||
*/
|
||||
* Width of data block (2nd kernel)
|
||||
*/
|
||||
#define KER2_BLOCK_WIDTH 32
|
||||
|
||||
/**
|
||||
* Height of data block (2nd kernel)
|
||||
*/
|
||||
* Height of data block (2nd kernel)
|
||||
*/
|
||||
#define KER2_BLOCK_HEIGHT 16
|
||||
|
||||
/**
|
||||
* LOG2 of width of data block (2nd kernel)
|
||||
*/
|
||||
* LOG2 of width of data block (2nd kernel)
|
||||
*/
|
||||
#define KER2_BW_LOG2 5
|
||||
|
||||
/**
|
||||
* LOG2 of height of data block (2nd kernel)
|
||||
*/
|
||||
* LOG2 of height of data block (2nd kernel)
|
||||
*/
|
||||
#define KER2_BH_LOG2 4
|
||||
|
||||
/**
|
||||
* Stride of shared memory buffer (2nd kernel)
|
||||
*/
|
||||
* Stride of shared memory buffer (2nd kernel)
|
||||
*/
|
||||
#define KER2_SMEMBLOCK_STRIDE (KER2_BLOCK_WIDTH + 1)
|
||||
|
||||
/**
|
||||
@@ -93,39 +93,40 @@ namespace cg = cooperative_groups;
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__device__ void CUDAsubroutineInplaceDCTvector(float *Vect0, int Step) {
|
||||
float *Vect1 = Vect0 + Step;
|
||||
float *Vect2 = Vect1 + Step;
|
||||
float *Vect3 = Vect2 + Step;
|
||||
float *Vect4 = Vect3 + Step;
|
||||
float *Vect5 = Vect4 + Step;
|
||||
float *Vect6 = Vect5 + Step;
|
||||
float *Vect7 = Vect6 + Step;
|
||||
__device__ void CUDAsubroutineInplaceDCTvector(float *Vect0, int Step)
|
||||
{
|
||||
float *Vect1 = Vect0 + Step;
|
||||
float *Vect2 = Vect1 + Step;
|
||||
float *Vect3 = Vect2 + Step;
|
||||
float *Vect4 = Vect3 + Step;
|
||||
float *Vect5 = Vect4 + Step;
|
||||
float *Vect6 = Vect5 + Step;
|
||||
float *Vect7 = Vect6 + Step;
|
||||
|
||||
float X07P = (*Vect0) + (*Vect7);
|
||||
float X16P = (*Vect1) + (*Vect6);
|
||||
float X25P = (*Vect2) + (*Vect5);
|
||||
float X34P = (*Vect3) + (*Vect4);
|
||||
float X07P = (*Vect0) + (*Vect7);
|
||||
float X16P = (*Vect1) + (*Vect6);
|
||||
float X25P = (*Vect2) + (*Vect5);
|
||||
float X34P = (*Vect3) + (*Vect4);
|
||||
|
||||
float X07M = (*Vect0) - (*Vect7);
|
||||
float X61M = (*Vect6) - (*Vect1);
|
||||
float X25M = (*Vect2) - (*Vect5);
|
||||
float X43M = (*Vect4) - (*Vect3);
|
||||
float X07M = (*Vect0) - (*Vect7);
|
||||
float X61M = (*Vect6) - (*Vect1);
|
||||
float X25M = (*Vect2) - (*Vect5);
|
||||
float X43M = (*Vect4) - (*Vect3);
|
||||
|
||||
float X07P34PP = X07P + X34P;
|
||||
float X07P34PM = X07P - X34P;
|
||||
float X16P25PP = X16P + X25P;
|
||||
float X16P25PM = X16P - X25P;
|
||||
float X07P34PP = X07P + X34P;
|
||||
float X07P34PM = X07P - X34P;
|
||||
float X16P25PP = X16P + X25P;
|
||||
float X16P25PM = X16P - X25P;
|
||||
|
||||
(*Vect0) = C_norm * (X07P34PP + X16P25PP);
|
||||
(*Vect2) = C_norm * (C_b * X07P34PM + C_e * X16P25PM);
|
||||
(*Vect4) = C_norm * (X07P34PP - X16P25PP);
|
||||
(*Vect6) = C_norm * (C_e * X07P34PM - C_b * X16P25PM);
|
||||
(*Vect0) = C_norm * (X07P34PP + X16P25PP);
|
||||
(*Vect2) = C_norm * (C_b * X07P34PM + C_e * X16P25PM);
|
||||
(*Vect4) = C_norm * (X07P34PP - X16P25PP);
|
||||
(*Vect6) = C_norm * (C_e * X07P34PM - C_b * X16P25PM);
|
||||
|
||||
(*Vect1) = C_norm * (C_a * X07M - C_c * X61M + C_d * X25M - C_f * X43M);
|
||||
(*Vect3) = C_norm * (C_c * X07M + C_f * X61M - C_a * X25M + C_d * X43M);
|
||||
(*Vect5) = C_norm * (C_d * X07M + C_a * X61M + C_f * X25M - C_c * X43M);
|
||||
(*Vect7) = C_norm * (C_f * X07M + C_d * X61M + C_c * X25M + C_a * X43M);
|
||||
(*Vect1) = C_norm * (C_a * X07M - C_c * X61M + C_d * X25M - C_f * X43M);
|
||||
(*Vect3) = C_norm * (C_c * X07M + C_f * X61M - C_a * X25M + C_d * X43M);
|
||||
(*Vect5) = C_norm * (C_d * X07M + C_a * X61M + C_f * X25M - C_c * X43M);
|
||||
(*Vect7) = C_norm * (C_f * X07M + C_d * X61M + C_c * X25M + C_a * X43M);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,44 +138,41 @@ __device__ void CUDAsubroutineInplaceDCTvector(float *Vect0, int Step) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__device__ void CUDAsubroutineInplaceIDCTvector(float *Vect0, int Step) {
|
||||
float *Vect1 = Vect0 + Step;
|
||||
float *Vect2 = Vect1 + Step;
|
||||
float *Vect3 = Vect2 + Step;
|
||||
float *Vect4 = Vect3 + Step;
|
||||
float *Vect5 = Vect4 + Step;
|
||||
float *Vect6 = Vect5 + Step;
|
||||
float *Vect7 = Vect6 + Step;
|
||||
__device__ void CUDAsubroutineInplaceIDCTvector(float *Vect0, int Step)
|
||||
{
|
||||
float *Vect1 = Vect0 + Step;
|
||||
float *Vect2 = Vect1 + Step;
|
||||
float *Vect3 = Vect2 + Step;
|
||||
float *Vect4 = Vect3 + Step;
|
||||
float *Vect5 = Vect4 + Step;
|
||||
float *Vect6 = Vect5 + Step;
|
||||
float *Vect7 = Vect6 + Step;
|
||||
|
||||
float Y04P = (*Vect0) + (*Vect4);
|
||||
float Y2b6eP = C_b * (*Vect2) + C_e * (*Vect6);
|
||||
float Y04P = (*Vect0) + (*Vect4);
|
||||
float Y2b6eP = C_b * (*Vect2) + C_e * (*Vect6);
|
||||
|
||||
float Y04P2b6ePP = Y04P + Y2b6eP;
|
||||
float Y04P2b6ePM = Y04P - Y2b6eP;
|
||||
float Y7f1aP3c5dPP =
|
||||
C_f * (*Vect7) + C_a * (*Vect1) + C_c * (*Vect3) + C_d * (*Vect5);
|
||||
float Y7a1fM3d5cMP =
|
||||
C_a * (*Vect7) - C_f * (*Vect1) + C_d * (*Vect3) - C_c * (*Vect5);
|
||||
float Y04P2b6ePP = Y04P + Y2b6eP;
|
||||
float Y04P2b6ePM = Y04P - Y2b6eP;
|
||||
float Y7f1aP3c5dPP = C_f * (*Vect7) + C_a * (*Vect1) + C_c * (*Vect3) + C_d * (*Vect5);
|
||||
float Y7a1fM3d5cMP = C_a * (*Vect7) - C_f * (*Vect1) + C_d * (*Vect3) - C_c * (*Vect5);
|
||||
|
||||
float Y04M = (*Vect0) - (*Vect4);
|
||||
float Y2e6bM = C_e * (*Vect2) - C_b * (*Vect6);
|
||||
float Y04M = (*Vect0) - (*Vect4);
|
||||
float Y2e6bM = C_e * (*Vect2) - C_b * (*Vect6);
|
||||
|
||||
float Y04M2e6bMP = Y04M + Y2e6bM;
|
||||
float Y04M2e6bMM = Y04M - Y2e6bM;
|
||||
float Y1c7dM3f5aPM =
|
||||
C_c * (*Vect1) - C_d * (*Vect7) - C_f * (*Vect3) - C_a * (*Vect5);
|
||||
float Y1d7cP3a5fMM =
|
||||
C_d * (*Vect1) + C_c * (*Vect7) - C_a * (*Vect3) + C_f * (*Vect5);
|
||||
float Y04M2e6bMP = Y04M + Y2e6bM;
|
||||
float Y04M2e6bMM = Y04M - Y2e6bM;
|
||||
float Y1c7dM3f5aPM = C_c * (*Vect1) - C_d * (*Vect7) - C_f * (*Vect3) - C_a * (*Vect5);
|
||||
float Y1d7cP3a5fMM = C_d * (*Vect1) + C_c * (*Vect7) - C_a * (*Vect3) + C_f * (*Vect5);
|
||||
|
||||
(*Vect0) = C_norm * (Y04P2b6ePP + Y7f1aP3c5dPP);
|
||||
(*Vect7) = C_norm * (Y04P2b6ePP - Y7f1aP3c5dPP);
|
||||
(*Vect4) = C_norm * (Y04P2b6ePM + Y7a1fM3d5cMP);
|
||||
(*Vect3) = C_norm * (Y04P2b6ePM - Y7a1fM3d5cMP);
|
||||
(*Vect0) = C_norm * (Y04P2b6ePP + Y7f1aP3c5dPP);
|
||||
(*Vect7) = C_norm * (Y04P2b6ePP - Y7f1aP3c5dPP);
|
||||
(*Vect4) = C_norm * (Y04P2b6ePM + Y7a1fM3d5cMP);
|
||||
(*Vect3) = C_norm * (Y04P2b6ePM - Y7a1fM3d5cMP);
|
||||
|
||||
(*Vect1) = C_norm * (Y04M2e6bMP + Y1c7dM3f5aPM);
|
||||
(*Vect5) = C_norm * (Y04M2e6bMM - Y1d7cP3a5fMM);
|
||||
(*Vect2) = C_norm * (Y04M2e6bMM + Y1d7cP3a5fMM);
|
||||
(*Vect6) = C_norm * (Y04M2e6bMP - Y1c7dM3f5aPM);
|
||||
(*Vect1) = C_norm * (Y04M2e6bMP + Y1c7dM3f5aPM);
|
||||
(*Vect5) = C_norm * (Y04M2e6bMM - Y1d7cP3a5fMM);
|
||||
(*Vect2) = C_norm * (Y04M2e6bMM + Y1d7cP3a5fMM);
|
||||
(*Vect6) = C_norm * (Y04M2e6bMP - Y1c7dM3f5aPM);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,40 +190,38 @@ __device__ void CUDAsubroutineInplaceIDCTvector(float *Vect0, int Step) {
|
||||
* \return None
|
||||
*/
|
||||
|
||||
__global__ void CUDAkernel2DCT(float *dst, float *src, int ImgStride) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
__global__ void CUDAkernel2DCT(float *dst, float *src, int ImgStride)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
|
||||
__shared__ float block[KER2_BLOCK_HEIGHT * KER2_SMEMBLOCK_STRIDE];
|
||||
__shared__ float block[KER2_BLOCK_HEIGHT * KER2_SMEMBLOCK_STRIDE];
|
||||
|
||||
int OffsThreadInRow = threadIdx.y * BLOCK_SIZE + threadIdx.x;
|
||||
int OffsThreadInCol = threadIdx.z * BLOCK_SIZE;
|
||||
src += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) +
|
||||
blockIdx.x * KER2_BLOCK_WIDTH + OffsThreadInRow;
|
||||
dst += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) +
|
||||
blockIdx.x * KER2_BLOCK_WIDTH + OffsThreadInRow;
|
||||
float *bl_ptr =
|
||||
block + OffsThreadInCol * KER2_SMEMBLOCK_STRIDE + OffsThreadInRow;
|
||||
int OffsThreadInRow = threadIdx.y * BLOCK_SIZE + threadIdx.x;
|
||||
int OffsThreadInCol = threadIdx.z * BLOCK_SIZE;
|
||||
src += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) + blockIdx.x * KER2_BLOCK_WIDTH
|
||||
+ OffsThreadInRow;
|
||||
dst += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) + blockIdx.x * KER2_BLOCK_WIDTH
|
||||
+ OffsThreadInRow;
|
||||
float *bl_ptr = block + OffsThreadInCol * KER2_SMEMBLOCK_STRIDE + OffsThreadInRow;
|
||||
|
||||
#pragma unroll
|
||||
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
bl_ptr[i * KER2_SMEMBLOCK_STRIDE] = src[i * ImgStride];
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
bl_ptr[i * KER2_SMEMBLOCK_STRIDE] = src[i * ImgStride];
|
||||
|
||||
cg::sync(cta);
|
||||
// process rows
|
||||
CUDAsubroutineInplaceDCTvector(
|
||||
block + (OffsThreadInCol + threadIdx.x) * KER2_SMEMBLOCK_STRIDE +
|
||||
OffsThreadInRow - threadIdx.x,
|
||||
1);
|
||||
cg::sync(cta);
|
||||
// process rows
|
||||
CUDAsubroutineInplaceDCTvector(
|
||||
block + (OffsThreadInCol + threadIdx.x) * KER2_SMEMBLOCK_STRIDE + OffsThreadInRow - threadIdx.x, 1);
|
||||
|
||||
cg::sync(cta);
|
||||
// process columns
|
||||
CUDAsubroutineInplaceDCTvector(bl_ptr, KER2_SMEMBLOCK_STRIDE);
|
||||
cg::sync(cta);
|
||||
// process columns
|
||||
CUDAsubroutineInplaceDCTvector(bl_ptr, KER2_SMEMBLOCK_STRIDE);
|
||||
|
||||
cg::sync(cta);
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
dst[i * ImgStride] = bl_ptr[i * KER2_SMEMBLOCK_STRIDE];
|
||||
cg::sync(cta);
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
dst[i * ImgStride] = bl_ptr[i * KER2_SMEMBLOCK_STRIDE];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,39 +238,37 @@ __global__ void CUDAkernel2DCT(float *dst, float *src, int ImgStride) {
|
||||
* \return None
|
||||
*/
|
||||
|
||||
__global__ void CUDAkernel2IDCT(float *dst, float *src, int ImgStride) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
__global__ void CUDAkernel2IDCT(float *dst, float *src, int ImgStride)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
|
||||
__shared__ float block[KER2_BLOCK_HEIGHT * KER2_SMEMBLOCK_STRIDE];
|
||||
__shared__ float block[KER2_BLOCK_HEIGHT * KER2_SMEMBLOCK_STRIDE];
|
||||
|
||||
int OffsThreadInRow = threadIdx.y * BLOCK_SIZE + threadIdx.x;
|
||||
int OffsThreadInCol = threadIdx.z * BLOCK_SIZE;
|
||||
src += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) +
|
||||
blockIdx.x * KER2_BLOCK_WIDTH + OffsThreadInRow;
|
||||
dst += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) +
|
||||
blockIdx.x * KER2_BLOCK_WIDTH + OffsThreadInRow;
|
||||
float *bl_ptr =
|
||||
block + OffsThreadInCol * KER2_SMEMBLOCK_STRIDE + OffsThreadInRow;
|
||||
int OffsThreadInRow = threadIdx.y * BLOCK_SIZE + threadIdx.x;
|
||||
int OffsThreadInCol = threadIdx.z * BLOCK_SIZE;
|
||||
src += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) + blockIdx.x * KER2_BLOCK_WIDTH
|
||||
+ OffsThreadInRow;
|
||||
dst += FMUL(blockIdx.y * KER2_BLOCK_HEIGHT + OffsThreadInCol, ImgStride) + blockIdx.x * KER2_BLOCK_WIDTH
|
||||
+ OffsThreadInRow;
|
||||
float *bl_ptr = block + OffsThreadInCol * KER2_SMEMBLOCK_STRIDE + OffsThreadInRow;
|
||||
|
||||
#pragma unroll
|
||||
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
bl_ptr[i * KER2_SMEMBLOCK_STRIDE] = src[i * ImgStride];
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
bl_ptr[i * KER2_SMEMBLOCK_STRIDE] = src[i * ImgStride];
|
||||
|
||||
cg::sync(cta);
|
||||
// process rows
|
||||
CUDAsubroutineInplaceIDCTvector(
|
||||
block + (OffsThreadInCol + threadIdx.x) * KER2_SMEMBLOCK_STRIDE +
|
||||
OffsThreadInRow - threadIdx.x,
|
||||
1);
|
||||
cg::sync(cta);
|
||||
// process rows
|
||||
CUDAsubroutineInplaceIDCTvector(
|
||||
block + (OffsThreadInCol + threadIdx.x) * KER2_SMEMBLOCK_STRIDE + OffsThreadInRow - threadIdx.x, 1);
|
||||
|
||||
cg::sync(cta);
|
||||
// process columns
|
||||
CUDAsubroutineInplaceIDCTvector(bl_ptr, KER2_SMEMBLOCK_STRIDE);
|
||||
cg::sync(cta);
|
||||
// process columns
|
||||
CUDAsubroutineInplaceIDCTvector(bl_ptr, KER2_SMEMBLOCK_STRIDE);
|
||||
|
||||
cg::sync(cta);
|
||||
cg::sync(cta);
|
||||
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
dst[i * ImgStride] = bl_ptr[i * KER2_SMEMBLOCK_STRIDE];
|
||||
for (unsigned int i = 0; i < BLOCK_SIZE; i++)
|
||||
dst[i * ImgStride] = bl_ptr[i * KER2_SMEMBLOCK_STRIDE];
|
||||
}
|
||||
|
||||
@@ -41,18 +41,11 @@ namespace cg = cooperative_groups;
|
||||
#include "Common.h"
|
||||
|
||||
/**
|
||||
* JPEG quality=0_of_12 quantization matrix
|
||||
*/
|
||||
__constant__ short Q[] = {
|
||||
32, 33, 51, 81, 66, 39, 34, 17,
|
||||
33, 36, 48, 47, 28, 23, 12, 12,
|
||||
51, 48, 47, 28, 23, 12, 12, 12,
|
||||
81, 47, 28, 23, 12, 12, 12, 12,
|
||||
66, 28, 23, 12, 12, 12, 12, 12,
|
||||
39, 23, 12, 12, 12, 12, 12, 12,
|
||||
34, 12, 12, 12, 12, 12, 12, 12,
|
||||
17, 12, 12, 12, 12, 12, 12, 12
|
||||
};
|
||||
* JPEG quality=0_of_12 quantization matrix
|
||||
*/
|
||||
__constant__ short Q[] = {32, 33, 51, 81, 66, 39, 34, 17, 33, 36, 48, 47, 28, 23, 12, 12, 51, 48, 47, 28, 23, 12,
|
||||
12, 12, 81, 47, 28, 23, 12, 12, 12, 12, 66, 28, 23, 12, 12, 12, 12, 12, 39, 23, 12, 12,
|
||||
12, 12, 12, 12, 34, 12, 12, 12, 12, 12, 12, 12, 17, 12, 12, 12, 12, 12, 12, 12};
|
||||
|
||||
/**
|
||||
**************************************************************************
|
||||
@@ -64,26 +57,26 @@ __constant__ short Q[] = {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__global__ void CUDAkernelQuantizationFloat(float *SrcDst, int Stride) {
|
||||
// Block index
|
||||
int bx = blockIdx.x;
|
||||
int by = blockIdx.y;
|
||||
__global__ void CUDAkernelQuantizationFloat(float *SrcDst, int Stride)
|
||||
{
|
||||
// Block index
|
||||
int bx = blockIdx.x;
|
||||
int by = blockIdx.y;
|
||||
|
||||
// Thread index (current coefficient)
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
// Thread index (current coefficient)
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
|
||||
// copy current coefficient to the local variable
|
||||
float curCoef =
|
||||
SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)];
|
||||
float curQuant = (float)Q[ty * BLOCK_SIZE + tx];
|
||||
// copy current coefficient to the local variable
|
||||
float curCoef = SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)];
|
||||
float curQuant = (float)Q[ty * BLOCK_SIZE + tx];
|
||||
|
||||
// quantize the current coefficient
|
||||
float quantized = roundf(curCoef / curQuant);
|
||||
curCoef = quantized * curQuant;
|
||||
// quantize the current coefficient
|
||||
float quantized = roundf(curCoef / curQuant);
|
||||
curCoef = quantized * curQuant;
|
||||
|
||||
// copy quantized coefficient back to the DCT-plane
|
||||
SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)] = curCoef;
|
||||
// copy quantized coefficient back to the DCT-plane
|
||||
SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)] = curCoef;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,37 +89,38 @@ __global__ void CUDAkernelQuantizationFloat(float *SrcDst, int Stride) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__global__ void CUDAkernelQuantizationShort(short *SrcDst, int Stride) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
// Block index
|
||||
int bx = blockIdx.x;
|
||||
int by = blockIdx.y;
|
||||
__global__ void CUDAkernelQuantizationShort(short *SrcDst, int Stride)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
// Block index
|
||||
int bx = blockIdx.x;
|
||||
int by = blockIdx.y;
|
||||
|
||||
// Thread index (current coefficient)
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
// Thread index (current coefficient)
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
|
||||
// copy current coefficient to the local variable
|
||||
short curCoef =
|
||||
SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)];
|
||||
short curQuant = Q[ty * BLOCK_SIZE + tx];
|
||||
// copy current coefficient to the local variable
|
||||
short curCoef = SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)];
|
||||
short curQuant = Q[ty * BLOCK_SIZE + tx];
|
||||
|
||||
// quantize the current coefficient
|
||||
if (curCoef < 0) {
|
||||
curCoef = -curCoef;
|
||||
curCoef += curQuant >> 1;
|
||||
curCoef /= curQuant;
|
||||
curCoef = -curCoef;
|
||||
} else {
|
||||
curCoef += curQuant >> 1;
|
||||
curCoef /= curQuant;
|
||||
}
|
||||
// quantize the current coefficient
|
||||
if (curCoef < 0) {
|
||||
curCoef = -curCoef;
|
||||
curCoef += curQuant >> 1;
|
||||
curCoef /= curQuant;
|
||||
curCoef = -curCoef;
|
||||
}
|
||||
else {
|
||||
curCoef += curQuant >> 1;
|
||||
curCoef /= curQuant;
|
||||
}
|
||||
|
||||
cg::sync(cta);
|
||||
cg::sync(cta);
|
||||
|
||||
curCoef = curCoef * curQuant;
|
||||
curCoef = curCoef * curQuant;
|
||||
|
||||
// copy quantized coefficient back to the DCT-plane
|
||||
SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)] = curCoef;
|
||||
// copy quantized coefficient back to the DCT-plane
|
||||
SrcDst[(by * BLOCK_SIZE + ty) * Stride + (bx * BLOCK_SIZE + tx)] = curCoef;
|
||||
}
|
||||
|
||||
@@ -46,33 +46,33 @@ namespace cg = cooperative_groups;
|
||||
#include "Common.h"
|
||||
|
||||
/**
|
||||
* Width of data block (short kernel)
|
||||
*/
|
||||
* Width of data block (short kernel)
|
||||
*/
|
||||
#define KERS_BLOCK_WIDTH 32
|
||||
|
||||
/**
|
||||
* Height of data block (short kernel)
|
||||
*/
|
||||
* Height of data block (short kernel)
|
||||
*/
|
||||
#define KERS_BLOCK_HEIGHT 32
|
||||
|
||||
/**
|
||||
* LOG2 of width of data block (short kernel)
|
||||
*/
|
||||
* LOG2 of width of data block (short kernel)
|
||||
*/
|
||||
#define KERS_BW_LOG2 5
|
||||
|
||||
/**
|
||||
* LOG2 of height of data block (short kernel)
|
||||
*/
|
||||
* LOG2 of height of data block (short kernel)
|
||||
*/
|
||||
#define KERS_BH_LOG2 5
|
||||
|
||||
/**
|
||||
* Stride of shared memory buffer (short kernel)
|
||||
*/
|
||||
* Stride of shared memory buffer (short kernel)
|
||||
*/
|
||||
#define KERS_SMEMBLOCK_STRIDE (KERS_BLOCK_WIDTH + 2)
|
||||
|
||||
/**
|
||||
* Half of data block width (short kernel)
|
||||
*/
|
||||
* Half of data block width (short kernel)
|
||||
*/
|
||||
#define KERS_BLOCK_WIDTH_HALF (KERS_BLOCK_WIDTH / 2)
|
||||
|
||||
#define SIN_1_4 0x5A82
|
||||
@@ -91,25 +91,27 @@ namespace cg = cooperative_groups;
|
||||
#define OCOS_7_16 0x063E
|
||||
|
||||
/**
|
||||
* Package of 2 shorts into 1 int - designed to perform i/o by integers to avoid
|
||||
* bank conflicts
|
||||
*/
|
||||
union PackedShorts {
|
||||
struct __align__(8) {
|
||||
short hShort1;
|
||||
short hShort2;
|
||||
};
|
||||
unsigned int hInt;
|
||||
* Package of 2 shorts into 1 int - designed to perform i/o by integers to avoid
|
||||
* bank conflicts
|
||||
*/
|
||||
union PackedShorts
|
||||
{
|
||||
struct __align__(8)
|
||||
{
|
||||
short hShort1;
|
||||
short hShort2;
|
||||
};
|
||||
unsigned int hInt;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts fixed point value to short value
|
||||
*/
|
||||
* Converts fixed point value to short value
|
||||
*/
|
||||
__device__ inline short unfixh(int x) { return (short)((x + 0x8000) >> 16); }
|
||||
|
||||
/**
|
||||
* Converts fixed point value to short value
|
||||
*/
|
||||
* Converts fixed point value to short value
|
||||
*/
|
||||
__device__ inline int unfixo(int x) { return (x + 0x1000) >> 13; }
|
||||
|
||||
/**
|
||||
@@ -122,74 +124,75 @@ __device__ inline int unfixo(int x) { return (x + 0x1000) >> 13; }
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__device__ void CUDAshortInplaceDCT(short *SrcDst, int Stride) {
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp14, tmp15, tmp16, tmp17;
|
||||
int tmp25, tmp26;
|
||||
__device__ void CUDAshortInplaceDCT(short *SrcDst, int Stride)
|
||||
{
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp14, tmp15, tmp16, tmp17;
|
||||
int tmp25, tmp26;
|
||||
|
||||
int DoubleStride = Stride << 1;
|
||||
int DoubleStride = Stride << 1;
|
||||
|
||||
short *DstPtr = SrcDst;
|
||||
in0 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in1 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in2 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in3 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in4 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in5 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in6 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in7 = *DstPtr;
|
||||
short *DstPtr = SrcDst;
|
||||
in0 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in1 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in2 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in3 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in4 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in5 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in6 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in7 = *DstPtr;
|
||||
|
||||
tmp0 = in7 + in0;
|
||||
tmp1 = in6 + in1;
|
||||
tmp2 = in5 + in2;
|
||||
tmp3 = in4 + in3;
|
||||
tmp4 = in3 - in4;
|
||||
tmp5 = in2 - in5;
|
||||
tmp6 = in1 - in6;
|
||||
tmp7 = in0 - in7;
|
||||
tmp0 = in7 + in0;
|
||||
tmp1 = in6 + in1;
|
||||
tmp2 = in5 + in2;
|
||||
tmp3 = in4 + in3;
|
||||
tmp4 = in3 - in4;
|
||||
tmp5 = in2 - in5;
|
||||
tmp6 = in1 - in6;
|
||||
tmp7 = in0 - in7;
|
||||
|
||||
tmp10 = tmp3 + tmp0;
|
||||
tmp11 = tmp2 + tmp1;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
tmp13 = tmp0 - tmp3;
|
||||
tmp10 = tmp3 + tmp0;
|
||||
tmp11 = tmp2 + tmp1;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
tmp13 = tmp0 - tmp3;
|
||||
|
||||
tmp16 = unfixo(FMUL(tmp6 + tmp5, SIN_1_4));
|
||||
tmp15 = unfixo(FMUL(tmp6 - tmp5, COS_1_4));
|
||||
tmp16 = unfixo(FMUL(tmp6 + tmp5, SIN_1_4));
|
||||
tmp15 = unfixo(FMUL(tmp6 - tmp5, COS_1_4));
|
||||
|
||||
tmp4 <<= 2;
|
||||
tmp7 <<= 2;
|
||||
tmp4 <<= 2;
|
||||
tmp7 <<= 2;
|
||||
|
||||
tmp14 = tmp4 + tmp15;
|
||||
tmp25 = tmp4 - tmp15;
|
||||
tmp26 = tmp7 - tmp16;
|
||||
tmp17 = tmp7 + tmp16;
|
||||
tmp14 = tmp4 + tmp15;
|
||||
tmp25 = tmp4 - tmp15;
|
||||
tmp26 = tmp7 - tmp16;
|
||||
tmp17 = tmp7 + tmp16;
|
||||
|
||||
DstPtr = SrcDst;
|
||||
*DstPtr = unfixh(FMUL(tmp10 + tmp11, SIN_1_4));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp13, COS_1_8) + FMUL(tmp12, SIN_1_8));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp10 - tmp11, COS_1_4));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp13, SIN_1_8) - FMUL(tmp12, COS_1_8));
|
||||
DstPtr = SrcDst;
|
||||
*DstPtr = unfixh(FMUL(tmp10 + tmp11, SIN_1_4));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp13, COS_1_8) + FMUL(tmp12, SIN_1_8));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp10 - tmp11, COS_1_4));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp13, SIN_1_8) - FMUL(tmp12, COS_1_8));
|
||||
|
||||
DstPtr = SrcDst + Stride;
|
||||
*DstPtr = unfixh(FMUL(tmp17, OCOS_1_16) + FMUL(tmp14, OSIN_1_16));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp26, OCOS_3_16) - FMUL(tmp25, OSIN_3_16));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp26, OCOS_5_16) + FMUL(tmp25, OSIN_5_16));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp17, OCOS_7_16) - FMUL(tmp14, OSIN_7_16));
|
||||
DstPtr = SrcDst + Stride;
|
||||
*DstPtr = unfixh(FMUL(tmp17, OCOS_1_16) + FMUL(tmp14, OSIN_1_16));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp26, OCOS_3_16) - FMUL(tmp25, OSIN_3_16));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp26, OCOS_5_16) + FMUL(tmp25, OSIN_5_16));
|
||||
DstPtr += DoubleStride;
|
||||
*DstPtr = unfixh(FMUL(tmp17, OCOS_7_16) - FMUL(tmp14, OSIN_7_16));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,67 +204,68 @@ __device__ void CUDAshortInplaceDCT(short *SrcDst, int Stride) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__device__ void CUDAshortInplaceDCT(unsigned int *V8) {
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp14, tmp15, tmp16, tmp17;
|
||||
int tmp25, tmp26;
|
||||
PackedShorts sh0, sh1, sh2, sh3;
|
||||
__device__ void CUDAshortInplaceDCT(unsigned int *V8)
|
||||
{
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp14, tmp15, tmp16, tmp17;
|
||||
int tmp25, tmp26;
|
||||
PackedShorts sh0, sh1, sh2, sh3;
|
||||
|
||||
sh0.hInt = V8[0];
|
||||
sh1.hInt = V8[1];
|
||||
sh2.hInt = V8[2];
|
||||
sh3.hInt = V8[3];
|
||||
in0 = sh0.hShort1;
|
||||
in1 = sh0.hShort2;
|
||||
in2 = sh1.hShort1;
|
||||
in3 = sh1.hShort2;
|
||||
in4 = sh2.hShort1;
|
||||
in5 = sh2.hShort2;
|
||||
in6 = sh3.hShort1;
|
||||
in7 = sh3.hShort2;
|
||||
sh0.hInt = V8[0];
|
||||
sh1.hInt = V8[1];
|
||||
sh2.hInt = V8[2];
|
||||
sh3.hInt = V8[3];
|
||||
in0 = sh0.hShort1;
|
||||
in1 = sh0.hShort2;
|
||||
in2 = sh1.hShort1;
|
||||
in3 = sh1.hShort2;
|
||||
in4 = sh2.hShort1;
|
||||
in5 = sh2.hShort2;
|
||||
in6 = sh3.hShort1;
|
||||
in7 = sh3.hShort2;
|
||||
|
||||
tmp0 = in7 + in0;
|
||||
tmp1 = in6 + in1;
|
||||
tmp2 = in5 + in2;
|
||||
tmp3 = in4 + in3;
|
||||
tmp4 = in3 - in4;
|
||||
tmp5 = in2 - in5;
|
||||
tmp6 = in1 - in6;
|
||||
tmp7 = in0 - in7;
|
||||
tmp0 = in7 + in0;
|
||||
tmp1 = in6 + in1;
|
||||
tmp2 = in5 + in2;
|
||||
tmp3 = in4 + in3;
|
||||
tmp4 = in3 - in4;
|
||||
tmp5 = in2 - in5;
|
||||
tmp6 = in1 - in6;
|
||||
tmp7 = in0 - in7;
|
||||
|
||||
tmp10 = tmp3 + tmp0;
|
||||
tmp11 = tmp2 + tmp1;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
tmp13 = tmp0 - tmp3;
|
||||
tmp10 = tmp3 + tmp0;
|
||||
tmp11 = tmp2 + tmp1;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
tmp13 = tmp0 - tmp3;
|
||||
|
||||
sh0.hShort1 = unfixh(FMUL(tmp10 + tmp11, SIN_1_4));
|
||||
sh2.hShort1 = unfixh(FMUL(tmp10 - tmp11, COS_1_4));
|
||||
sh0.hShort1 = unfixh(FMUL(tmp10 + tmp11, SIN_1_4));
|
||||
sh2.hShort1 = unfixh(FMUL(tmp10 - tmp11, COS_1_4));
|
||||
|
||||
sh1.hShort1 = unfixh(FMUL(tmp13, COS_1_8) + FMUL(tmp12, SIN_1_8));
|
||||
sh3.hShort1 = unfixh(FMUL(tmp13, SIN_1_8) - FMUL(tmp12, COS_1_8));
|
||||
sh1.hShort1 = unfixh(FMUL(tmp13, COS_1_8) + FMUL(tmp12, SIN_1_8));
|
||||
sh3.hShort1 = unfixh(FMUL(tmp13, SIN_1_8) - FMUL(tmp12, COS_1_8));
|
||||
|
||||
tmp16 = unfixo(FMUL(tmp6 + tmp5, SIN_1_4));
|
||||
tmp15 = unfixo(FMUL(tmp6 - tmp5, COS_1_4));
|
||||
tmp16 = unfixo(FMUL(tmp6 + tmp5, SIN_1_4));
|
||||
tmp15 = unfixo(FMUL(tmp6 - tmp5, COS_1_4));
|
||||
|
||||
tmp4 <<= 2;
|
||||
tmp7 <<= 2;
|
||||
tmp4 <<= 2;
|
||||
tmp7 <<= 2;
|
||||
|
||||
tmp14 = tmp4 + tmp15;
|
||||
tmp25 = tmp4 - tmp15;
|
||||
tmp26 = tmp7 - tmp16;
|
||||
tmp17 = tmp7 + tmp16;
|
||||
tmp14 = tmp4 + tmp15;
|
||||
tmp25 = tmp4 - tmp15;
|
||||
tmp26 = tmp7 - tmp16;
|
||||
tmp17 = tmp7 + tmp16;
|
||||
|
||||
sh0.hShort2 = unfixh(FMUL(tmp17, OCOS_1_16) + FMUL(tmp14, OSIN_1_16));
|
||||
sh3.hShort2 = unfixh(FMUL(tmp17, OCOS_7_16) - FMUL(tmp14, OSIN_7_16));
|
||||
sh2.hShort2 = unfixh(FMUL(tmp26, OCOS_5_16) + FMUL(tmp25, OSIN_5_16));
|
||||
sh1.hShort2 = unfixh(FMUL(tmp26, OCOS_3_16) - FMUL(tmp25, OSIN_3_16));
|
||||
sh0.hShort2 = unfixh(FMUL(tmp17, OCOS_1_16) + FMUL(tmp14, OSIN_1_16));
|
||||
sh3.hShort2 = unfixh(FMUL(tmp17, OCOS_7_16) - FMUL(tmp14, OSIN_7_16));
|
||||
sh2.hShort2 = unfixh(FMUL(tmp26, OCOS_5_16) + FMUL(tmp25, OSIN_5_16));
|
||||
sh1.hShort2 = unfixh(FMUL(tmp26, OCOS_3_16) - FMUL(tmp25, OSIN_3_16));
|
||||
|
||||
V8[0] = sh0.hInt;
|
||||
V8[1] = sh1.hInt;
|
||||
V8[2] = sh2.hInt;
|
||||
V8[3] = sh3.hInt;
|
||||
V8[0] = sh0.hInt;
|
||||
V8[1] = sh1.hInt;
|
||||
V8[2] = sh2.hInt;
|
||||
V8[3] = sh3.hInt;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,73 +278,74 @@ __device__ void CUDAshortInplaceDCT(unsigned int *V8) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__device__ void CUDAshortInplaceIDCT(short *SrcDst, int Stride) {
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp20, tmp21, tmp22, tmp23;
|
||||
int tmp30, tmp31;
|
||||
int tmp40, tmp41, tmp42, tmp43;
|
||||
int tmp50, tmp51, tmp52, tmp53;
|
||||
__device__ void CUDAshortInplaceIDCT(short *SrcDst, int Stride)
|
||||
{
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp20, tmp21, tmp22, tmp23;
|
||||
int tmp30, tmp31;
|
||||
int tmp40, tmp41, tmp42, tmp43;
|
||||
int tmp50, tmp51, tmp52, tmp53;
|
||||
|
||||
short *DstPtr = SrcDst;
|
||||
in0 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in1 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in2 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in3 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in4 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in5 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in6 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in7 = *DstPtr;
|
||||
short *DstPtr = SrcDst;
|
||||
in0 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in1 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in2 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in3 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in4 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in5 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in6 = *DstPtr;
|
||||
DstPtr += Stride;
|
||||
in7 = *DstPtr;
|
||||
|
||||
tmp10 = FMUL(in0 + in4, COS_1_4);
|
||||
tmp11 = FMUL(in0 - in4, COS_1_4);
|
||||
tmp12 = FMUL(in2, SIN_1_8) - FMUL(in6, COS_1_8);
|
||||
tmp13 = FMUL(in6, SIN_1_8) + FMUL(in2, COS_1_8);
|
||||
tmp10 = FMUL(in0 + in4, COS_1_4);
|
||||
tmp11 = FMUL(in0 - in4, COS_1_4);
|
||||
tmp12 = FMUL(in2, SIN_1_8) - FMUL(in6, COS_1_8);
|
||||
tmp13 = FMUL(in6, SIN_1_8) + FMUL(in2, COS_1_8);
|
||||
|
||||
tmp20 = tmp10 + tmp13;
|
||||
tmp21 = tmp11 + tmp12;
|
||||
tmp22 = tmp11 - tmp12;
|
||||
tmp23 = tmp10 - tmp13;
|
||||
tmp20 = tmp10 + tmp13;
|
||||
tmp21 = tmp11 + tmp12;
|
||||
tmp22 = tmp11 - tmp12;
|
||||
tmp23 = tmp10 - tmp13;
|
||||
|
||||
tmp30 = unfixo(FMUL(in3 + in5, COS_1_4));
|
||||
tmp31 = unfixo(FMUL(in3 - in5, COS_1_4));
|
||||
tmp30 = unfixo(FMUL(in3 + in5, COS_1_4));
|
||||
tmp31 = unfixo(FMUL(in3 - in5, COS_1_4));
|
||||
|
||||
in1 <<= 2;
|
||||
in7 <<= 2;
|
||||
in1 <<= 2;
|
||||
in7 <<= 2;
|
||||
|
||||
tmp40 = in1 + tmp30;
|
||||
tmp41 = in7 + tmp31;
|
||||
tmp42 = in1 - tmp30;
|
||||
tmp43 = in7 - tmp31;
|
||||
tmp40 = in1 + tmp30;
|
||||
tmp41 = in7 + tmp31;
|
||||
tmp42 = in1 - tmp30;
|
||||
tmp43 = in7 - tmp31;
|
||||
|
||||
tmp50 = FMUL(tmp40, OCOS_1_16) + FMUL(tmp41, OSIN_1_16);
|
||||
tmp51 = FMUL(tmp40, OSIN_1_16) - FMUL(tmp41, OCOS_1_16);
|
||||
tmp52 = FMUL(tmp42, OCOS_5_16) + FMUL(tmp43, OSIN_5_16);
|
||||
tmp53 = FMUL(tmp42, OSIN_5_16) - FMUL(tmp43, OCOS_5_16);
|
||||
tmp50 = FMUL(tmp40, OCOS_1_16) + FMUL(tmp41, OSIN_1_16);
|
||||
tmp51 = FMUL(tmp40, OSIN_1_16) - FMUL(tmp41, OCOS_1_16);
|
||||
tmp52 = FMUL(tmp42, OCOS_5_16) + FMUL(tmp43, OSIN_5_16);
|
||||
tmp53 = FMUL(tmp42, OSIN_5_16) - FMUL(tmp43, OCOS_5_16);
|
||||
|
||||
DstPtr = SrcDst;
|
||||
*DstPtr = unfixh(tmp20 + tmp50);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp21 + tmp53);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp22 + tmp52);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp23 + tmp51);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp23 - tmp51);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp22 - tmp52);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp21 - tmp53);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp20 - tmp50);
|
||||
DstPtr = SrcDst;
|
||||
*DstPtr = unfixh(tmp20 + tmp50);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp21 + tmp53);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp22 + tmp52);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp23 + tmp51);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp23 - tmp51);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp22 - tmp52);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp21 - tmp53);
|
||||
DstPtr += Stride;
|
||||
*DstPtr = unfixh(tmp20 - tmp50);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,67 +357,68 @@ __device__ void CUDAshortInplaceIDCT(short *SrcDst, int Stride) {
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
__device__ void CUDAshortInplaceIDCT(unsigned int *V8) {
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp20, tmp21, tmp22, tmp23;
|
||||
int tmp30, tmp31;
|
||||
int tmp40, tmp41, tmp42, tmp43;
|
||||
int tmp50, tmp51, tmp52, tmp53;
|
||||
PackedShorts sh0, sh1, sh2, sh3;
|
||||
__device__ void CUDAshortInplaceIDCT(unsigned int *V8)
|
||||
{
|
||||
int in0, in1, in2, in3, in4, in5, in6, in7;
|
||||
int tmp10, tmp11, tmp12, tmp13;
|
||||
int tmp20, tmp21, tmp22, tmp23;
|
||||
int tmp30, tmp31;
|
||||
int tmp40, tmp41, tmp42, tmp43;
|
||||
int tmp50, tmp51, tmp52, tmp53;
|
||||
PackedShorts sh0, sh1, sh2, sh3;
|
||||
|
||||
sh0.hInt = V8[0];
|
||||
sh1.hInt = V8[1];
|
||||
sh2.hInt = V8[2];
|
||||
sh3.hInt = V8[3];
|
||||
in0 = sh0.hShort1;
|
||||
in1 = sh0.hShort2;
|
||||
in2 = sh1.hShort1;
|
||||
in3 = sh1.hShort2;
|
||||
in4 = sh2.hShort1;
|
||||
in5 = sh2.hShort2;
|
||||
in6 = sh3.hShort1;
|
||||
in7 = sh3.hShort2;
|
||||
sh0.hInt = V8[0];
|
||||
sh1.hInt = V8[1];
|
||||
sh2.hInt = V8[2];
|
||||
sh3.hInt = V8[3];
|
||||
in0 = sh0.hShort1;
|
||||
in1 = sh0.hShort2;
|
||||
in2 = sh1.hShort1;
|
||||
in3 = sh1.hShort2;
|
||||
in4 = sh2.hShort1;
|
||||
in5 = sh2.hShort2;
|
||||
in6 = sh3.hShort1;
|
||||
in7 = sh3.hShort2;
|
||||
|
||||
tmp10 = FMUL(in0 + in4, COS_1_4);
|
||||
tmp11 = FMUL(in0 - in4, COS_1_4);
|
||||
tmp12 = FMUL(in2, SIN_1_8) - FMUL(in6, COS_1_8);
|
||||
tmp13 = FMUL(in6, SIN_1_8) + FMUL(in2, COS_1_8);
|
||||
tmp10 = FMUL(in0 + in4, COS_1_4);
|
||||
tmp11 = FMUL(in0 - in4, COS_1_4);
|
||||
tmp12 = FMUL(in2, SIN_1_8) - FMUL(in6, COS_1_8);
|
||||
tmp13 = FMUL(in6, SIN_1_8) + FMUL(in2, COS_1_8);
|
||||
|
||||
tmp20 = tmp10 + tmp13;
|
||||
tmp21 = tmp11 + tmp12;
|
||||
tmp22 = tmp11 - tmp12;
|
||||
tmp23 = tmp10 - tmp13;
|
||||
tmp20 = tmp10 + tmp13;
|
||||
tmp21 = tmp11 + tmp12;
|
||||
tmp22 = tmp11 - tmp12;
|
||||
tmp23 = tmp10 - tmp13;
|
||||
|
||||
tmp30 = unfixo(FMUL(in3 + in5, COS_1_4));
|
||||
tmp31 = unfixo(FMUL(in3 - in5, COS_1_4));
|
||||
tmp30 = unfixo(FMUL(in3 + in5, COS_1_4));
|
||||
tmp31 = unfixo(FMUL(in3 - in5, COS_1_4));
|
||||
|
||||
in1 <<= 2;
|
||||
in7 <<= 2;
|
||||
in1 <<= 2;
|
||||
in7 <<= 2;
|
||||
|
||||
tmp40 = in1 + tmp30;
|
||||
tmp41 = in7 + tmp31;
|
||||
tmp42 = in1 - tmp30;
|
||||
tmp43 = in7 - tmp31;
|
||||
tmp40 = in1 + tmp30;
|
||||
tmp41 = in7 + tmp31;
|
||||
tmp42 = in1 - tmp30;
|
||||
tmp43 = in7 - tmp31;
|
||||
|
||||
tmp50 = FMUL(tmp40, OCOS_1_16) + FMUL(tmp41, OSIN_1_16);
|
||||
tmp51 = FMUL(tmp40, OSIN_1_16) - FMUL(tmp41, OCOS_1_16);
|
||||
tmp52 = FMUL(tmp42, OCOS_5_16) + FMUL(tmp43, OSIN_5_16);
|
||||
tmp53 = FMUL(tmp42, OSIN_5_16) - FMUL(tmp43, OCOS_5_16);
|
||||
tmp50 = FMUL(tmp40, OCOS_1_16) + FMUL(tmp41, OSIN_1_16);
|
||||
tmp51 = FMUL(tmp40, OSIN_1_16) - FMUL(tmp41, OCOS_1_16);
|
||||
tmp52 = FMUL(tmp42, OCOS_5_16) + FMUL(tmp43, OSIN_5_16);
|
||||
tmp53 = FMUL(tmp42, OSIN_5_16) - FMUL(tmp43, OCOS_5_16);
|
||||
|
||||
sh0.hShort1 = unfixh(tmp20 + tmp50);
|
||||
sh0.hShort2 = unfixh(tmp21 + tmp53);
|
||||
sh1.hShort1 = unfixh(tmp22 + tmp52);
|
||||
sh1.hShort2 = unfixh(tmp23 + tmp51);
|
||||
sh2.hShort1 = unfixh(tmp23 - tmp51);
|
||||
sh2.hShort2 = unfixh(tmp22 - tmp52);
|
||||
sh3.hShort1 = unfixh(tmp21 - tmp53);
|
||||
sh3.hShort2 = unfixh(tmp20 - tmp50);
|
||||
sh0.hShort1 = unfixh(tmp20 + tmp50);
|
||||
sh0.hShort2 = unfixh(tmp21 + tmp53);
|
||||
sh1.hShort1 = unfixh(tmp22 + tmp52);
|
||||
sh1.hShort2 = unfixh(tmp23 + tmp51);
|
||||
sh2.hShort1 = unfixh(tmp23 - tmp51);
|
||||
sh2.hShort2 = unfixh(tmp22 - tmp52);
|
||||
sh3.hShort1 = unfixh(tmp21 - tmp53);
|
||||
sh3.hShort2 = unfixh(tmp20 - tmp50);
|
||||
|
||||
V8[0] = sh0.hInt;
|
||||
V8[1] = sh1.hInt;
|
||||
V8[2] = sh2.hInt;
|
||||
V8[3] = sh3.hInt;
|
||||
V8[0] = sh0.hInt;
|
||||
V8[1] = sh1.hInt;
|
||||
V8[2] = sh2.hInt;
|
||||
V8[3] = sh3.hInt;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,53 +437,46 @@ __device__ void CUDAshortInplaceIDCT(unsigned int *V8) {
|
||||
*/
|
||||
|
||||
#define IMAD(a, b, c) (((a) * (b)) + (c))
|
||||
#define IMUL(a, b) ((a) * (b))
|
||||
#define IMUL(a, b) ((a) * (b))
|
||||
|
||||
__global__ void CUDAkernelShortDCT(short *SrcDst, int ImgStride) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
__shared__ short block[KERS_BLOCK_HEIGHT * KERS_SMEMBLOCK_STRIDE];
|
||||
int OffsThreadInRow = FMUL(threadIdx.y, BLOCK_SIZE) + threadIdx.x;
|
||||
int OffsThreadInCol = FMUL(threadIdx.z, BLOCK_SIZE);
|
||||
int OffsThrRowPermuted =
|
||||
(OffsThreadInRow & 0xFFFFFFE0) |
|
||||
((OffsThreadInRow << 1) | (OffsThreadInRow >> 4) & 0x1) & 0x1F;
|
||||
__global__ void CUDAkernelShortDCT(short *SrcDst, int ImgStride)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
__shared__ short block[KERS_BLOCK_HEIGHT * KERS_SMEMBLOCK_STRIDE];
|
||||
int OffsThreadInRow = FMUL(threadIdx.y, BLOCK_SIZE) + threadIdx.x;
|
||||
int OffsThreadInCol = FMUL(threadIdx.z, BLOCK_SIZE);
|
||||
int OffsThrRowPermuted =
|
||||
(OffsThreadInRow & 0xFFFFFFE0) | ((OffsThreadInRow << 1) | (OffsThreadInRow >> 4) & 0x1) & 0x1F;
|
||||
|
||||
SrcDst +=
|
||||
IMAD(IMAD(blockIdx.y, KERS_BLOCK_HEIGHT, OffsThreadInCol), ImgStride,
|
||||
IMAD(blockIdx.x, KERS_BLOCK_WIDTH, OffsThreadInRow * 2));
|
||||
short *bl_ptr =
|
||||
block + IMAD(OffsThreadInCol, KERS_SMEMBLOCK_STRIDE, OffsThreadInRow * 2);
|
||||
SrcDst += IMAD(IMAD(blockIdx.y, KERS_BLOCK_HEIGHT, OffsThreadInCol),
|
||||
ImgStride,
|
||||
IMAD(blockIdx.x, KERS_BLOCK_WIDTH, OffsThreadInRow * 2));
|
||||
short *bl_ptr = block + IMAD(OffsThreadInCol, KERS_SMEMBLOCK_STRIDE, OffsThreadInRow * 2);
|
||||
|
||||
// load data to shared memory (only first half of threads in each row performs
|
||||
// data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
// load data to shared memory (only first half of threads in each row performs
|
||||
// data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)] =
|
||||
((int *)SrcDst)[i * (ImgStride / 2)];
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)] = ((int *)SrcDst)[i * (ImgStride / 2)];
|
||||
}
|
||||
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceDCT(
|
||||
block + OffsThreadInCol * KERS_SMEMBLOCK_STRIDE + OffsThrRowPermuted,
|
||||
KERS_SMEMBLOCK_STRIDE);
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceDCT((unsigned int *)(block +
|
||||
OffsThreadInRow * KERS_SMEMBLOCK_STRIDE +
|
||||
OffsThreadInCol));
|
||||
cg::sync(cta);
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceDCT(block + OffsThreadInCol * KERS_SMEMBLOCK_STRIDE + OffsThrRowPermuted, KERS_SMEMBLOCK_STRIDE);
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceDCT((unsigned int *)(block + OffsThreadInRow * KERS_SMEMBLOCK_STRIDE + OffsThreadInCol));
|
||||
cg::sync(cta);
|
||||
|
||||
// store data to global memory (only first half of threads in each row
|
||||
// performs data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
// store data to global memory (only first half of threads in each row
|
||||
// performs data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)SrcDst)[i * (ImgStride / 2)] =
|
||||
((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)];
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)SrcDst)[i * (ImgStride / 2)] = ((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,50 +494,43 @@ __global__ void CUDAkernelShortDCT(short *SrcDst, int ImgStride) {
|
||||
* \return None
|
||||
*/
|
||||
|
||||
__global__ void CUDAkernelShortIDCT(short *SrcDst, int ImgStride) {
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
__shared__ short block[KERS_BLOCK_HEIGHT * KERS_SMEMBLOCK_STRIDE];
|
||||
__global__ void CUDAkernelShortIDCT(short *SrcDst, int ImgStride)
|
||||
{
|
||||
// Handle to thread block group
|
||||
cg::thread_block cta = cg::this_thread_block();
|
||||
__shared__ short block[KERS_BLOCK_HEIGHT * KERS_SMEMBLOCK_STRIDE];
|
||||
|
||||
int OffsThreadInRow = IMAD(threadIdx.y, BLOCK_SIZE, threadIdx.x);
|
||||
int OffsThreadInCol = IMUL(threadIdx.z, BLOCK_SIZE);
|
||||
int OffsThrRowPermuted =
|
||||
(OffsThreadInRow & 0xFFFFFFE0) |
|
||||
((OffsThreadInRow << 1) | (OffsThreadInRow >> 4) & 0x1) & 0x1F;
|
||||
int OffsThreadInRow = IMAD(threadIdx.y, BLOCK_SIZE, threadIdx.x);
|
||||
int OffsThreadInCol = IMUL(threadIdx.z, BLOCK_SIZE);
|
||||
int OffsThrRowPermuted =
|
||||
(OffsThreadInRow & 0xFFFFFFE0) | ((OffsThreadInRow << 1) | (OffsThreadInRow >> 4) & 0x1) & 0x1F;
|
||||
|
||||
SrcDst +=
|
||||
IMAD(IMAD(blockIdx.y, KERS_BLOCK_HEIGHT, OffsThreadInCol), ImgStride,
|
||||
IMAD(blockIdx.x, KERS_BLOCK_WIDTH, OffsThreadInRow * 2));
|
||||
short *bl_ptr =
|
||||
block + IMAD(OffsThreadInCol, KERS_SMEMBLOCK_STRIDE, OffsThreadInRow * 2);
|
||||
SrcDst += IMAD(IMAD(blockIdx.y, KERS_BLOCK_HEIGHT, OffsThreadInCol),
|
||||
ImgStride,
|
||||
IMAD(blockIdx.x, KERS_BLOCK_WIDTH, OffsThreadInRow * 2));
|
||||
short *bl_ptr = block + IMAD(OffsThreadInCol, KERS_SMEMBLOCK_STRIDE, OffsThreadInRow * 2);
|
||||
|
||||
// load data to shared memory (only first half of threads in each row performs
|
||||
// data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
// load data to shared memory (only first half of threads in each row performs
|
||||
// data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)] =
|
||||
((int *)SrcDst)[i * (ImgStride / 2)];
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)] = ((int *)SrcDst)[i * (ImgStride / 2)];
|
||||
}
|
||||
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceIDCT(
|
||||
block + OffsThreadInCol * KERS_SMEMBLOCK_STRIDE + OffsThrRowPermuted,
|
||||
KERS_SMEMBLOCK_STRIDE);
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceIDCT(
|
||||
(unsigned int *)(block + OffsThreadInRow * KERS_SMEMBLOCK_STRIDE +
|
||||
OffsThreadInCol));
|
||||
cg::sync(cta);
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceIDCT(block + OffsThreadInCol * KERS_SMEMBLOCK_STRIDE + OffsThrRowPermuted, KERS_SMEMBLOCK_STRIDE);
|
||||
cg::sync(cta);
|
||||
CUDAshortInplaceIDCT((unsigned int *)(block + OffsThreadInRow * KERS_SMEMBLOCK_STRIDE + OffsThreadInCol));
|
||||
cg::sync(cta);
|
||||
|
||||
// store data to global memory (only first half of threads in each row
|
||||
// performs data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
// store data to global memory (only first half of threads in each row
|
||||
// performs data moving (each thread moves 2 shorts)
|
||||
if (OffsThreadInRow < KERS_BLOCK_WIDTH_HALF) {
|
||||
#pragma unroll
|
||||
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)SrcDst)[i * (ImgStride / 2)] =
|
||||
((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)];
|
||||
}
|
||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
||||
((int *)SrcDst)[i * (ImgStride / 2)] = ((int *)bl_ptr)[i * (KERS_SMEMBLOCK_STRIDE / 2)];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user