summaryrefslogtreecommitdiff
path: root/compiler/moco-tf/doc/Conversion.md
blob: 08551cc3c8caa4a01a4cf6ffdc8cd7101b6484e0 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
This document outlines how to express each TensorFlow operation on top of _loco_

**CAUTION** All the python examples below are written in Python 3 with TensorFlow v1.13.

**DISCLAIMER** _loco_ does not support named values, but all the below _loco_ examples assign "name" to each value to make it easy to read.

### Placeholder

**Placeholder** in _TensorFlow_ corresponds to **Pull** in _loco_.

_Python_:
```python
import tensorflow as tf
input = tf.placeholder(dtype=tf.float32, shape=[3, 4], name='input')
print(tf.get_default_graph().as_graph_def())
```

API reference: [tf.placeholder](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf)

_TensorFlow_
```prototext
node {
  name: "input"
  op: "Placeholder"
  attr {
    key: "dtype"
    value { type: DT_FLOAT }
  }
  attr {
    key: "shape"
    value {
      shape {
        dim { size: 3 }
        dim { size: 4 }
      }
    }
  }
}
```

_loco_:
```
%input = Pull(dtype: FLOAT32, shape: [3, 4])
Push(%input)
```

### Identity

**Identity** in _TensorFlow_ corresponds to **Forward** in _loco_.

_Python_:
```python
import tensorflow as tf
input = tf.placeholder(dtype=tf.float32, shape=[3, 4])
ident = tf.identity(input)
print(tf.get_default_graph().as_graph_def())
```

API reference: [tf.identity](https://www.tensorflow.org/api_docs/python/tf/identity)

_TensorFlow_:
```
node {
  name: "Placeholder"
  op: "Placeholder"
  attr {
    key: "dtype"
    value { type: DT_FLOAT }
  }
  attr {
    key: "shape"
    value {
      shape {
        dim { size: 3 }
        dim { size: 4 }
      }
    }
  }
}
node {
  name: "Identity"
  op: "Identity"
  input: "Placeholder"
  attr {
    key: "T"
    value { type: DT_FLOAT }
  }
}
```

_loco_:
```
%input = Pull(dtype: FLOAT32, shape: [3, 4])
%ident = Forward(%input)
Push(%ident)
```

### Const

**Const** in _TensorFlow_ corresponds to **ConstGen** in _loco_.

_Python_:
```python
import tensorflow as tf
constant = tf.constant(value=[1.0], dtype=tf.float32, shape=[3, 4])
tf.get_default_graph().as_graph_def()
```

API reference: [tf.constant](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/constant)

_TensorFlow_:
```
node {
  name: "Const"
  op: "Const"
  attr {
    key: "dtype"
    value { type: DT_FLOAT }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_FLOAT
        tensor_shape {
          dim { size: 3 }
          dim { size: 4 }
        }
        float_val: 1.0
      }
    }
  }
}
```

_loco_:
```
%constant = ConstGen(dtype: FLOAT32, shape: [3, 4], data: ...);
Push(%constant)
```