我正在学习dpc++,并试图实现2d数组矩阵程序。我被困在节目中间了。请检查吹气码并支持我。需要帮助。
#include<CL/sycl.hpp>
#include<stdio.h>
#define N 2
using namespace sycl;
int main(){
int ha[N][N] = {1,2,3,4};
int hb[N][N] = {1,2,3,4};
int hc[N][N];
//printing ha and hb arrays here
//synchronization block start
{
queue q;
buffer my_buf1(ha);
buffer my_buf2(hb);
buffer my_buf3(hc);
q.submit([&](handler &h) {
stream out(1024,256,h);
accessor dev_acs1(my_buf1,h);
accessor dev_acs2(my_buf2,h);
accessor dev_acs3(my_buf3,h);我不知道如何编写parallel_for函数来添加ha[i][j]和hb[i][j]并将其放入hc[i][j]中。
h.parallel_for(range{N,N},[=](id<2> idx){
----------------------
});
host_accessor host_hc(my_buf3);
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
std::cout<<host_hc[i][j];
}
return 0;
}发布于 2022-06-28 11:48:12
请在下面找到2d矩阵添加的代码:
#include<CL/sycl.hpp>
#include<stdio.h>
#include<iostream>
#define N 2
using namespace sycl;
int main(){
int ha[N][N] = {1,2,3,4};
int hb[N][N] = {1,2,3,4};
int hc[N][N]={0};
//printing ha and hb arrays here
//synchronization block start
{
queue q;
buffer my_buf1(*ha,range<2>(N,N));
buffer my_buf2(*hb,range<2>(N,N));
buffer my_buf3(*hc,range<2>(N,N));
q.submit([&](handler &h) {
stream out(1024,256,h);
accessor dev_acs1(my_buf1,h,read_only);
accessor dev_acs2(my_buf2,h,read_only);
accessor dev_acs3(my_buf3,h,write_only);
h.parallel_for(range{N,N},[=](id<2> idx){
int i = idx[1];
int j = idx[0];
dev_acs3[i][j]=dev_acs1[i][j] + dev_acs2[i][j]; // (or) dev_acs3[idx]=dev_acs1[idx] + dev_acs2[idx];
});
});
host_accessor host_hc(my_buf3);
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
std::cout<<host_hc[i][j]<<"\n" ;
}
return 0;
}https://stackoverflow.com/questions/72740567
复制相似问题