Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ their results are needed:
- the end of the program.

On the RTX 5080 a launch that does not wait costs about 7.5 µs, against 14 µs for one that does, whatever the
kernel's size: for small kernels, launches are what the time goes on.
kernel's size: for small kernels, launches are what the time goes on. On Intel's integrated GPU of a Core Ultra 9
285K, 2000 small launches take 13 ms that way, against 63 ms waiting after each.

A kernel that fails (an array index past the end, say) is reported where the program next waits, not at its own
launch, and at the end of the program if nothing waits before it:
Expand All @@ -548,8 +549,7 @@ tslang gpu (cuda): running a kernel failed (719 unspecified launch failure)
```

`TSLANG_GPU_SYNC=1` waits after every launch, so the error comes from the launch that caused it, and so does
`TSLANG_GPU_PROFILE=1`, which times each kernel. On Intel's GPUs every launch waits for now (Level Zero's
synchronous command list).
`TSLANG_GPU_PROFILE=1`, which times each kernel.

## Numbers on the GPU

Expand Down
18 changes: 15 additions & 3 deletions tslang/lib/TypeScriptAsyncRuntime/GpuRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static GpuDriver *hipInitDriver(void)
#define ZE_STRUCTURE_TYPE_KERNEL_DESC 0x1d
#define ZE_INIT_FLAG_GPU_ONLY 1
#define ZE_DEVICE_TYPE_GPU 1
#define ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS 1
#define ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS 2
#define ZE_MODULE_FORMAT_IL_SPIRV 0
#define ZE_KERNEL_INDIRECT_ACCESS_FLAG_DEVICE 2

Expand Down Expand Up @@ -433,6 +433,7 @@ static struct
GpuResult (*zeKernelSetArgumentValue)(void *, uint32_t, size_t, const void *);
GpuResult (*zeKernelSetIndirectAccess)(void *, uint32_t);
GpuResult (*zeCommandListAppendLaunchKernel)(void *, void *, const ze_group_count_t *, void *, uint32_t, void **);
GpuResult (*zeCommandListAppendBarrier)(void *, void *, uint32_t, void **);
GpuResult (*zeDriverGetLastErrorDescription)(void *, const char **); // since 1.6; may be missing
GpuResult (*zeModuleGetGlobalPointer)(void *, const char *, size_t *, void **);
void *driver;
Expand Down Expand Up @@ -494,7 +495,13 @@ static GpuResult levelZeroAlloc(GpuPtr *ptr, size_t bytes)
*ptr = (GpuPtr)(uintptr_t)p;
return r;
}
static GpuResult levelZeroFree(GpuPtr ptr) { return ze.zeMemFree(ze.context, (void *)(uintptr_t)ptr); }
// zeMemFree does not wait for a kernel still on the memory (cuMemFree and hipFree do): a GpuArray collected
// after a launch that was not waited for is freed only after it
static GpuResult levelZeroFree(GpuPtr ptr)
{
GpuResult r = ze.zeCommandListHostSynchronize(ze.list, UINT64_MAX);
return r != 0 ? r : ze.zeMemFree(ze.context, (void *)(uintptr_t)ptr);
}
static GpuResult levelZeroCopy(void *dst, const void *src, size_t bytes)
{
GpuResult r = ze.zeCommandListAppendMemoryCopy(ze.list, dst, src, bytes, NULL, 0, NULL);
Expand All @@ -521,6 +528,10 @@ static GpuResult levelZeroLaunch(void *fn, const unsigned *grid, const unsigned
ze_group_count_t groups = {grid[0], grid[1], grid[2]};
if (r == 0)
r = ze.zeCommandListAppendLaunchKernel(ze.list, fn, &groups, NULL, 0, NULL);
// the list runs its commands in any order unless told: what comes after the kernel (another kernel on its
// arrays, a copy back) waits for it, as on a CUDA or HIP stream
if (r == 0)
r = ze.zeCommandListAppendBarrier(ze.list, NULL, 0, NULL);
return r;
}
static GpuResult levelZeroSynchronize(void) { return ze.zeCommandListHostSynchronize(ze.list, UINT64_MAX); }
Expand Down Expand Up @@ -569,6 +580,7 @@ static GpuDriver *levelZeroInit(void)
GPU_SYM(driver, lib, ze.zeKernelSetArgumentValue, "zeKernelSetArgumentValue");
GPU_SYM(driver, lib, ze.zeKernelSetIndirectAccess, "zeKernelSetIndirectAccess");
GPU_SYM(driver, lib, ze.zeCommandListAppendLaunchKernel, "zeCommandListAppendLaunchKernel");
GPU_SYM(driver, lib, ze.zeCommandListAppendBarrier, "zeCommandListAppendBarrier");
*(void **)&ze.zeDriverGetLastErrorDescription = gpuSym(lib, "zeDriverGetLastErrorDescription");
if ((*(void **)&ze.zeModuleGetGlobalPointer = gpuSym(lib, "zeModuleGetGlobalPointer")))
driver->getGlobal = levelZeroGetGlobal;
Expand Down Expand Up @@ -616,7 +628,7 @@ static GpuDriver *levelZeroInit(void)
if (r != 0)
return gpuUnusable(driver, "zeContextCreate failed", r);
ze_command_queue_desc_t queueDesc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, NULL, 0, 0, 0,
ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS, 0};
ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS, 0};
if ((r = ze.zeCommandListCreateImmediate(ze.context, ze.device, &queueDesc, &ze.list)) != 0)
return gpuUnusable(driver, "zeCommandListCreateImmediate failed", r);
driver->ready = 1;
Expand Down
Loading