Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-411

Arithmetic Intensity Of Matmul

Problem

Compute the arithmetic intensity of a dense matrix multiply with shapes (m, k) @ (k, n): flops = 2 * m * n * k and bytes_moved = bytes_per_value * (m * k + k * n + m * n) for reading both operands and writing the output.

The signature is arithmetic_intensity(m, n, k, bytes_per_value=2). Return flops per byte.

Hint

Count every element of both inputs and the output exactly once.

Test cases

case 1
in: [1,1,1,2]
expected: 0.3333333333
case 2
in: [512,512,512,2]
expected: 170.6666666667
case 3
in: [1024,4096,1024,2]
expected: 455.1111111111
case 4
in: [64,64,64,4]
expected: 10.6666666667
Starter codePython
def arithmetic_intensity(m, n, k, bytes_per_value=2):
    # Your code here
    pass

4 test cases · run your code against them in the editor