Skip to content

Commit 295d4db

Browse files
committed
add intranode P2P async transfer and remove chunk
1 parent 9f1a519 commit 295d4db

8 files changed

Lines changed: 324 additions & 266 deletions

File tree

python/triton/experimental/tle/language/raw/core.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ def _tle_raw_call(func, args, *, output_indices, hint, smem, _semantic):
7070
source_id = func.register_pending_source(hint=hint)
7171
dsl_region_op = func.create_region_deferred(_semantic.builder, source_id, handles, alias_indices, hint)
7272
else:
73-
if func.compiler.lower() == "nvcc" or (func.compiler.lower() == "clang" and func.target.lower() == "bc"):
74-
patch_hash_method_for_pointer_type()
75-
module = import_from_path(func.extern_file)
76-
target_fn = getattr(module, func.extern_func_name)
77-
ret = target_fn(*args, _semantic=_semantic)
78-
return ret
73+
if func.compiler is not None:
74+
if func.compiler.lower() == "nvcc" or (func.compiler.lower() == "clang" and func.target is not None
75+
and func.target.lower() == "bc"):
76+
patch_hash_method_for_pointer_type()
77+
module = import_from_path(func.extern_file)
78+
target_fn = getattr(module, func.extern_func_name)
79+
ret = target_fn(*args, _semantic=_semantic)
80+
return ret
7981

8082
handles = [arg.handle for arg in args]
8183
context = _semantic.builder.get_context()

python/triton/experimental/tle/raw/cuda/runtime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ def __init__(self, fn: Any, file: Path, *args, **kwargs) -> None:
165165
self.deferred: Final[bool] = kwargs.get("deferred", False)
166166
self.__triton_builtin__: Final[bool] = True
167167

168-
if self.compiler.lower() == "nvcc" and knobs.runtime.add_stages_inspection_hook is None:
168+
if self.compiler is not None and self.compiler.lower(
169+
) == "nvcc" and knobs.runtime.add_stages_inspection_hook is None:
169170
nvcc_cuda_hook = partial(make_cubin_inspection_hook, self)
170171
knobs.runtime.add_stages_inspection_hook = nvcc_cuda_hook
171172

python/tutorials/tle/raw/nvshmem/01-simple-shift/simple-shift.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from common.utils import (
1010
install_cumodule_hook,
1111
load_library,
12+
tensor_from_pointer,
1213
prepare_clang_bitcode,
1314
)
1415

@@ -30,18 +31,6 @@ def simple_shift_kernel(destination_ptr, ):
3031
tle_raw.call(simple_shift, [destination_ptr])
3132

3233

33-
def tensor_from_pointer(pointer, shape, dtype, device):
34-
num_elements = 1
35-
for extent in shape:
36-
num_elements *= extent
37-
storage = torch._C._construct_storage_from_data_pointer(
38-
pointer.value,
39-
device,
40-
num_elements * dtype.itemsize,
41-
)
42-
return torch.empty(0, dtype=dtype, device=device).set_(storage).view(shape)
43-
44-
4534
def simpe_shift():
4635
common_path = Path(__file__).parents[1] / "common" / "common-host.so"
4736
host_path = Path(__file__).with_name("simple-shift-host.so")
@@ -79,6 +68,7 @@ def simpe_shift():
7968
common_lib,
8069
mype_in_node.value,
8170
Path(__file__).with_name("simple-shift-device.bc"),
71+
Path(__file__).with_name("simple-shift-device.cu"),
8272
simple_shift,
8373
)
8474

python/tutorials/tle/raw/nvshmem/02-allgather-gemm/ag-gemm-device.cu

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,33 @@ enum {
1717
};
1818

