int main(void)
{
int host_Ap[5] = {0,2,2,3,6};
int host_Aj[6] = {0,2,2,0,1,2};
float host_Ax[6] = {10,20,30,40,50,60};
float host_x[3] = {1,1,1};
float host_y[4] = {0,0,0,0};
int * device_Ap;
cudaMalloc(&device_Ap, 5 * sizeof(int));
int * device_Aj;
cudaMalloc(&device_Aj, 6 * sizeof(int));
float * device_Ax;
cudaMalloc(&device_Ax, 6 * sizeof(float));
float * device_x;
cudaMalloc(&device_x, 3 * sizeof(float));
float * device_y;
cudaMalloc(&device_y, 4 * sizeof(float));
cudaMemcpy(device_Ap, host_Ap, 5 * sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(device_Aj, host_Aj, 6 * sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(device_Ax, host_Ax, 6 * sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(device_x, host_x, 3 * sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(device_y, host_y, 4 * sizeof(float), cudaMemcpyHostToDevice);
{
HostIndexArrayView row_offsets (host_Ap, host_Ap + 5);
HostIndexArrayView column_indices(host_Aj, host_Aj + 6);
HostValueArrayView values (host_Ax, host_Ax + 6);
HostValueArrayView x (host_x, host_x + 3);
HostValueArrayView y (host_y, host_y + 4);
HostIndexArrayView,
HostValueArrayView> HostView;
HostView A(4, 3, 6, row_offsets, column_indices, values);
std::cout << "\nhost csr_matrix_view" << std::endl;
std::cout << "\nx array" << std::endl;
std::cout << "\n y array, y = A * x" << std::endl;
}
{
thrust::device_ptr<int> wrapped_device_Ap(device_Ap);
thrust::device_ptr<int> wrapped_device_Aj(device_Aj);
thrust::device_ptr<float> wrapped_device_Ax(device_Ax);
thrust::device_ptr<float> wrapped_device_x(device_x);
thrust::device_ptr<float> wrapped_device_y(device_y);
DeviceIndexArrayView row_offsets (wrapped_device_Ap, wrapped_device_Ap + 5);
DeviceIndexArrayView column_indices(wrapped_device_Aj, wrapped_device_Aj + 6);
DeviceValueArrayView values (wrapped_device_Ax, wrapped_device_Ax + 6);
DeviceValueArrayView x (wrapped_device_x, wrapped_device_x + 3);
DeviceValueArrayView y (wrapped_device_y, wrapped_device_y + 4);
DeviceIndexArrayView,
DeviceValueArrayView> DeviceView;
DeviceView A(4, 3, 6, row_offsets, column_indices, values);
std::cout << "\ndevice csr_matrix_view" << std::endl;
std::cout << "\nx array" << std::endl;
std::cout << "\n y array, y = A * x" << std::endl;
}
cudaFree(device_Ap);
cudaFree(device_Aj);
cudaFree(device_Ax);
cudaFree(device_x);
cudaFree(device_y);
return 0;
}