AnsweredAssumed Answered

Facing problems in porting CUDA code to OpenCL

Question asked by xxrenuk on Mar 18, 2013
Latest reply on Mar 26, 2013 by xxrenuk

Hello,

 

    I'm trying to port the CUDA code to OpenCL. I'm using "AMD-APP-SDK-v2.8-lnx32" for compiling my host code. As per my understanding I have made the changes to run it on OpenCL. The host code compiles fine, but when I run the binary created, it tries to compile the kernel code and it fails saying

 

ERROR: Failed to build executable
"/tmp/OCLoPv5RX.cl", line 1: error: unrecognized token
  �$.
  ^

"/tmp/OCLoPv5RX.cl", line 1: error: expected a declaration
  �$.
  ^

2 errors detected in the compilation of "/tmp/OCLoPv5RX.cl".

Frontend phase failed compilation.

 

How to debug these type of errors - any pointers? I'm trying to learn OpenCl now, please help.

 

The changes I made from CUDA to Open CL

 

CUDA

__global void draw_gpu(unsigned char *buf, scene_gpu *myScene)

OpenCl

__kernel void draw_gpu(__global unsigned char *buf,__global scene_gpu *myScene)

 

CUDA

    int j= blockIdx.x;

    int i= threadIdx.x;

OpenCl

    int j= get_group_id(0);

    int i= get_local_id(0);

CUDA

__device__ bool hitSphere_d(const ray &r, const sphere &s, float &t)

OpenCl

bool hitSphere_d(const ray &r, const sphere &s, float &t)

 

CUDA

__device__ float min_d (float a, float b)

OpenCl

float min_d (float a, float b)

 

Please note that here I had __device__ qualified functions, ie these functions are called by device(GPU) from the kernel function. Whereas in OpenCl I read giving extra qualifier is not necessary. Is this if fine ?

I have attached the cuda kernel and OpenCl kernel code, please have a look and suggest any changes.

Attachments

Outcomes