diff --git a/src/tensor.cu b/src/tensor.cu index 4711e62b..95c684b3 100644 --- a/src/tensor.cu +++ b/src/tensor.cu @@ -59,23 +59,29 @@ inline std::vector Tokenize( const std::string &input void Tensor::Load(const std::string &path) { + size_t totSize = std::accumulate(pimpl_->shape().begin(), pimpl_->shape().end(), + 1, std::multiplies()); + cerr << "totSize=" << totSize << endl; + std::vector hostData(totSize); + fstream strm; strm.open(path.c_str()); - size_t lineNum = 0; string line; + size_t ind = 0; while ( getline (strm, line) ) { cerr << line << '\n'; vector toks = Tokenize(line); for (size_t i = 0; i < toks.size(); ++i) { - pimpl_->set(toks[i], lineNum, i); + hostData[ind] = toks[i]; } - ++lineNum; + ++ind; } strm.close(); + } } diff --git a/src/tensor.h b/src/tensor.h index fea9398c..e8ff92bf 100644 --- a/src/tensor.h +++ b/src/tensor.h @@ -152,10 +152,8 @@ class TensorImpl { thrust::fill(data_.begin(), data_.end(), value); } - void set(value_type value, size_t x, size_t y) { - assert(shape().size() == 2); - size_t sizeRow = sizeof(Float) * shape()[1]; - data_[x + sizeRow * y] = value; + void set(const std::vector &values) { + thrust::copy(values.begin(), values.end(), data_.begin()); } std::string Debug() const