- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I've been trying to compile a small program as a proof of concept using icpx and g++. I've been following the instructions provided here, but I can't get it to work. Specifically, when I run the following command:
icpx -fsycl -fsycl-device-only -Xclang -fsycl-int-header=add-vector-host.h add-vector.cpp
it generates an empty header file. I'm not sure what I'm doing wrong - the bc file seems to be generated correctly, but there are no specifications on what to do with that file.
I'm using three different files: one with my host code, another with my function definition, and a header file. The program is just a simple vector addition. I've tried both a functor and a function with the SYCL_EXTERNAL macro, but neither has made any difference. If I compile everything with icpx it works just fine.
Any help or advice would be greatly appreciated. Thank you!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for posting in Intel Communities.
We are unable to reproduce your issue at our end.
We are using oneAPI 2023.1.0 version and Ubuntu 20.04.6 LTS Operating system.
Below is the sample code we used,
host.cpp
#include <CL/sycl.hpp>
#include <iostream>
#include "add-vector.h"
int main() {
constexpr int N = 10;
// Create a SYCL queue
cl::sycl::queue q;
// Create input and output buffers on the device
cl::sycl::buffer<float> in_buf{cl::sycl::range<1>(N)};
cl::sycl::buffer<float> out_buf{cl::sycl::range<1>(N)};
// Initialize input buffer on the host
{
auto in_ptr = in_buf.get_access<cl::sycl::access::mode::write>();
for (int i = 0; i < N; i++) {
in_ptr[i] = i;
}
}
// Launch the SYCL kernel
q.submit([&](cl::sycl::handler& h) {
auto in_ptr = in_buf.get_access<cl::sycl::access::mode::read>(h);
auto out_ptr = out_buf.get_access<cl::sycl::access::mode::write>(h);
h.parallel_for<class add_vector>(cl::sycl::range<1>(N),
[=](cl::sycl::id<1> idx) {
out_ptr[idx] = add(in_ptr[idx], 1.0f);
});
});
// Read the output buffer from the device and print the results
auto out_ptr = out_buf.get_access<cl::sycl::access::mode::read>();
for (int i = 0; i < N; i++) {
std::cout << out_ptr[i] << " ";
}
std::cout << std::endl;
return 0;
}
add-vector.cpp
#include <CL/sycl.hpp>
#include "add-vector.h"
float add(float a, float b) {
return a + b;
}
add-vector.h
#ifndef ADD_VECTOR_H
#define ADD_VECTOR_H
float SYCL_EXTERNAL add(float a, float b);
#endif
Here are the commands we tried, to execute the code:
source /opt/intel/oneapi/setvars.sh
export LIBDIR=/opt/intel/oneapi/compiler/latest/linux/lib
icpx -fsycl -c host.cpp -fPIC -o host.o
icpx -fsycl -c add-vector.cpp -fPIC -o add-vector.o
icpx -fsycl -fsycl-device-only -Xclang -fsycl-int-header=a_host.h host.cpp
icpx -fsycl -fsycl-device-only -Xclang -fsycl-int-header=b_host.h add-vector.cpp
g++ -std=c++17 -c host.cpp -o a_host.o -include a_host.h -fPIC -I/opt/intel/oneapi/compiler/latest/linux/include -I/opt/intel/oneapi/compiler/latest/linux/include/sycl
g++ -std=c++17 -c add-vector.cpp -o b_host.o -include b_host.h -fPIC -I/opt/intel/oneapi/compiler/latest/linux/include -I/opt/intel/oneapi/compiler/latest/linux/include/sycl
icpx -fPIC -fsycl -fsycl-link host.o add-vector.o -o device.o
g++ a_host.o b_host.o device.o -L$LIBDIR -lOpenCL -lsycl -o finalexe.exe
./finalexe.exe
Please let us know, if you still face any issues.
Thanks & Regards,
Vankudothu Vaishnavi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Has the information provided above helped? If yes, could you please confirm whether we can close this thread from our end?
Thanks & Regards,
Vankudothu Vaishnavi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We assume that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.
Thanks & Regards,
Vankudothu Vaishnavi.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page