All Projects → tpoisonooo → how-to-optimize-gemm

tpoisonooo / how-to-optimize-gemm

Licence: MIT license
row-major matmul optimization

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
Cuda
1817 projects
objective c
16641 projects - #2 most used programming language
Mathematica
289 projects
Makefile
30231 projects

Projects that are alternatives of or similar to how-to-optimize-gemm

nordvpn
NordVpn Docker Client
Stars: ✭ 475 (+64.93%)
Mutual labels:  armv7, arm64
Cloudflare Ddns
🎉🌩️ Dynamic DNS (DDNS) service based on Cloudflare! Access your home network remotely via a custom domain name without a static IP!
Stars: ✭ 332 (+15.28%)
Mutual labels:  armv7, arm64
novix
kris nóva userspace and kernel tools for the Novix operating system
Stars: ✭ 33 (-88.54%)
Mutual labels:  armv7, arm64
tensorflow-serving-arm
TensorFlow Serving ARM - A project for cross-compiling TensorFlow Serving targeting popular ARM cores
Stars: ✭ 75 (-73.96%)
Mutual labels:  armv7, arm64
Pieman
Script for creating custom OS images for single-board computers
Stars: ✭ 149 (-48.26%)
Mutual labels:  armv7, arm64
alpine-php-fpm
Lightweight and optimised PHP-FPM (PHP 7.4, 8.0, 8.1) Docker images with essential extensions on top of latest Alpine Linux.
Stars: ✭ 53 (-81.6%)
Mutual labels:  armv7, arm64
Grafana On Raspberry
Grafana packages for raspberry pi (armv6/armv7) and aarch64/arm64
Stars: ✭ 318 (+10.42%)
Mutual labels:  armv7, arm64
focalboard-docker
Cross platform Docker images for Focalboard.
Stars: ✭ 12 (-95.83%)
Mutual labels:  armv7, arm64
Multi Arch Images
Support for multi-platform architecture Docker images using buildx.
Stars: ✭ 143 (-50.35%)
Mutual labels:  armv7, arm64
Element Web
element.io docker image generator
Stars: ✭ 21 (-92.71%)
Mutual labels:  armv7, arm64
discolix
distroless arm docker images
Stars: ✭ 22 (-92.36%)
Mutual labels:  armv7, arm64
Build Openssl Curl
Scripts to build OpenSSL, HTTP/2 (nghttp2) and cURL (libcurl) for MacOS, iOS and tvOS devices (x86_64, armv7, armv7s, arm64, arm64e). Now Supporting Apple Silicon, OpenSSL 1.1.1 with TLS 1.3 and Mac Catalyst builds.
Stars: ✭ 230 (-20.14%)
Mutual labels:  armv7, arm64
tiller-multiarch
Helm Tiller images for amd64, arm64, and armhf. ⚓️🎉
Stars: ✭ 80 (-72.22%)
Mutual labels:  armv7, arm64
docker-nagios
Docker image for Nagios Core in Alpine Linux with basic plugins, available for x86, x64 , ARM v6, ARM v7 and ARM64.
Stars: ✭ 33 (-88.54%)
Mutual labels:  armv7, arm64
docker-opengl
Multi-Arch Docker - Mesa 3D OpenGL Software Rendering (Gallium) - LLVMpipe, and OpenSWR Drivers
Stars: ✭ 68 (-76.39%)
Mutual labels:  armv7, arm64
Rappel
A linux-based assembly REPL for x86, amd64, armv7, and armv8
Stars: ✭ 818 (+184.03%)
Mutual labels:  armv7, arm64
Synestiaos
The Synestia Operating System
Stars: ✭ 159 (-44.79%)
Mutual labels:  armv7, arm64
alpine-qbittorrent-openvpn
qBittorrent docker container with OpenVPN client running as unprivileged user on alpine linux
Stars: ✭ 230 (-20.14%)
Mutual labels:  armv7, arm64
SPIR-V-Blast
Converting the C-like language to binary or human readable SPIR-V
Stars: ✭ 17 (-94.1%)
Mutual labels:  vulkan
Lift
Vulkan Path Tracer with Optix Denoiser integration
Stars: ✭ 30 (-89.58%)
Mutual labels:  vulkan

how-to-optimize-gemm

English | 简体中文

row-major matmul optimization

backend armv7 aarch64 aarch64-int8 cuda cuda-int4 vulkan x86
support ✔️ ✔️ ✔️ ✔️ WIP ✔️

All backends and corresponding tutorials

backend tutorial
aarch64 GEMM 入门
aarch64 GEMM caching
aarch64-int8 -
armv7 ARMv7 4x4kernel 懒人优化小实践
cuda cuda 入门的正确姿势:how-to-optimize-gemm
cuda-int4 WIP int4 炼丹要术
vulkan 如何火急火燎地上手 Vulkan

Build and run

Usage is similar for all backends:

  1. Open the backend directory to be used, and change the OLD and NEW of makefile to the same implementation for the first run, for example
$ cd aarch64
$ cat makefile
OLD    := MMult_4x4_10
NEW   := MMult_4x4_10
..
  1. makefilewill compile and run the implementation whichNEWpoint at, and copyoutput_MMult_4x4_10.mtooutput_new.m`
$ make run
$ cat output_new.m
  1. It may not be intuitive to look at the numbers directly, so draw a line chart
$ python3 -m pip install -r ../requirements.txt
$ python3 plot.py

Differences between backends

Specific to each hardware, there are subtle differences:

  • NEW may choose a different name
  • vulkan/int4 needs prerequisitions

1. armv7 and aarch64

A. Prepare armv7/aarch64 linux development environment, Raspberry Pi/rk3399/aws arm server are all fine.

B. By default ARCH := native, build and run directly

$ cd armv8 && make run

2. aarch64 int8

chgemm is an int8 gemm library.

  • blue line is chgemm implementation
  • orange line is aarch64 fp32 peak

Compared to the code in this tutorial, the differences are:

  1. Dealing with the boundary problem, unlike the tutorial where only multiples of 4 are considered;
  2. Int8 reaches a maximum of 18.6 gflops (relative to the theoretical limit of fp32 is only 14.3 on RK3399, gemmlowp is about 12-14gflops);
  3. Based on symmetric quantization, input value range must be in [-127, +127], and -128 cannot appear;
  4. Built-in small example about how to integrate into android studio

chgemm has been merged into ncnn INT8 convolution implementation.

3. x86 original

flame referenced by x86 is the original implementation, with some differences from this repo:

  1. The original is column-major x86 SSE version
  2. Both are tutorials, and the MMult_4x4_17.c written now can reach 70% of the armv8.1 CPU peak
  3. The boundary problem is not dealt with now, only the case where MNK is a multiple of 4 is considered; sub_kernel also only writes the simplest kind of assembly. Practical needs a simple adjustment;
  4. In terms of drawing, octave was discarded (it is too troublesome to configure the environment once for embedded devices), and python was used instead.

4. CUDA

This version is faster than NVIDIA cuBLAS

  • green line is MMult_cuda_12 without tensorcore
  • blue line is cuBLAS without tensorcore

  1. Need to install cuda driver and nvcc by yourself
  2. CPU OpenBLAS is required to do the baseline to verify that the values are correct

5. Vulkan

  1. vulkan build depends on kompute API packaging, see vulkan build documentation for details

  2. More about how to learn compute shader

6. CUDA int4

WIP

Introduce some tools

  • megpeak: For measuring hardware limit performance, support arm/x86/OCL..
  • perf: Available in linux system tools, for system-level performance analysis and disassembly
  • YHs_Sample: dalao 's implementation
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].