triton.language.atomic_or
1. OP 概述
简介:原子性逻辑或操作,在指定的内存位置执行逻辑或(|)操作 原型:
triton.language.atomic_or(
pointer,
val,
mask=None,
sem=None,
scope=None,
_semantic=None
) -> pointer
可以作为tensor的成员函数调用,如x.atomic_or(...),与atomic_or(x, ...)等效。
2. OP 规格
2.1 参数说明
参数名 |
类型 |
说明 |
|---|---|---|
|
|
要操作的内存位置,执行 *pointer | val 计算后的结果写回到该内存 |
|
|
执行原子操作的值(右操作数) |
|
|
指定数据范围,防止访问越界 |
|
|
指定操作的内存语义 |
|
|
观察原子操作同步效果的线程范围 |
|
- |
保留参数,暂不支持外部调用 |
返回值:
pointer:tensor,执行操作之前的旧值
2.2 支持规格
2.2.1 DataType 支持
int8 |
int16 |
int32 |
uint8 |
uint16 |
uint32 |
uint64 |
int64 |
fp16 |
fp32 |
fp64 |
bf16 |
bool |
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GPU |
× |
× |
√ |
× |
× |
× |
× |
√ |
× |
× |
× |
× |
× |
Ascend A2/A3 |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
× |
× |
× |
× |
× |
2.2.2 Shape 支持
无特殊要求
2.3 特殊限制说明
相对社区能力缺失且无法实现
差异点 |
描述 |
|---|---|
sem |
社区官方配置可接受的值为“acquire”、“release”、“acq_rel”(默认,代表“ACQUIRE_RELEASE”)和“relaxed” |
scope |
可接受的值为“gpu”、“cta”、或“sys”、 |
2.4 使用方法
以下示例实现了原子或计算:
@triton.jit
def atomic_or(in_ptr0, out_ptr0, out_ptr1, n_elements, BLOCK_SIZE: tl.constexpr):
xoffset = tl.program_id(0) * BLOCK_SIZE
xindex = xoffset + tl.arange(0, BLOCK_SIZE)[:]
yindex = tl.arange(0, BLOCK_SIZE)[:]
xmask = xindex < n_elements
x0 = xindex
x1 = yindex
tmp0 = tl.load(in_ptr0 + (x0), xmask)
tmp1 = tl.atomic_or(out_ptr0 + (x1), tmp0, xmask)
tl.store(out_ptr1 + (x1), tmp1, xmask)