Skip to content

Commit 49a7547

Browse files
authored
Merge branch 'main' into feature/tle_fix_extract_tile
2 parents 52f252c + 04215a5 commit 49a7547

33 files changed

Lines changed: 3608 additions & 432 deletions

File tree

.github/new-prs-labeler.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CORE:
3030
- 'cmake/**'
3131
- 'include/**'
3232
- 'lib/**'
33-
- 'python/**'
3433
- 'scripts/**'
3534
- 'test/**'
3635
- 'unittest/**'
@@ -45,6 +44,19 @@ CORE:
4544
- 'setup.py'
4645
- '.github/actions/**'
4746
- '.github/workflows/code-format-check.yml'
47+
- all-globs-to-any-file:
48+
- 'python/**'
49+
- '!python/setup_tools/utils/cambricon.py'
50+
- '!python/setup_tools/utils/enflame.py'
51+
- '!python/setup_tools/utils/hcu.py'
52+
- '!python/setup_tools/utils/iluvatar.py'
53+
- '!python/setup_tools/utils/metax.py'
54+
- '!python/setup_tools/utils/mthreads.py'
55+
- '!python/setup_tools/utils/ppu.py'
56+
- '!python/setup_tools/utils/rpu.py'
57+
- '!python/setup_tools/utils/sunrise.py'
58+
- '!python/setup_tools/utils/thrive.py'
59+
- '!python/setup_tools/utils/xpu.py'
4860

4961
# ==========================================
5062
# 2. CI/CD Labels
@@ -128,6 +140,7 @@ cambricon:
128140
- 'third_party/cambricon/**'
129141
- '.github/workflows/cambricon*'
130142
- '.github/workflows/benchmark/cambricon/**'
143+
- 'python/setup_tools/utils/cambricon.py'
131144

132145
cpu:
133146
- changed-files:
@@ -142,40 +155,45 @@ enflame:
142155
- 'third_party/enflame/**'
143156
- '.github/workflows/enflame*'
144157
- '.github/workflows/benchmark/enflame/**'
158+
- 'python/setup_tools/utils/enflame.py'
145159

146160
hcu:
147161
- changed-files:
148162
- any-glob-to-any-file:
149163
- 'third_party/hcu/**'
150164
- '.github/workflows/hcu*'
151165
- '.github/workflows/benchmark/hcu/**'
166+
- 'python/setup_tools/utils/hcu.py'
152167

153168
iluvatar:
154169
- changed-files:
155170
- any-glob-to-any-file:
156171
- 'third_party/iluvatar/**'
157172
- '.github/workflows/iluvatar*'
158173
- '.github/workflows/benchmark/iluvatar/**'
174+
- 'python/setup_tools/utils/iluvatar.py'
159175

160176
metax:
161177
- changed-files:
162178
- any-glob-to-any-file:
163179
- 'third_party/metax/**'
164180
- '.github/workflows/metax*'
165181
- '.github/workflows/benchmark/metax/**'
182+
- 'python/setup_tools/utils/metax.py'
166183

167184
mthreads:
168185
- changed-files:
169186
- any-glob-to-any-file:
170187
- 'third_party/mthreads/**'
171188
- '.github/workflows/mthreads*'
172189
- '.github/workflows/benchmark/mthreads/**'
190+
- 'python/setup_tools/utils/mthreads.py'
173191

174192
nvidia:
175193
- changed-files:
176194
- any-glob-to-any-file:
177195
- 'third_party/nvidia/**'
178-
- '.github/workflows/nv*'
196+
- '.github/workflows/nvidia*'
179197
- '.github/workflows/benchmark/nvidia/**'
180198

181199
ppu:
@@ -184,27 +202,31 @@ ppu:
184202
- 'third_party/ppu/**'
185203
- '.github/workflows/ppu*'
186204
- '.github/workflows/benchmark/ppu/**'
205+
- 'python/setup_tools/utils/ppu.py'
187206

188207
rpu:
189208
- changed-files:
190209
- any-glob-to-any-file:
191210
- 'third_party/rpu/**'
192211
- '.github/workflows/rpu*'
193212
- '.github/workflows/benchmark/rpu/**'
213+
- 'python/setup_tools/utils/rpu.py'
194214

