6 #include <cuda_runtime.h>
14 std::ifstream file(filename);
15 if (!file.is_open()) {
16 throw std::runtime_error(
"Error opening file");
20 std::vector<double> temp_data;
21 std::string line, value;
24 while (std::getline(file, line)) {
26 std::istringstream s(line);
29 while (std::getline(s, value,
',')) {
31 temp_data.push_back(std::stod(value));
36 if (temp_data.size() != rows * cols) {
37 throw std::runtime_error(
"CSV data size does not match matrix dimensions");
41 cudaMemcpy(d_data, temp_data.data(), rows * cols *
sizeof(
double), cudaMemcpyHostToDevice);
void read_csv(const char *filename)
Read data from a CSV file into the matrix.
Defines the Matrix class for GPU-accelerated matrix operations.