Skip to content

Commit 5bd02cb

Browse files
committed
- Add README
- Simplify Conv1d implementation by using fast_conv and cuda_conv
1 parent fe07c94 commit 5bd02cb

File tree

2 files changed

+5
-185
lines changed

2 files changed

+5
-185
lines changed

README.md

Lines changed: 0 additions & 163 deletions
This file was deleted.

minitorch/nn/layers.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,11 @@ def __init__(self, in_channels, out_channels, kernel_width, backend, stride=1, i
3636
self.kernel_width = kernel_width
3737

3838
def forward(self, input):
39-
batch, in_channels, w = input.shape
40-
kw = self.kernel_width
41-
stride = self.stride
42-
out_channels = self.weights.value.shape[0]
43-
44-
out_w = (w - kw) // stride + 1
45-
46-
output = input.zeros((batch, out_channels, out_w))
47-
48-
for b in range(batch):
49-
for oc in range(out_channels):
50-
for ow in range(out_w):
51-
start_w = ow * stride
52-
total = 0.0
53-
for ic in range(in_channels):
54-
for k in range(kw):
55-
iw = start_w + k
56-
if iw < w:
57-
total += input[b, ic, iw] * self.weights.value[oc, ic, k]
58-
output[b, oc, ow] = total + self.bias.value[0, oc, 0]
59-
60-
return output
39+
if self.backend.cuda and cuda_conv is not None:
40+
out = cuda_conv.conv1d(input, self.weights.value, self.stride) + self.bias.value
41+
else:
42+
out = fast_conv.conv1d(input, self.weights.value, self.stride) + self.bias.value
43+
return out
6144

6245

6346
class Conv2d(Module):

0 commit comments

Comments
 (0)