Intel® DevCloud
Help for those needing help starting or connecting to the Intel® DevCloud
1626 Discussions

The compilation problem of calling FPGA and GPU in file

HYB
Beginner
1,873 Views

Use the FPGA queue in the main file test.cpp and call the function in gpu.cpp. The function uses the GPU queue. How to compile the file, the following compilation statement has an error: terminate called after throwing an instance of 'CL:: sycl:: runtime_ error'

 

Compile command:

dpcpp -DFPGA_EMULATOR \-fsycl-targets=spir64_fpga-unknown-unknown-sycldevice gpu.cpp \-c -o gpu.o

dpcpp -DFPGA_EMULATOR \-fsycl-targets=spir64_fpga-unknown-unknown-sycldevice,spir64-unknown-unknown-sycldevice test.cpp gpu.o -o test test.cpp gpu.hpp gpu.cpp

 

test.cpp

HYB_0-1631090154085.png

gpu.hpp

HYB_1-1631090173465.png

gpu.cpp

HYB_2-1631090207253.pngHYB_3-1631090224908.png

 

0 Kudos
1 Solution
AthiraM_Intel
Moderator
1,600 Views

Hi,

 

Could you please follow the below steps:

 

1. Replace your build.sh file by the below commands:

 

dpcpp -DFPGA_EMULATOR gpu.cpp \-c -o gpu.o

dpcpp -DFPGA_EMULATOR test.cpp gpu.o -o test

 

2. Run build.sh and run.sh files:

 

qsub -l nodes=1:gpu:ppn=2 -d . build.sh

qsub -l nodes=1:gpu:ppn=2 -d . run.sh

 

Please find the attached result (Image.PNG) for reference.

Hope this helps. If you have any further issue, please let us know.

 

Thanks.

 

View solution in original post

0 Kudos
10 Replies
AthiraM_Intel
Moderator
1,839 Views

Hi,


Thank you for posting in Intel Communities.

Could you please share sample reproducer code and the complete steps, so that we can try out the same from our end?


Thanks



0 Kudos
HYB
Beginner
1,756 Views

test.cpp

#include <stdio.h>
#include <stdlib.h>
#include "gpu.hpp"
#include <CL/sycl.hpp>
#include <CL/sycl/INTEL/fpga_extensions.hpp>
using namespace std;
using namespace cl::sycl;

int main(){
queue Q{ INTEL::fpga_emulator_selector{} };
std::cout << "Running on device: " << Q.get_device().get_info<info::device::name>() << "\n";

int size = 16;
int *data = (int *)malloc(sizeof(int)*size);
int *device_data = malloc_device<int>(size,Q);
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");
Q.memcpy(device_data, data, sizeof(int) * size);

Q.submit([&](auto &h) {
h.parallel_for(range{ size_t(size) }, [=](id<1> i) {
device_data[i] = device_data[i] * 10;
});
});

Q.memcpy(data, device_data, sizeof(int) * size);
printf("the data on fpga is:\n");
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");

addOnGpu();

free(data);
free(device_data,Q);
return 0;
}

 

gpu.hpp

#include <stdio.h>
#include <stdlib.h>
#include <CL/sycl.hpp>
#include <CL/sycl/INTEL/fpga_extensions.hpp>
using namespace std;
using namespace cl::sycl;

void addOnGpu();

 

gpu.cpp

#include "gpu.hpp"
using namespace std;
using namespace cl::sycl;

void addOnGpu(){

queue Q{ cl::sycl::gpu_selector{} };
//queue q{ INTEL::fpga_emulator_selector{} };
std::cout << "Running on GPU device: " << Q.get_device().get_info<info::device::name>() << "\n";

int size = 16;
int *data = (int *)malloc(sizeof(int)*size);
int *device_data = malloc_device<int>(size,Q);
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");
Q.memcpy(device_data, data, sizeof(int) * size);

Q.submit([&](auto &h) {
h.parallel_for(range{ size_t(size) }, [=](id<1> i) {
device_data[i] = device_data[i] * 100;
});
});

Q.memcpy(data, device_data, sizeof(int) * size);
printf("the data on fpga is:\n");
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");

//addOnGpu(data,size);

free(data);
free(device_data,Q);
}

 

 

0 Kudos
AthiraM_Intel
Moderator
1,773 Views

Hi,


We have not heard back from you. Could you please give us an update?


Thanks.


0 Kudos
HYB
Beginner
1,727 Views

test.cpp

