Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions high_performance_operators/gemm/version1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,58 @@

template<class type>
struct matrix_2d {
matrix_2d(std::vector<std::vector<type>> &data) {
this->data = data;
h = data.size();
w = data[0].size();

public:
matrix_2d(std::vector<std::vector<type>> data) {
h = data.size();
w = data[0].size();
stride[0] = w;
stride[1] = 1;

this->data = new type[h * w];
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
(this->data)[i * stride[0] + j * stride[1]] = data[i][j];
}
}
}

matrix_2d(int high, int width, type fill = 0) {
data.resize(high, std::vector<type>(width, fill));
h = high;
w = width;
h = high;
w = width;
stride[0] = w;
stride[1] = 1;

this->data = new type[h * w];
std::fill(this->data, this->data + h * w, fill);
}

~matrix_2d() {
delete data;
}

std::vector<type> & operator[](int i) {
return data[i];
type * data_ptr() {
return data;
}

type * operator[](int i) {
return (this->data) + i * stride[0];
}

friend std::ostream & operator<<(std::ostream & o, matrix_2d<type> & m) {
for (int i = 0; i < m.h; ++i) {
for (int j = 0; j < m.w; ++j) o << m[i][j] << " ";
o << std::endl;
}
return o;
for (int i = 0; i < m.h; ++i) {
for (int j = 0; j < m.w; ++j) o << m[i][j] << " ";
o << std::endl;
}
return o;
}

int h;
int w;
std::vector<std::vector<type>> data;

private:
int stride[2];
type * data;
};

template<class type>
Expand Down