forked from gorgonia/gorgonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_infidel.go
97 lines (81 loc) · 4.57 KB
/
op_infidel.go
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
package gorgonia
import (
"fmt"
"hash"
"hash/fnv"
"github.com/chewxy/gorgonia/tensor"
"github.com/chewxy/hm"
)
/*
This file contains code for Ops that aren't really functions in the sense that they aren't pure.
Since they're not adherents to the Church of Lambda, they are INFIDELS! A fatwa will be issued on them shortly
*/
type stmtOp interface {
Op
isStmt() bool
}
// letOp is not really a function. It's more of a binding statement.
// However, it's implemented as a Op so that it can be counted for register allocation and liveness
type letOp struct{}
func (op letOp) Arity() int { return 0 }
func (op letOp) Type() hm.Type { return nil }
func (op letOp) ReturnsPtr() bool { return true }
func (op letOp) OverwritesInput() int { return 0 }
func (op letOp) CallsExtern() bool { return false }
func (op letOp) InferShape(...DimSizer) (tensor.Shape, error) { return nil, nil }
func (op letOp) DiffWRT(int) []bool { return nil }
func (op letOp) SymDiff(inputs Nodes, outputNode, gradNode *Node) (Nodes, error) { return nil, nil }
func (op letOp) Do(vals ...Value) (Value, error) { return nil, nil }
func (op letOp) String() string { return "=" }
func (op letOp) WriteHash(h hash.Hash) { h.Write([]byte("let")) }
func (op letOp) Hashcode() uint32 {
h := fnv.New32a()
op.WriteHash(h)
return h.Sum32()
}
func (op letOp) isStmt() bool { return true }
// readOp reads a value off the input. This op ensures that a value used, and hence codegen'd out
type readOp struct {
into *Value // no, it's not a mistake. It's a pointer to a Value (which is an interface{} type)
}
func (op readOp) Arity() int { return 0 }
func (op readOp) Type() hm.Type { return nil }
func (op readOp) ReturnsPtr() bool { return true }
func (op readOp) OverwritesInput() int { return 0 }
func (op readOp) CallsExtern() bool { return false }
func (op readOp) InferShape(...DimSizer) (tensor.Shape, error) { return nil, nil }
func (op readOp) DiffWRT(int) []bool { return nil }
func (op readOp) SymDiff(inputs Nodes, outputNode, gradNode *Node) (Nodes, error) { return nil, nil }
func (op readOp) Do(vals ...Value) (Value, error) { return nil, nil }
func (op readOp) String() string { return "print" }
func (op readOp) WriteHash(h hash.Hash) { h.Write([]byte("print")) }
func (op readOp) Hashcode() uint32 {
h := fnv.New32a()
op.WriteHash(h)
return h.Sum32()
}
func (op readOp) isStmt() bool { return true }
// devTrans is a dummy Op, used to aid in creating the program that is run in a *tapeMachine. It is inserted not into the graph, but into a slice of sorted nodes, and will not show up in thegraph.
type devTrans struct {
from, to Device
toNode *Node
}
func (op devTrans) Arity() int { panic("not implemented") }
func (op devTrans) Type() hm.Type { panic("not implemented") }
func (op devTrans) InferShape(...DimSizer) (tensor.Shape, error) { panic("not implemented") }
func (op devTrans) Do(...Value) (Value, error) { panic("not implemented") }
func (op devTrans) ReturnsPtr() bool { return false }
func (op devTrans) CallsExtern() bool { return true }
func (op devTrans) OverwritesInput() int { return -1 }
func (op devTrans) WriteHash(h hash.Hash) { fmt.Fprintf(h, "from:%vto%v", op.from, op.to) }
func (op devTrans) Hashcode() uint32 {
h := fnv.New32a()
op.WriteHash(h)
return h.Sum32()
}
func (op devTrans) String() string { return fmt.Sprintf("[CP %v %v]", op.from, op.to) }
func (op devTrans) isStmt() bool { return true }
func (op devTrans) CUDADo(extern External, dev Device, prealloc Value, inputs ...Value) (retVal Value, err error) {
return nil, nil
}
func (op devTrans) CUDAFuncName() string { return op.String() }