195215
sunrise:
196216
- changed-files:
197217
- any-glob-to-any-file:
198218
- 'third_party/sunrise/**'
199219
- '.github/workflows/sunrise*'
200220
- '.github/workflows/benchmark/sunrise/**'
221+
- 'python/setup_tools/utils/sunrise.py'
201222

202223
thrive:
203224
- changed-files:
204225
- any-glob-to-any-file:
205226
- 'third_party/thrive/**'
206227
- '.github/workflows/thrive*'
207228
- '.github/workflows/benchmark/thrive/**'
229+
- 'python/setup_tools/utils/thrive.py'
208230

209231
tileir:
210232
- changed-files:
@@ -233,6 +255,7 @@ xpu:
233255
- 'third_party/xpu/**'
234256
- '.github/workflows/xpu*'
235257
- '.github/workflows/benchmark/xpu/**'
258+
- 'python/setup_tools/utils/xpu.py'
236259

237260
# ====================================================================================
238261
# 6. TLE Labels

.github/workflows/rpu3.6-build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ concurrency:
3939
# (cancel-in-progress: false) so an in-flight board test is never interrupted
4040
# mid-run (a cancelled smoke can orphan a launch_kernel_runner that wedges
4141
# /dev/rpu for the next job).
42-
group: rpu3.6-board
42+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
4343
cancel-in-progress: false
4444

4545
# The RPU CI runner is a small x86 host that orchestrates the build/test on a

.github/workflows/sunrise3.6-build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
export TRITON_OFFLINE_BUILD=1
7272
export TRITON_BUILD_PROTON=OFF
7373
export FLAGTREE_BACKEND=sunrise
74-
MAX_JOBS=32 python3 -m pip install . --no-build-isolation -v
74+
MAX_JOBS=32 python3 -m pip install . -v
7575
7676
- name: Clear cache if ClearCache label present
7777
if: steps.check_backend.outputs.should_skip != 'true'

python/setup_tools/utils/sunrise.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def configure_llvm(path):
3333
cache.store(
3434
file="sunrise_llvm22_dev_release",
3535
condition=is_sunrise,
36-
url="https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/llvm-1fdc1dfa-triton-v3.6.x.tar.gz",
36+
url="https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/llvm-9027ac27-triton-v3.6.x.tar.gz",
3737
pre_hook=lambda: check_env("LLVM_SYSPATH"),
3838
post_hook=configure_llvm,
3939
)
4040
cache.store(
4141
file="sunriseTritonPlugin.so",
4242
condition=is_sunrise and not os.environ.get("FLAGTREE_PLUGIN"),
43-
url="https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/sunriseTritonPlugin_v0.6.0.tar.gz",
44-
md5_digest="f3c65d44",
43+
url="https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/sunriseTritonPlugin_v0.6.0.4.tar.gz",
44+
md5_digest="4c77b8c0",
4545
)
4646

4747

python/test/tle/unit/test_tle_cumsum.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ def _is_hcu_backend():
2727
threads_per_warp = get_current_target().warp_size if is_hip() else 32
2828

2929

30-
def _is_amd_hip_backend():
31-
return is_hip() and not FLAGTREE_BACKEND
32-
33-
3430
def _require_cuda():
3531
try:
3632
if _is_enflame_backend():
@@ -280,7 +276,6 @@ def test_tle_cumsum_amdgcn_fastpath_regression_guard():
280276
"Detected predicated ds_write: possible regression to generic path"
281277

282278

283-
@pytest.mark.skipif(_is_amd_hip_backend(), reason="requires AMD local-pointer lowering")
284279
def test_tle_cumsum_helper_preserves_adjacent_sentinel():
285280
block = 512
286281
num_warps = block // threads_per_warp
@@ -302,7 +297,6 @@ def test_tle_cumsum_helper_preserves_adjacent_sentinel():
302297
torch.testing.assert_close(sentinel, expected_sentinel)
303298

304299

