Giter Club home page Giter Club logo

go-mm's Introduction

go-mm

This project explores the usage of Apple's Metal-compatible GPUs from Go code, using Objective-C bindings, Metal Shading Library source files, and the Metal Performance Shaders library. The performance of matrix multiplication tasks is compared across a couple different hand-written MSL implementations, the MPS library, Gonum and OpenBLAS, and hand-written Go implementations.

High Level Overview

This project is discussed in detail in this blog post, which also explains more about how cgo is used and how the Metal APIs work.

This program is fairly simple:

  ~/code/go-mm ~>> ./go-mm --help
  Usage of ./go-mm:
  -fast
    	Enable fast mode
  -gpu-only
    	Use GPU only
  -incr string
    	Incremental integer value

  ~/code/go-mm ~>> go build -o go-mm
  ~/code/go-mm ~>> ./go-mm 
  2023-12-01 18:29:27.097 go-mm[82758:22587913] Using default device Apple M2
  elements naive transpose transpose_parallel metal_naive metal_transpose mps gonum openblas
  160000 206.33 199.33 42.67 8.33 5.67 0.33 5.00 1.33
  250000 382.33 401.00 89.33 11.33 7.33 0.00 9.33 3.67
  360000 663.00 683.00 146.33 18.33 11.00 0.00 16.67 10.33 
  ^C
  ~/code/go-mm ~>> ./go-mm --gpu-only
  2023-12-01 18:33:07.687 go-mm[82789:22590787] Using default device Apple M2
  elements metal_naive metal_transpose mps
  160000 7.33 6.67 0.67
  250000 7.33 9.00 0.00
  360000 9.00 10.33 0.00
  490000 12.33 14.33 1.00
  640000 18.00 20.67 1.00
  810000 24.67 28.33 1.33
  1000000 35.00 38.67 2.00

This data can be used to plot a graph of multiplication time in ms, via the provided Python script

Performance Graph

Plotting results removing the slowest three methods:

Performance Graph - Fast Implementations

Plotting results is trivial through the provided Python script

~/code/go-mm ~>> python3 plot.py ./z --gpuonly

In order to build this project, it is expected that OpenBLAS is installed through brew. You can see in main.go the following flags are passed to compilation of the underlying cgo compilation:

#cgo LDFLAGS: -framework Foundation -framework Metal -framework MetalPerformanceShaders -framework CoreGraphics -L/opt/homebrew/opt/openblas/lib -lopenblas

If you need to install OpenBLAS through a different method, make sure to modify this linker argument. You will also need to ensure that netlib is installed, as a dependency for Gonum.

go-mm's People

Contributors

mikecvet avatar

Stargazers

Arunava Basu avatar Vyom Sharma avatar Madan Kumar Y avatar Ekansh Agrawal avatar

Watchers

 avatar

Forkers

ashishd hiboyang

go-mm's Issues

Cannot run on macOS M1

When I tried downloading the project files, and running the project using go build, it instantly kills when I run ./go-mm. Using GoLand IDE btw.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.