Skip to content

Adding collectives HAL operations and compiler support. - #11342

Merged
benvanik merged 6 commits into
mainfrom
benvanik-collectives
Dec 6, 2022
Merged

benvanik merged 6 commits into
mainfrom
benvanik-collectives

Conversation

@benvanik

Copy link
Copy Markdown
Collaborator

This adds end-to-end support from a new stream.async.collective op 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:

  • send/recv are not available at the stream.async.* level
  • collectives cannot currently be performed in-place (Support in-place collective operations in stream dialect transformations. #11249 is tracking the support required)
  • supported collective element types and reduction operators are basically just NCCL
  • emulation for unsupported element types and reduction operators is missing - we should insert casts and such at higher levels

The 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.

@benvanik
benvanik force-pushed the benvanik-collectives branch 3 times, most recently from 9fb6bba to fe01ddb Compare November 29, 2022 17:12
@benvanik
benvanik marked this pull request as ready for review November 29, 2022 17:38
@benvanik
benvanik removed the request for review from antiagainst November 29, 2022 17:38
Comment on lines +253 to +260
// 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");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +28 to +29
// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@okkwon okkwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/

@benvanik
benvanik force-pushed the benvanik-collectives branch from fe01ddb to e1736ed Compare December 6, 2022 00:17
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.
@benvanik
benvanik force-pushed the benvanik-collectives branch from e1736ed to 0066c7a Compare December 6, 2022 01:53
@benvanik
benvanik merged commit 27be42f into main Dec 6, 2022
@benvanik
benvanik deleted the benvanik-collectives branch December 6, 2022 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants