Skip to content

Commit 93c18bf

Browse files
zheng-xqMikhail Zolotukhin
authored andcommitted
Add ElementWise support (pytorch#150)
1 parent 81f0847 commit 93c18bf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

benchmarks/tensorexpr/elementwise.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ def __init__(self, mode, device, N):
77
self.N = N
88
self.d1 = self.rand([N], device=device, requires_grad=self.requires_grad)
99
self.d2 = self.rand([N], device=device, requires_grad=self.requires_grad)
10+
self.d3 = self.rand([N], device=device, requires_grad=self.requires_grad)
11+
self.d4 = self.rand([N], device=device, requires_grad=self.requires_grad)
12+
self.inputs = [self.d1, self.d2, self.d3, self.d4]
1013

11-
def forward(self):
12-
y = self.mul(self.d1, self.d2)
14+
def forward(self, d1, d2, d3, d4):
15+
y = d1 * d2 + d3 * d4
1316
return y
1417

1518
def reference(self):
16-
return self.numpy(self.d1) * self.numpy(self.d2)
19+
return self.numpy(self.d1) * self.numpy(self.d2) + self.numpy(self.d3) * self.numpy(self.d4)
1720

1821
def config(self):
1922
return [self.N]
@@ -24,11 +27,11 @@ def module():
2427

2528
def memory_workload(self):
2629
if self.mode == 'fwd':
27-
sol_count = 2 + 1
28-
algorithmic_count = 2 + 1
30+
sol_count = 4 + 1
31+
algorithmic_count = 3 + 1
2932
else:
30-
sol_count = (2 + 1) + (1 + 2)
31-
algorithmic_count = (2 + 1) + ((2 + 1) + (2 + 1))
33+
sol_count = (4 + 1) + (1 + 4)
34+
algorithmic_count = (4 + 1) + ((2 + 1) * 4)
3235

3336
buffer_size = self.N * 4
3437
return {'sol': buffer_size * sol_count, 'algorithmic': buffer_size * algorithmic_count}

0 commit comments

Comments
 (0)