- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I am trying to pass a vector of array to the USM allocator class and am trying to follow the syntax given in one of the webinars which goes like:
usm_allocator<int, usm::alloc::shared> alloc(q.get_context(), q.get_device());
std::vector<int, decltype(alloc)> v(size, initial value, alloc);
I have attached the code I am trying this in. I am getting the output but also an error as follows:
Device: Intel(R) Gen9
terminate called after throwing an instance of 'cl::sycl::runtime_error'
what(): Native API failed. Native API returns: -30 (CL_INVALID_VALUE) -30 (CL_INVALID_VALUE)
Aborted (core dumped)
System spec: Ubuntu 18.04.4 LTS, Intel® HD Graphics 630 (Kaby Lake GT2)
oneAPI version beta 07, running on default L0 BE
Please kindly advise on the error and syntax I have used for the vector of array passed to USM alloc class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Suraj,
Your syntax of vector allocation is correct. In your code(attached) you are trying to free a double-pointer which is not allocated by any of the SYCL allocation function so there will not be any SYCL context associated with the pointer. This is the reason for the error.
You can directly clear the vector of array instead of freeing the pointer to the vector.
Please find the below code for more details.
#include <CL/sycl.hpp>
#include <vector>
#include <iostream>
#include <array>
using namespace sycl;
static const int N = 5;
int main(){
gpu_selector device_selector;
queue q(device_selector);
std::cout << "Device: " << q.get_device().get_info<info::device::name>() << std::endl;
auto ctx = q.get_context();
usm_allocator<std::array<double,3>, usm::alloc::shared> alloc(q.get_context(), q.get_device());
std::vector<std::array<double,3>,decltype(alloc) > arrVec(N,alloc);
//std::array<std::vector<double>,3> arrVec({std::vector<double>(5,alloc),std::vector<double>(11), std::vector<double>(12)});
for(int i=0; i<N; i++)
for(int j=0; j<3; j++)
arrVec[i][j] = (i+1)*10 + j + 1;
double** ptr0 = (double**)(&arrVec[0][0]);
{
q.submit([&](handler &h) {
h.parallel_for(range<2>(N,3), [=] (id<2> i){
// ptr[i] *= ptr1[i];
ptr0[i[0]][i[1]] += 1;
});
}).wait_and_throw();
}
std::cout<<"O/P"<<std::endl;
for(int i=0; i<N; i++)
std::cout << arrVec[i][0] <<" "<< arrVec[i][1] << std::endl;
arrVec.clear();
return 0;
}
Warm Regards,
Abhishek
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Suraj,
Your syntax of vector allocation is correct. In your code(attached) you are trying to free a double-pointer which is not allocated by any of the SYCL allocation function so there will not be any SYCL context associated with the pointer. This is the reason for the error.
You can directly clear the vector of array instead of freeing the pointer to the vector.
Please find the below code for more details.
#include <CL/sycl.hpp>
#include <vector>
#include <iostream>
#include <array>
using namespace sycl;
static const int N = 5;
int main(){
gpu_selector device_selector;
queue q(device_selector);
std::cout << "Device: " << q.get_device().get_info<info::device::name>() << std::endl;
auto ctx = q.get_context();
usm_allocator<std::array<double,3>, usm::alloc::shared> alloc(q.get_context(), q.get_device());
std::vector<std::array<double,3>,decltype(alloc) > arrVec(N,alloc);
//std::array<std::vector<double>,3> arrVec({std::vector<double>(5,alloc),std::vector<double>(11), std::vector<double>(12)});
for(int i=0; i<N; i++)
for(int j=0; j<3; j++)
arrVec[i][j] = (i+1)*10 + j + 1;
double** ptr0 = (double**)(&arrVec[0][0]);
{
q.submit([&](handler &h) {
h.parallel_for(range<2>(N,3), [=] (id<2> i){
// ptr[i] *= ptr1[i];
ptr0[i[0]][i[1]] += 1;
});
}).wait_and_throw();
}
std::cout<<"O/P"<<std::endl;
for(int i=0; i<N; i++)
std::cout << arrVec[i][0] <<" "<< arrVec[i][1] << std::endl;
arrVec.clear();
return 0;
}
Warm Regards,
Abhishek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. I understand. Silly mistake on my part. The issue is resolved for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Suraj,
Thank you for the confirmation, please post a new thread if you have any other issues.
Warm Regards,
Abhishek
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page