305-
@pytest.mark.skipif(_is_amd_hip_backend(), reason="requires AMD local-pointer lowering")
306300
def test_tle_cumsum_scalar_base_addptr_alias_regression():
307301
block = 512
308302
num_warps = block // threads_per_warp

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def __init__(self, fn: Any, file: Path, *args, **kwargs) -> None:
234234
self.lowered_region_dialect: Final[str] = "llvm"
235235
self.arg_dialect: Final[str] = "llvm"
236236
self.source_file: Final[str] = str(file)
237+
self.opt_level: Final[str] = kwargs.get("opt_level", "-O3")
237238

238239
if self.library == "nvshmem":
239240
from triton.experimental.tle.raw.nvshmem.utils import enable_nvshmem_device_bc
@@ -259,7 +260,7 @@ def register_pending_source(self, *, hint: str = "") -> str:
259260
extern_func_name=self.extern_func_name,
260261
source=self.code,
261262
hint=hint,
262-
extra={"source_file": self.source_file},
263+
extra={"source_file": self.source_file, "opt_level": self.opt_level},
263264
)
264265

265266
def create_region_by_llvm(self, builder, llvm: str, handles, alias_indices, hint: str = "",
@@ -285,7 +286,7 @@ def make_llvm(self, mlir_context) -> str:
285286
"--cuda-device-only",
286287
_get_cuda_gpu_arch(),
287288
"-emit-llvm",
288-
"-O2",
289+
self.opt_level,
289290
"-S",
290291
"-",
291292
"-o",
@@ -314,5 +315,6 @@ def read_text(self):
314315
file=_CudaSourceFile(),
315316
extern_func_name=entry.get("extern_func_name"),
316317
deferred=True,
318+
opt_level=entry.get("opt_level"),
317319
)
318320
return cuda_fn.make_llvm(context)