1919
extern "C" __device__ __attribute__((always_inline)) void
20-
ag_mark_local_ready(__attribute__((address_space(1))) uint64_t *ready, int rank,
21-
int num_chunks) {
22-
int chunk_id = (int)blockIdx.x;
23-
if (chunk_id >= num_chunks) {
24-
return;
25-
}
20+
ag_mark_local_ready(__attribute__((address_space(1))) uint64_t *ready,
21+
int rank) {
2622
if (threadIdx.x == 0) {
2723
__threadfence_system();
28-
ready[(size_t)rank * num_chunks + chunk_id] = 1;
24+
ready[(size_t)rank] = 1;
2925
}
3026
__syncthreads();
3127
}
3228

33-
// One Triton program publishes one chunk of this rank's A slice to one peer.
3429
extern "C" __device__ __attribute__((always_inline)) void
35-
ag_publish_local_chunk(__attribute__((address_space(1))) __half *workspace,
36-
__attribute__((address_space(1))) uint64_t *ready,
37-
int elements_per_rank, int elements_per_chunk,
38-
int num_chunks, int rank, int world_size) {
39-
int block_id = (int)blockIdx.x;
40-
int peer_offset = block_id / num_chunks + 1;
41-
int chunk_id = block_id % num_chunks;
30+
ag_publish_local_rank(__attribute__((address_space(1))) __half *workspace,
31+
__attribute__((address_space(1))) uint64_t *ready,
32+
int elements_per_rank, int rank, int world_size) {
33+
int peer_offset = (int)blockIdx.x + 1;
4234
if (peer_offset >= world_size) {
4335
return;
4436
}
4537

4638
int peer = (rank + peer_offset) % world_size;
47-
__half *local_chunk = workspace + (size_t)rank * elements_per_rank +
48-
(size_t)chunk_id * elements_per_chunk;
49-
uint64_t *chunk_ready = ready + (size_t)rank * num_chunks + chunk_id;
39+
__half *local_rank = workspace + (size_t)rank * elements_per_rank;
40+
uint64_t *rank_ready = ready + (size_t)rank;
5041

51-
nvshmemx_putmem_signal_nbi_block(local_chunk, local_chunk,
52-
(size_t)elements_per_chunk * sizeof(__half),
53-
chunk_ready, 1, NVSHMEM_SIGNAL_SET, peer);
42+
nvshmemx_putmem_signal_nbi_block(local_rank, local_rank,
43+
(size_t)elements_per_rank * sizeof(__half),
44+
rank_ready, 1, NVSHMEM_SIGNAL_SET, peer);
5445
}
5546

56-
// The GEMM program waits for the source chunk whose A rows it will consume.
5747
extern "C" __device__ __attribute__((always_inline)) void
5848
ag_wait_ready(__attribute__((address_space(1))) uint64_t *ready,
5949
int signal_index) {

python/tutorials/tle/raw/nvshmem/02-allgather-gemm/ag-gemm-host.cu

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
} \
1717
} while (0)
1818

19-
extern "C" int ag_gemm_workspace_create(int elements_per_rank, int num_chunks,
20-
void **workspace, uint64_t **ready,
21-
int *mype, int *npes, int *mype_in_node,
22-
int *npes_in_node) {
23-
if (elements_per_rank <= 0 || num_chunks <= 0 || workspace == nullptr ||
24-
ready == nullptr) {
19+
extern "C" int ag_gemm_workspace_create(int elements_per_rank, void **workspace,
20+
uint64_t **ready, int *mype, int *npes,
21+
int *mype_in_node, int *npes_in_node) {
22+
if (elements_per_rank <= 0 || workspace == nullptr || ready == nullptr) {
2523
return -1;
2624
}
2725

@@ -33,8 +31,7 @@ extern "C" int ag_gemm_workspace_create(int elements_per_rank, int num_chunks,
3331

3432
size_t workspace_bytes = (size_t)(*npes) * elements_per_rank * sizeof(__half);
3533
*workspace = nvshmem_malloc(workspace_bytes);
36-
*ready = (uint64_t *)nvshmem_calloc((size_t)(*npes) * num_chunks,
37-
sizeof(uint64_t));
34+
*ready = (uint64_t *)nvshmem_calloc((size_t)(*npes), sizeof(uint64_t));
3835
if (*workspace == nullptr || *ready == nullptr) {
3936
if (*ready != nullptr) {
4037
nvshmem_free(*ready);
@@ -56,3 +53,11 @@ extern "C" int ag_gemm_workspace_destroy(void *workspace, void *ready) {
5653
nvshmem_free(workspace);
5754
return 0;
5855
}
56+
57+
extern "C" void *ag_gemm_peer_workspace_ptr(void *workspace, int peer) {
58+
return nvshmem_ptr(workspace, peer);
59+
}
60+
61+
extern "C" uint64_t *ag_gemm_peer_ready_ptr(uint64_t *ready, int peer) {
62+
return (uint64_t *)nvshmem_ptr(ready, peer);
63+
}

0 commit comments

Comments
 (0)