| 903 | } |
| 904 | |
| 905 | int main() { |
| 906 | char* version_str = getenv("MATMUL_VERSION"); |
| 907 | int version = version_str == NULL ? 10 : atoi(version_str); |
| 908 | // 1 == f32: No-Op |
| 909 | // 2 == f32: naive matmul |
| 910 | // 3 == f32: tiling |
| 911 | // 4 == f32: 1D blocktiling |
| 912 | // 5 == f32: 2D blocktiling |
| 913 | // 6 == f32: 1D blocktiling with loop unrolling |
| 914 | // 7 == f32: 2D blocktiling with loop unrolling |
| 915 | // 8 == f32: 2D blocktiling with loop unrolling and vectorization |
| 916 | // 9 == f32: 2D blocktiling with loop unrolling, vectorization and transpose |
| 917 | // 10 == f16: 2D blocktiling with loop unrolling and vectorization (default) |
| 918 | // 11 == f16: 2D blocktiling with loop unrolling, vectorization and transpose |
| 919 | bool enableF16 = version == 10 || version ==11; |
| 920 | bool transposedInput = version == 9 || version == 11; |
| 921 | NumType numtype = enableF16 ? kf16 : kf32; |
| 922 | |
| 923 | size_t M, K, N; // Matrix dimensions |
| 924 | char* kTestSize_str = getenv("MATMUL_SIZE"); |
| 925 | int kTestSize = kTestSize_str == NULL ? 2 : atoi(kTestSize_str); |
| 926 | if (kTestSize == 0) { |
| 927 | // Tiny test |
| 928 | M = 32; |
| 929 | K = 32; |
| 930 | N = 32; |
| 931 | } else if (kTestSize == 1) { |
| 932 | // Small test |
| 933 | M = 256; |
| 934 | K = 128; |
| 935 | N = 512; |
| 936 | } else { |
| 937 | // Large test |
| 938 | M = 4096; |
| 939 | K = 4096; |
| 940 | N = 2 * 4096; |
| 941 | } |
| 942 | |
| 943 | #ifdef METAL_PROFILER |
| 944 | startCapture(); |
| 945 | #endif |
| 946 | if (enableF16) { |
| 947 | runTestWithCheck<half>(version, M, K, N, transposedInput, kTestSize, numtype); |
| 948 | } else { |
| 949 | runTestWithCheck<float>(version, M, K, N, transposedInput, kTestSize, numtype); |
| 950 | } |
| 951 | #ifdef METAL_PROFILER |
| 952 | stopCapture(); |
| 953 | #endif |
| 954 | |
| 955 | LOG(kDefLog, kInfo, "Done."); |
| 956 | return 0; |
| 957 | } |