python/triton/experimental/tle/raw/nvshmem/utils.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def _compile_cuda_host_to_cache(
222222
f"-L{lib_dir}",
223223
f"-l:{host_lib.name}",
224224
"-lnvshmem_device",
225+
"-lcuda",
225226
"-Xlinker",
226227
"-rpath",
227228
"-Xlinker",
@@ -313,12 +314,23 @@ def init_nvshmem_by_torch_pg(common, group):
313314
torch.distributed.barrier(group=group)
314315

315316

316-
def tensor_from_pointer(pointer, shape, dtype, device):
317+
def tensor_from_pointer(
318+
pointer: int | ctypes.c_void_p,
319+
shape: tuple[int, ...],
320+
dtype: torch.dtype,
321+
device: torch.device,
322+
) -> torch.Tensor:
323+
"""Create a non-owning Torch tensor view over a CUDA allocation."""
324+
address = pointer.value if isinstance(pointer, ctypes.c_void_p) else pointer
325+
if address is not None and not isinstance(address, int):
326+
raise TypeError(f"pointer must be int or ctypes.c_void_p, got {type(pointer).__name__}")
327+
if not address:
328+
raise ValueError("pointer cannot be null; CUDA memory must be allocated")
317329
elements = 1
318330
for extent in shape:
319331
elements *= extent
320332
storage = torch._C._construct_storage_from_data_pointer(
321-
pointer.value,
333+
address,
322334
device,
323335
elements * dtype.itemsize,
324336
)
@@ -336,6 +348,18 @@ def set_signal_cuda_ptr(signal_ptr, signal, stream):
336348
CUDA_CHECK(err)
337349

338350

351+
def copy_on_stream(dst_ptr, src_ptr, nbytes, stream):
352+
_, cudart = _get_cuda_modules()
353+
(err, ) = cudart.cudaMemcpyAsync(
354+
dst_ptr,
355+
src_ptr,
356+
nbytes,
357+
cudart.cudaMemcpyKind.cudaMemcpyDefault,
358+
stream.cuda_stream,
359+
)
360+
CUDA_CHECK(err)
361+
362+
339363
def print_perf(
340364
name: str,
341365
value: float,

python/triton/runtime/autotuner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def prune_configs(self, kwargs: Dict) -> List[Config]:
310310
pruned_configs = copy.deepcopy(self.configs)
311311
# pruned_configs = self.configs
312312
if self.early_config_prune:
313-
pruned_configs = self.early_config_prune(self.configs, self.nargs, **kwargs)
313+
pruned_configs = self.early_config_prune(pruned_configs, self.nargs, **kwargs)
314314
if not pruned_configs:
315315
raise AutotunerError(
316316
"No valid autotuner configs after pruning. `early_config_prune` should return at least one config.")

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#include <cuda_fp16.h>
21
#include <stddef.h>
32
#include <stdint.h>
43

54
extern "C" __device__ uint64_t nvshmem_signal_wait_until(uint64_t *sig_addr,
65
int cmp,
76
uint64_t cmp_value);
7+
extern "C" __device__ void
8+
nvshmemx_putmem_signal_block(void *dest, const void *source, size_t bytes,
9+
uint64_t *sig_addr, uint64_t signal, int sig_op,
10+
int pe);
811

912
enum {
1013
NVSHMEM_CMP_GE = 5,
@@ -16,7 +19,7 @@ ag_mark_local_ready(__attribute__((address_space(1))) uint64_t *ready,
1619
int rank) {
1720
if (threadIdx.x == 0) {
1821
__threadfence_system();
19-
ready[(size_t)rank] = 1;
22+
ready[rank] = 1;
2023
}
2124
__syncthreads();
2225
}
@@ -29,3 +32,13 @@ ag_wait_ready(__attribute__((address_space(1))) uint64_t *ready,
2932
}
3033
__syncthreads();
3134
}
35+
36+
extern "C" __device__ __attribute__((always_inline)) void
37+
ag_putmem_signal_block(__attribute__((address_space(1))) void *dest,
38+
__attribute__((address_space(1))) const void *source,
39+
size_t bytes,
40+
__attribute__((address_space(1))) uint64_t *sig_addr,
41+
uint64_t signal, int peer) {
42+
nvshmemx_putmem_signal_block(dest, source, bytes, sig_addr, signal,
43+
NVSHMEM_SIGNAL_SET, peer);
44+
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#include <cuda_fp16.h>
21
#include <cuda_runtime.h>
32
#include <nvshmem.h>
43
#include <nvshmemx.h>
54
#include <stdint.h>
65
#include <stdio.h>
7-
#include <stdlib.h>
86

97
#define CUDA_CHECK(stmt) \
108
do { \
@@ -16,10 +14,12 @@
1614
} \
1715
} while (0)
1816

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) {
17+
extern "C" int ag_gemm_workspace_create(int elements_per_rank, int element_size,
18+
void **workspace, uint64_t **ready,
19+
int *mype, int *npes, int *mype_in_node,
20+
int *npes_in_node) {
21+
if (elements_per_rank <= 0 || element_size <= 0 || workspace == nullptr ||
22+
ready == nullptr) {
2323
return -1;
2424
}
2525

@@ -29,7 +29,7 @@ extern "C" int ag_gemm_workspace_create(int elements_per_rank, void **workspace,
2929
*npes_in_node = nvshmem_team_n_pes(NVSHMEMX_TEAM_NODE);
3030
CUDA_CHECK(cudaSetDevice(*mype_in_node));
3131

32-
size_t workspace_bytes = (size_t)(*npes) * elements_per_rank * sizeof(__half);
32+
size_t workspace_bytes = (size_t)(*npes) * elements_per_rank * element_size;
3333
*workspace = nvshmem_malloc(workspace_bytes);
3434
*ready = (uint64_t *)nvshmem_calloc((size_t)(*npes), sizeof(uint64_t));
3535
if (*workspace == nullptr || *ready == nullptr) {
@@ -61,3 +61,13 @@ extern "C" void *ag_gemm_peer_workspace_ptr(void *workspace, int peer) {
6161
extern "C" uint64_t *ag_gemm_peer_ready_ptr(uint64_t *ready, int peer) {
6262
return (uint64_t *)nvshmem_ptr(ready, peer);
6363
}
64+
65+
extern "C" void ag_gemm_barrier_all_on_stream(cudaStream_t stream) {
66+
nvshmemx_barrier_all_on_stream(stream);
67+
}
68+
69+
extern "C" void ag_gemm_signal_wait_until_on_stream(uint64_t *signal,
70+
uint64_t value,
71+
cudaStream_t stream) {
72+
nvshmemx_signal_wait_until_on_stream(signal, NVSHMEM_CMP_GE, value, stream);
73+
}

0 commit comments

Comments
 (0)