第一种方法:
从global memory加载数据时coalesce
#include "cuda_runtime.h"
#include <cuda.h>
#include <time.h>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/cudawarping.hpp>
#include "opencv2/highgui.hpp"
#include <iostream>
#include <math.h>
#include <chrono>
// using namespace cv;
// using namespace std;
// enlarge k times in x and y direction
__global__ void inter_nearest_k(uchar3 *dataIn, uchar3 *dataOut, int imgHeight, int imgWidth, int k)
{
int xIndex = threadIdx.x + blockIdx.x * blockDim.x;
int yIndex = threadIdx.y + blockIdx.y * blockDim.y;
if(xIndex < imgWidth && yIndex < imgHeight)
{
uchar3 rgb = dataIn[yIndex * imgWidth + xIndex];
for(int j = 0; j < k; j++) // y direction
{
for(int i = 0; i < k; i++) // x direction
{
dataOut[(k * yIndex + j) * k * imgWidth + k * xIndex + i] = rgb;
}
}
}
}
int main(void)
{
int k = 11;
cv::Mat img_ori = cv::imread("lisfan-70.jpg");
int imgWidth = img_ori.cols;
int imgHeight = img_ori.rows;
std::cout << "img_ori.cols: " << img_ori.cols << std::endl; //列
std::cout << "img_ori.rows: " << img_ori.rows << std::endl; //行
cv::Mat img_resize_cpu;
auto start_cpu = std::chrono::steady_clock::now();
resize(img_ori, img_resize_cpu, cv::Size(k*img_ori.cols, k*img_ori.rows), 0, 0, cv::INTER_NEAREST);
auto end_cpu = std::