Repository navigation
Adding collectives HAL operations and compiler support. - #11342
Conversation
9fb6bba to
fe01ddb
Compare
| // TODO(#9580): check if nccl symbols are available - if not then we fail | ||
| // here and have the error propagated up to users. If we wanted to delay load | ||
| // NCCL we'd want to take a lock here, load it, and merge the symbols into the | ||
| // dynamic symbol table. | ||
| if (true) { | ||
| return iree_make_status( | ||
| IREE_STATUS_UNIMPLEMENTED, | ||
| "NCCL unavailable and collective operations cannot be performed"); |
There was a problem hiding this comment.
Ok cool, I was going to ask about this - there should probably be some minimum version check and channel creation should fail if using an older version / version without support, but checking for nccl symbols makes sense too.
There was a problem hiding this comment.
it'll take some time for collectives to work (compiler still needs work, runtime needs implementation) and it'll be unlikely that any extant compiler can target a (current) runtime with them - if this were a year from now we'd definitely want to gate it, though!
| iree_string_view_t key, | ||
| int64_t* out_value); | ||
|
|
||
| iree_status_t(IREE_API_PTR* create_channel)( |
There was a problem hiding this comment.
Can you think a bit about how to test this HAL code?
The HAL CTS allows for including and excluding tests: https://github.com/iree-org/iree/blob/main/runtime/src/iree/hal/drivers/cuda/cts/CMakeLists.txt so you could add a test that only runs on CUDA at the start, for example.
There was a problem hiding this comment.
CTS should may work for this stuff but if we need multiple processes collaborating it's likely to need its own dedicated runner to set that up. That could still be a C test that forks off other processes, though.
| // NOTE: this implementation is just for a single active device. As we start to | ||
| // support multiple devices we'll need to change this to be per-device. |
There was a problem hiding this comment.
I'm a bit worried about how many places assume single device. Do you think we'll be able to incrementally support multiple devices without some of these more advanced features (collectives in this case)?
There was a problem hiding this comment.
There's just a few passes at this point, but yeah, we'll need to fix them. My plan is to have one convention we use like emitForAllDevices(...callback...) and that these passes can all be updated for that - that helper could then emit the device selection logic and duplication if there are multiple devices live at a time.
| memcpy(id.data, params.id.data, IREE_ARRAYSIZE(id.data)); | ||
| } | ||
| if (iree_hal_cuda_nccl_id_is_empty(&id)) { | ||
| // TODO: maybe this is ok? a localhost alias or something? |
There was a problem hiding this comment.
I think it should be okay until we add a support for an automatic server bootstrapping, i.e., starting a server, getting the IP address, and broadcasting the IP address to the other process.
There was a problem hiding this comment.
yeah, for the broadcast stuff we will likely still want that to happen in the hosting application layer (PJRT/etc) and have them pass that in as the device default ID - or let the user create the channels themselves and pass those in via setters (func.func @set_channel(%channel: !hal.channel) etc) - I'm not sure we want to be in the business of MPI coordination at this layer but could have helpers for testing/etc in iree/tooling/
fe01ddb to
e1736ed
Compare
In the future it'd be nice to make this op support more flexible bindings for access so in-place is a single rw resource instead of a ro/wo pair.
This turns the CSE-able pure default op into a unique creation op that can be lowered into the HAL dialect.
It's modeled like stream.async.copy (for better or worse at least consistent) but will likely change as part of #11249 for supporting in-place collectives (or, stream.async.copy will be updated for memmove-like behavior). Locations in the code that need updating have been marked with a TODO. The send/recv ops are not yet modeled and will likely be done as dedicated ops due to their unary operand/result nature.
e1736ed to
0066c7a
Compare
This adds end-to-end support from a new
stream.async.collectiveop and communication channel type down through the HAL and all the way to runtime.Conceptually collective operations are commands that can be recorded into command buffers and the various HAL backends can decide how to implement them. The commands are transfer-like but may be implemented with dispatch logic.
We could offer a local emulated channel that let us simulate multiple devices by performing copies but this first version just returns unimplemented on all backends. A skeleton of the runtime support is provided for NCCL support in the CUDA backend. In the future we can add local/ backend support for various collective libraries if we want or expose a factory mechanism on device creation to allow hosting applications control over the communication channels and routing. A utility has been added to allow command buffer implementations to accumulate batches of collective operations for efficient submission to the underlying library APIs.
There are several areas future changes will focus on but what's here should be enough for some basic hello-world programs, major things missing:
stream.async.*levelThe next steps for wiring this up are to implement NCCL shared library loading, implement the
TODO(#9580)s in the code for calling into NCCL, and some representation of collectives at the flow level that lower into the stream ops.Progress on #9580.