Giter Site home page Giter Site logo

matrix-gpu's Introduction

Matrix Multiplication on GPU

There are 2 programs: cpu and gpu. Both of them does the same thing is multiply two 1000 x 1000 matrices.

The algorithm to multiply is simple:

for (int row = 0; row < MATRIX_SIZE; row++) {
    for (int col = 0; col < MATRIX_SIZE; col++) {
      ulong sum = 0;
      for (int k = 0; k < MATRIX_SIZE; k++) {
        sum += A[row * MATRIX_SIZE + k] * B[k * MATRIX_SIZE + col];
      }
      C[row * MATRIX_SIZE + col] = sum;
    }
  }

The GPU program uses OpenCL.

How to run

On macOS, compile with Make:

make

Them run the CPU program with:

./cpu

Run the GPU program with:

./gpu

Compare the result

To compare the result of the two methods, do the following steps:

Step 1: Run CPU code and save the output to output_cpu file:

./cpu > output_cpu

Step 2: Run GPU code and save the output to output_gpu file:

./gpu > output_gpu

Step 3: Use diff to compare the two results to make sure outputs are the same:

diff output_cpu output_gpu

The only different is the running time. For example:

< Runtime: 4.849347ms
---
> Runtime: 0.001779ms

matrix-gpu's People

Contributors

huytd avatar

Watchers

 avatar James Cloos avatar  avatar

matrix-gpu's Issues

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.