cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

givenchy
Journeyman III

2D array using clSVMAlloc ?

Hi ,

I can write a 2D dynamic array as follow :

"""

int size = 256 ;

int *temp[5] ;

temp[0] = (int *)malloc(sizeof(int) * size);

"""

But when I want to dynamic create a 2D array by using clSVMAlloc as previously said , how could I do this ?

Thanks : D

0 Likes
5 Replies
dipak
Big Boss

You can create a host 2D array like this using clSVMalloc, however you can not access that 2D array same way from the kernel code. Instead, you may think of creating a 2D image from a 1D buffer which is created using clSVMalloc. In this way, you can access the 1D SVM buffer same as any 2D image. To see how to create a 2D image from a SVM buffer, please check here Re: Re: How to process images using SVM of OpenCL2.0? On your host side, you can rearrange that 1D SVM buffer to access it as 2D array.


Regards,


0 Likes

HI dipak ,

Thanks for your answer.

The sample code as follow ,

"

typedef struct {

     int a ;

     double c;

     double d;

     double d;

     ......

}test;

int szie = 25600 ;

test *temp[5000] ;

temp[0] = (temp *)malloc(sizeof(temp) * size);

...

(Maybe temp will be allocated temp[4099] = (temp *)malloc(sizeof(temp) * size); )

"

I understand the method you proposed .

But I need a dynamic 2D array of structure as sample code .
If I use 1D->2D , it will show "segmentation fault".

-----------------------------------

The original Idea as shown ,

"

     temp   a[5000][25600]; // dynamicly increase the size of array

     temp * b = (temp *)clSVMAlloc = (.... , sizeof(temp) * 25600 ..);

     b=a[0] ;

     //put a in to kernel to do some computation.     

     //But kernel sees the error input value about b when using GPU.

"

In Opencl CPU type or C program , this assignment will be work and b can get the correctly value.

I want to do this assignment between host memory and SVM memory(GPU can access right value) 

There are two method to solve this problem ,

1. for loop

     b = a[0]

2. memcpy

But I want to create the dynamic 2d array in shared virtual memory , I can use SVM to share data between CPU and device.

thanks : D

0 Likes

I was doing some experiments with SVM for 2D accessing and want to share that experimental code with you. It was only for experimental purpose. I didn't test the same on various setup.

I don't think you'll have any problem to understand the code. If required, we may discuss offline. Hope this is helpful for you.

In the cpp file, you may change the following flags and values to check the various scenario.

#define ACCESS_2D_DIRECT    0
#define SVM_DYNAMIC_1D1

int SVM_ROW = 100; // For me, when SVM_DYNAMIC_1D = 0, larger value giving segfault

int SVM_COL = 2000;

Setup:

Windows 7 64 bit,

Hawaii XT card

APP SDK 3.0 beta

latest driver (internal)

Regards,

0 Likes

I could understand the meaning of setting flag.But could you give me a example how to use this flage like void* temp = (void *)svmalloc(.......)

So the experiment is testing on discrete GPU , I would try to test the method you replied me on kaveri .

Thanks : )

Date: Thu, 14 May 2015 08:17:58 -0500

From: developer.forums@amd.com

To: r02922065@ntu.edu.tw

Subject: Re: 2D array using clSVMAlloc ? | AMD Developer Forums

AMD Developer Forums

Re: 2D array using clSVMAlloc ?

in OpenCL

I was doing some experiments with SVM for 2D accessing and want to share that experimental code with you. It was only for experimental purpose. I didn't test the same on various setup.

I don't think you'll have any problem to understand the code. If required, we may discuss offline. Hope this is helpful for you.

In the cpp file, you may change the following flags and values to check the various scenario.

#define ACCESS_2D_DIRECT 0#define SVM_DYNAMIC_1D1 int SVM_ROW = 100; // For me, when SVM_DYNAMIC_1D = 0, larger value giving segfault

int SVM_COL = 2000;

Setup:

Windows 7 64 bit,

Hawaii XT card

APP SDK 3.0 beta

latest driver (internal)

Regards,

Reply to this message by replying to this email -or- go to the message on AMD Developer Forums

SHARE THE LOVE! Help other developers by marking replies to your questions as Helpful or Correct. If you are the original question asker, you can mark replies as Helpful or Correct by:

Go to the message on AMD Developer Forums (you’ll need to log in).

Click on either the Helpful Answer button or the Correct Answer button.

Pat yourself on the back! You’ve helped others who have the same question as you by telling them which replies are helpful and correct.

0 Likes

could you  give me a  example  how to use  this  flage  like   void*  temp  = (void *)svmalloc(.......)

Sorry, I'm unable to follow your question. Here, which flag are you referring to? Is it related to my experimental code?

Regards,

0 Likes