GithubHelp home page GithubHelp logo

Comments (6)

justinjfu avatar justinjfu commented on July 17, 2024

Do you have a minimal code example that can reproduce?

Just profiling jax.block_until_ready(jax.numpy.zeros((9500000,3), dtype=jnp.float32)) in isolation takes <500us on my end on a V100.

from jax.

chihuahua avatar chihuahua commented on July 17, 2024

Oh, XLA JIT compilation should be used to reproduce. Thank you! I can repro a compute time latency of 131 microseconds with

@jax.jit
def run_zeros() -> jax.Array:
  """Run the main logic to benchmark."""
  with jax.named_scope("benchmark_broadcast"):
    return jnp.zeros((9500000, 3), dtype=jnp.float32)

values = run_zeros()
  jax.block_until_ready(values)
  print(values)

image

The resulting HLO indicates the slow broadcast:

@@f32[9500000,3]{1,0} fusion(), kind=kLoop, calls=
 {
   tmp_0 = f32[] constant(0)
   ROOT tmp_1 = f32[9500000,3]{1,0} broadcast(f32[] tmp_0), dimensions={}
 }

from jax.

chihuahua avatar chihuahua commented on July 17, 2024

Might it be possible that the CUDA implementation for broadcast here only uses 1 SM? And is thus not parallelized?

from jax.

hawkinsp avatar hawkinsp commented on July 17, 2024

Ah, it's 130 microseconds, not milliseconds?

I don't think it's physically possible to do better?

A V100 has 900GB/s memory bandwidth, per the specs. 9500000 * 3 * 4 bytes / 900e9 bytes/sec = 127us.

(I'm a bit surprised here, actually, I thought NVIDIA's published bandwidth numbers are bidirectional, which would mean twice as long, but your measurement seems to indicate otherwise.)

So... unless I'm mistaken, you're almost getting roofline memory bandwidth and you should not expect to do better?

from jax.

chihuahua avatar chihuahua commented on July 17, 2024

Ohhh... Apologies. It is 131 microseconds! I have corrected the original post.

from jax.

chihuahua avatar chihuahua commented on July 17, 2024

Thank you for the analysis! I suppose allocating a new memory block (versus reading from existing memory) also encounters this memory bandwidth. That would present a bottleneck indeed that means we can't do better.

from jax.

Related Issues (20)

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.