Files
tinygrad/test/test_specific_conv.py
Diogo a9a1df785f Webgpu support (#1077)
* initial commit

* 81 passing

* 105 passing tests

* 148 passing

* CI tests

* install dep on ci

* try opencl pkgs

* try using vulkan

* down to only 6 failing

* refactor

* cleaning up

* another test skipped due to buffer limit

* linter

* segfault

* indent fix

* another segfault found

* small touchups

* Fix max and maxpool tests

* Add constant folding

* Add javascript export script

* better asserts in codegen

* manual upcasting

* reverted token type change

* skip safetensor test due to unsupported type

* FIx efficientnet and all other model tests

* Remove np copy

* fixed indent and missing import

* manually destroy the buffer

* revert back to length

* linter errors

* removed extra val

* skip broken tests

* skipping more tests

* Make the page pretty

* Save model weights as safetensor

* Fix imagenet to c test

* Fix second imagenet to c bug

* Async and paralel kernel compilation

* workgroup support

* reversed local size

* fixed non local bug

* correct local groups

* ci experiment

* removed typo

* Fix define local by using shared memory

* Refactor

* try running on mac

* match metal tests

* add more workers

* scope down tests

* trying windows runner

* fixed windows env

* see how many it can do

* merged master

* refactor

* missed refactor

* increase test suite coverage

* missing import

* whitespace in test_efficientnet.py

* getting there

* fixed reset

* fixed bufs

* switched to cstyle

* cleanup

* min/max rename

* one more linter issue

* fixed demo

* linter

* testing ci chrome

* add unsafe webgpu arg

* add build step

* remove WEBGPU from cmd line

* use module

* try forcing directx

* trying forced metal backend

* temp disable conv2d for CI

* disable conv_trasnpose2d

---------

Co-authored-by: 0x4d - Martin Loretz <20306567+martinloretzzz@users.noreply.github.com>
Co-authored-by: George Hotz <72895+geohot@users.noreply.github.com>
2023-07-12 12:52:06 -07:00

54 lines
2.2 KiB
Python

import unittest
from tinygrad.tensor import Tensor
from tinygrad.helpers import dtypes
from tinygrad.lazy import Device
# similar to test/external/external_test_gpu_ast.py, but universal
class TestSpecific(unittest.TestCase):
# from openpilot
# 1x1 6 <- 24
def test_1x1_6_24(self):
x = Tensor.randn(1, 24*4, 32, 64)
w = Tensor.randn(6*4, 24*4, 1, 1)
x.conv2d(w).permute(0,2,3,1).reshape(32, 384, 4).contiguous().realize()
def test_vec_mul(self):
# this forces it to be an image...
x = Tensor.ones(1, 512, 4).contiguous().reshape(1, 2048)
w = Tensor.randn(2048, 512)
(x @ w).reshape(1, 128, 4).contiguous().realize()
@unittest.skipIf(Device.DEFAULT in ["LLVM", "WEBGPU"], "Broken on LLVM and webgpu")
def test_big_vec_mul(self):
# from LLaMA
# 0 buffer<4096, dtypes.float> [View((1024, 1, 1, 4), (4, 0, 0, 1), 0, None)]
# 1 buffer<4096, dtypes.float> [View((1024, 1024, 4, 4), (0, 4, 1, 0), 0, None)]
# 2 buffer<16777216, dtypes.half> [View((1024, 1024, 4, 4), (16384, 4, 1, 4096), 0, None)]
x = Tensor.randn(4096).realize()
w = Tensor.randn(4096, 4096, device='cpu').cast(dtypes.float16).to(Device.DEFAULT).realize()
(x @ w.T).realize()
# from https://dl.acm.org/doi/pdf/10.1145/3495243.3517020
# ~260 GFLOPS on Adreno 640, should be 260*(720/890)*(596/710) = 176.5 on downclocked 630
# we get 170
def test_1x1_28_28(self):
x = Tensor.randn(1, 256, 28, 28)
w = Tensor.randn(256, 256, 1, 1)
x.conv2d(w).permute(0,2,3,1).reshape(28, 28*256//4, 4).contiguous().realize()
# 132 GFLOPS on Adreno 640, should be 132*(720/890)*(596/710) = 90 on downclocked 630
# gets 54 with broken opt, 74 without opt, and 146 if we pad and opt 3!
def test_3x3_28_28_stride_2(self):
x = Tensor.randn(1, 288, 36, 36)
w = Tensor.randn(384, 288, 3, 3)
x.conv2d(w, stride=2).permute(0,2,3,1).reshape(17, 17*384//4, 4).contiguous().realize()
def test_3x3_28_28_stride_2_padded(self):
x = Tensor.randn(1, 288, 36, 36)
w = Tensor.randn(384, 288, 3, 3)
x.conv2d(w, stride=2, padding=1).permute(0,2,3,1).reshape(18, 18*384//4, 4).contiguous().realize()
if __name__ == '__main__':
unittest.main()