#include <stdio.h>
#include <stdlib.h>
#include "gpu.hpp"
#include <CL/sycl.hpp>
#include <CL/sycl/INTEL/fpga_extensions.hpp>
using namespace std;
using namespace cl::sycl;

int main(){
queue Q{ INTEL::fpga_emulator_selector{} };
std::cout << "Running on device: " << Q.get_device().get_info<info::device::name>() << "\n";

int size = 16;
int *data = (int *)malloc(sizeof(int)*size);
int *device_data = malloc_device<int>(size,Q);
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");
Q.memcpy(device_data, data, sizeof(int) * size);

Q.submit([&](auto &h) {
h.parallel_for(range{ size_t(size) }, [=](id<1> i) {
device_data[i] = device_data[i] * 10;
});
});

Q.memcpy(data, device_data, sizeof(int) * size);
printf("the data on fpga is:\n");
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");

addOnGpu();

free(data);
free(device_data,Q);
return 0;
}

 

gpu.hpp

#include <stdio.h>
#include <stdlib.h>
#include <CL/sycl.hpp>
#include <CL/sycl/INTEL/fpga_extensions.hpp>
using namespace std;
using namespace cl::sycl;

void addOnGpu();

 

gpu.cpp

#include "gpu.hpp"
using namespace std;
using namespace cl::sycl;

void addOnGpu(){

queue Q{ cl::sycl::gpu_selector{} };
//queue q{ INTEL::fpga_emulator_selector{} };
std::cout << "Running on GPU device: " << Q.get_device().get_info<info::device::name>() << "\n";

int size = 16;
int *data = (int *)malloc(sizeof(int)*size);
int *device_data = malloc_device<int>(size,Q);
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");
Q.memcpy(device_data, data, sizeof(int) * size);

Q.submit([&](auto &h) {
h.parallel_for(range{ size_t(size) }, [=](id<1> i) {
device_data[i] = device_data[i] * 100;
});
});

Q.memcpy(data, device_data, sizeof(int) * size);
printf("the data on fpga is:\n");
for (int i = 0; i < size; i++) {
data[i] = i; printf("%d\t",data[i]);
} printf("\n");

//addOnGpu(data,size);

free(data);
free(device_data,Q);
}

 

build.sh

dpcpp -DFPGA_EMULATOR \-fsycl-targets=spir64_fpga-unknown-unknown-sycldevice gpu.cpp \-c -o gpu.o
dpcpp -DFPGA_EMULATOR \-fsycl-targets=spir64_fpga-unknown-unknown-sycldevice,spir64-unknown-unknown-sycldevice test.cpp gpu.o -o test

 

run.sh

./test

 

The control command at the control panel end is:

qsub -l neednodes=1:fpga_compile:ppn=2,nodes=1:fpga_compile:ppn=2 -d . build.sh
qsub -l neednodes=1:fpga_compile:ppn=2,nodes=1:fpga_compile:ppn=2 -d . run.sh

 

Can't output correct results, what's the problem?

0 Kudos
AthiraM_Intel
Moderator
1,694 Views

Hi,

Could you share the error log and respective screenshot?

Also we are facing error while trying your command. So try the below commands.

qsub -l nodes=1:fpga_compile:ppn=2 -d . build.sh

qsub -l nodes=1:fpga_compile:ppn=2 -d . run.sh

If the issue still persists, please let us know.


Thanks


0 Kudos
HYB
Beginner
1,656 Views

There was still an error trying your command.

0 Kudos
AthiraM_Intel
Moderator
1,601 Views

Hi,

 

Could you please follow the below steps:

 

1. Replace your build.sh file by the below commands:

 

dpcpp -DFPGA_EMULATOR gpu.cpp \-c -o gpu.o

dpcpp -DFPGA_EMULATOR test.cpp gpu.o -o test

 

2. Run build.sh and run.sh files:

 

qsub -l nodes=1:gpu:ppn=2 -d . build.sh

qsub -l nodes=1:gpu:ppn=2 -d . run.sh

 

Please find the attached result (Image.PNG) for reference.

Hope this helps. If you have any further issue, please let us know.

 

Thanks.

 

0 Kudos
HYB
Beginner
1,501 Views

Thank you very much for your guidance. I finished the task successfully

0 Kudos
HYB
Beginner
1,505 Views

Thank you very much for your guidance. I finished the task successfully

0 Kudos
AthiraM_Intel
Moderator
1,487 Views

Hi,


Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.



Thanks.


0 Kudos
Reply