Skip to content

metal_adder::verify() is so fast, something doesn't seem right. #1

Description

@ericmoderbacher

Thanks for sharing this repo. I've been playing with it on my m1 MacBook Air. For giggles I wanted to see how much faster the GPU execution time was than the verification function, which also is doing the addition locally. To my surprise verify() was faster.

if the vector lengths are set to 1,000,000 these are my measurements:

metal data prep took 14947µs.
metal commit took 22µs.
metal wait untill complete took 2584µs.
TEST PASSED
metal verify took 641µs.

and for 10,000,000:

metal data prep took 155846µs.
metal commit took 29µs.
metal wait untill complete took 7725µs.
TEST PASSED
metal verify took 7402µs.

I wanted to share in case you didn't notice how quick verify is. I will be looking at this closer this weekend. It seems like there is some sort of 2000µs-ish overhead in the wait call.

By the way I even tried modifying verify to see if the difference was that verify only had to access elements and not write to them:

void metal_adder::verify() {
  auto a = (float *)_A->contents();
  auto b = (float *)_B->contents();
  auto c = (float *)_C->contents();

  for (unsigned long i = 0; i < vector_length; ++i) {
    if (c[i] != (a[i] + b[i])) {
      std::cout << "\033[1;31m TEST FAILED \033[0m\n";
    }
    c[i] = a[i] + b[i];
  }
  std::cout << "\033[1;32m TEST PASSED \033[0m\n";
}

And it was still a bit faster!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions