Hi everyone !!
I want to migrate this CUDA code to oneAPI. The problem is that when using DPCT, I have an incompatibility with CUDA 1-Channel, because SYCL supports only 4-Channels, but I don’t know how to modify the reading part to obtain the same result.
This is my CUDA example code:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "cuda_texture_types.h"
#include "texture_fetch_functions.h"
#include "texture_types.h"
#include <stdio.h>
texture < int, 2 > textureD;
__global__ void kernel(int * dOutput, int width, int height)
{
int row =
blockIdx.y * blockDim.y + threadIdx.y;
int col =
blockIdx.x * blockDim.x + threadIdx.x;
dOutput[row * width + col] =
tex2D(textureD, col, row);
}
int main()
{
int * h;
int width =
10;
int height =
10;
int size =
width * height;
cudaHostAlloc < int > ( & h, size * sizeof(int), cudaHostAllocDefault);
int i =
0;
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
h[row * width + col] =
i;
i++;
}
}
int * d;
size_t pitch;
cudaMallocPitch < int > ( & d, & pitch, width * sizeof(int), height);
cudaMemcpy2D(d, pitch, h, width * sizeof(int), width * sizeof(int), height, cudaMemcpyHostToDevice);
cudaChannelFormatDesc channel =
cudaCreateChannelDesc < int > ();
cudaBindTexture2D(NULL, & textureD, d, & channel, width, height, pitch);
int * hOutput;
cudaHostAlloc < int > ( & hOutput, size * sizeof(int), cudaHostAllocDefault);
int * dOutput;
cudaMalloc < int > ( & dOutput, size * sizeof(int));
kernel << < 1, width * height >>> (dOutput, width, height);
cudaMemcpy(hOutput, dOutput, size * sizeof(int), cudaMemcpyDeviceToHost);
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
printf("%d ", h[row * width + col]);
}
printf("\n");
}
printf("\n");
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
printf("%d ", hOutput[row * width + col]);
}
printf("\n");
}
getchar();
cudaFreeHost(h);
cudaFree(d);
cudaFree(dOutput);
cudaFreeHost(hOutput);
return 0;
}
Anyone can migrate this code to oneAPI ? I’ve been with this for 2 weeks. Thank you so much !