-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.h
57 lines (45 loc) · 1.4 KB
/
matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef MATRIX_HPP
#define MATRIX_HPP
#include "kernels.h"
#include "lazy_alloc.h"
#include "types.h"
#include <cassert>
#include <iomanip>
#include <iostream>
#define ptr_idx(stride, row, col) ((row) * stride + (col))
class Matrix {
private:
Shape shape;
LazyDeviceAllocator allocator;
public:
Matrix(Shape shape);
Matrix(Shape shape, LazyDeviceAllocator allocator);
static Matrix new_owned_host(float *host_ptr, Shape shape);
static Matrix new_borrowed_host(float *host_ptr, Shape shape);
static Matrix new_owned_dev(float *dev_ptr, Shape shape);
static Matrix new_borrowed_dev(float *dev_ptr, Shape shape);
void host_print();
void host_fill(float val);
void dev_fill(float val);
void host_fill_rand(float low, float high);
void dev_fill_rand(float low, float high);
void host_add(Matrix &other);
void dev_add(Matrix &other);
void host_mul(Matrix &a, Matrix &b);
void dev_mul(Matrix &a, Matrix &b);
void set_borrowed_host_ptr_unchecked(float *host_ptr);
void set_owned_host_ptr_unchecked(float *host_ptr);
void set_borrowed_dev_ptr_unchecked(float *dev_ptr);
void set_owned_dev_ptr_unchecked(float *dev_ptr);
float *get_host_ptr();
float *get_dev_ptr();
float *get_host_ptr_unchecked();
float *get_dev_ptr_unchecked();
Device current_device();
Shape get_shape();
size_t elem_count();
void to_host();
void to_dev();
size_t alloc_size();
};
#endif // MATRIX_HPP