Skip to content

Commit 2c37270

Browse files
committed
merge prefetch.uniform into prefetch
1 parent 532e0d9 commit 2c37270

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,18 +2378,22 @@ def NVVM_PrefetchOp : NVVM_Op<"prefetch"> {
23782378

23792379
The `cacheLevel` attribute specifies the cache level to which the cache line
23802380
containing the specified address is brought.
2381+
2382+
`uniform` can be specified after the `cacheLevel` to indicate that the
2383+
prefetch is performed to the specified uniform cache level. If `uniform` is specified, `addr` must be a generic address pointer and no operation is performed if `addr` maps to a `const`, `local`, or `shared` memory location.
23812384

23822385
The `evictPriority` attribute is optional and specifies the cache eviction
23832386
priority when `cacheLevel` is L2.
23842387

23852388
[For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/#data-movement-and-conversion-instructions-prefetch-prefetchu)
23862389
}];
23872390
let arguments = (ins PrefetchCacheLevelAttr:$cacheLevel,
2391+
UnitAttr:$uniform,
23882392
AnyTypeOf<[LLVM_PointerGlobal,
23892393
LLVM_PointerLocal,
23902394
LLVM_PointerGeneric]>:$addr,
23912395
OptionalAttr<CacheEvictionPriorityAttr>:$evictPriority);
2392-
let assemblyFormat = "`level` `=` $cacheLevel `,` $addr (`,` `evict_priority` `=` $evictPriority^)? attr-dict `:` type($addr)";
2396+
let assemblyFormat = "`level` `=` $cacheLevel (`uniform` $uniform^)? `,` $addr (`,` `evict_priority` `=` $evictPriority^)? attr-dict `:` type($addr)";
23932397
let hasVerifier = 1;
23942398

23952399
let extraClassDeclaration = [{
@@ -2401,27 +2405,6 @@ def NVVM_PrefetchOp : NVVM_Op<"prefetch"> {
24012405
}];
24022406
}
24032407

2404-
def NVVM_PrefetchUniformOp : NVVM_Op<"prefetch.uniform"> {
2405-
let summary = "Brings the cache line containing an address into the specified uniform cache level";
2406-
let description = [{
2407-
Operand `addr` must be a generic address pointer and no operation is
2408-
performed if `addr` maps to a `const`, `local`, or `shared` memory location.
2409-
2410-
The `cacheLevel` attribute specifies the cache level to which the cache line
2411-
containing the specified address is brought. The only supported level is L1.
2412-
2413-
[For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/#data-movement-and-conversion-instructions-prefetch-prefetchu)
2414-
}];
2415-
let arguments = (ins PrefetchCacheLevelAttr:$cacheLevel,
2416-
LLVM_PointerGeneric:$addr);
2417-
let assemblyFormat = "`level` `=` $cacheLevel `,` $addr attr-dict `:` type($addr)";
2418-
let hasVerifier = 1;
2419-
2420-
let llvmBuilder = [{
2421-
createIntrinsicCall(builder, llvm::Intrinsic::nvvm_prefetchu_L1, $addr);
2422-
}];
2423-
}
2424-
24252408
def NVVM_PrefetchTensorMapOp : NVVM_Op<"prefetch.tensormap",
24262409
[DeclareOpInterfaceMethods<BasicPtxBuilderOpInterface>]>,
24272410
Arguments<(ins LLVM_AnyPointer:$tmaDescriptor, PtxPredicate:$predicate)> {

mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,15 +1206,27 @@ LogicalResult NVVM::VoteSyncOp::verify() {
12061206
}
12071207

12081208
LogicalResult NVVM::PrefetchOp::verify() {
1209+
unsigned addressSpace =
1210+
llvm::cast<LLVM::LLVMPointerType>(getAddr().getType()).getAddressSpace();
12091211
auto evictPriority = getEvictPriority();
12101212

1213+
if (getUniform()) {
1214+
if (!(getCacheLevel() == NVVM::PrefetchCacheLevel::L1)) {
1215+
return emitOpError("unsupported cache level, the only supported uniform "
1216+
"cache level is L1");
1217+
}
1218+
if (addressSpace != NVVM::NVVMMemorySpace::kGenericMemorySpace) {
1219+
return emitOpError(
1220+
"prefetch to uniform cache requires a generic pointer");
1221+
}
1222+
}
1223+
12111224
if (evictPriority && getCacheLevel() != NVVM::PrefetchCacheLevel::L2)
12121225
return emitOpError(
12131226
"cache eviction priority supported only for cache level L2");
12141227

12151228
if (evictPriority &&
1216-
(llvm::cast<LLVM::LLVMPointerType>(getAddr().getType())
1217-
.getAddressSpace() != NVVM::NVVMMemorySpace::kGlobalMemorySpace))
1229+
(addressSpace != NVVM::NVVMMemorySpace::kGlobalMemorySpace))
12181230
return emitOpError("cache eviction priority requires a global pointer");
12191231

12201232
if (evictPriority &&
@@ -1227,13 +1239,6 @@ LogicalResult NVVM::PrefetchOp::verify() {
12271239
return success();
12281240
}
12291241

1230-
LogicalResult NVVM::PrefetchUniformOp::verify() {
1231-
if (getCacheLevel() != NVVM::PrefetchCacheLevel::L1)
1232-
return emitOpError(
1233-
"unsupported cache level, the only supported level is L1");
1234-
return success();
1235-
}
1236-
12371242
/// Packs the given `field` into the `result`.
12381243
/// The `result` is 64-bits and each `field` can be 32-bits or narrower.
12391244
static llvm::Value *
@@ -1771,6 +1776,13 @@ llvm::Intrinsic::ID PrefetchOp::getIntrinsicID(Operation &op) {
17711776
unsigned as = llvm::cast<LLVM::LLVMPointerType>(curOp.getAddr().getType())
17721777
.getAddressSpace();
17731778

1779+
if (curOp.getUniform()) {
1780+
if (cacheLevel == NVVM::PrefetchCacheLevel::L1)
1781+
return llvm::Intrinsic::nvvm_prefetchu_L1;
1782+
else
1783+
llvm_unreachable("Invalid uniform cache level");
1784+
}
1785+
17741786
if (cacheLevel == NVVM::PrefetchCacheLevel::L1) {
17751787
switch (as) {
17761788
case NVVM::NVVMMemorySpace::kGenericMemorySpace:

mlir/test/Dialect/LLVMIR/nvvm.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ func.func @prefetch(%gen_ptr: !llvm.ptr, %local_ptr: !llvm.ptr<5>, %global_ptr:
614614
nvvm.prefetch level = L2, %global_ptr, evict_priority = evict_last : !llvm.ptr<1>
615615
// CHECK: nvvm.prefetch level = L2, %{{.*}}
616616
nvvm.prefetch level = L2, %global_ptr, evict_priority = evict_normal : !llvm.ptr<1>
617-
// CHECK: nvvm.prefetch.uniform level = L1, %{{.*}}
618-
nvvm.prefetch.uniform level = L1, %gen_ptr : !llvm.ptr
617+
// CHECK: nvvm.prefetch level = L1 uniform, %{{.*}}
618+
nvvm.prefetch level = L1 uniform, %gen_ptr : !llvm.ptr
619619
return
620620
}
621621

mlir/test/Target/LLVMIR/nvvm/prefetch.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ llvm.func @prefetch_L1_uniform(%gen_ptr: !llvm.ptr) {
4242
// CHECK-NEXT: call void @llvm.nvvm.prefetchu.L1(ptr %0)
4343
// CHECK-NEXT: ret void
4444
// CHECK-NEXT: }
45-
nvvm.prefetch.uniform level = L1, %gen_ptr : !llvm.ptr
45+
nvvm.prefetch level = L1 uniform, %gen_ptr : !llvm.ptr
4646
llvm.return
4747
}

mlir/test/Target/LLVMIR/nvvmir-invalid.mlir

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,15 @@ llvm.func @nvvm_prefetch_L2_with_invalid_no_allocate(%global_ptr: !llvm.ptr<1>)
300300
// -----
301301

302302
llvm.func @nvvm_prefetch_uniform_with_L2(%gen_ptr: !llvm.ptr) {
303-
// expected-error @below {{unsupported cache level, the only supported level is L1}}
304-
nvvm.prefetch.uniform level = L2, %gen_ptr : !llvm.ptr
303+
// expected-error @below {{unsupported cache level, the only supported uniform cache level is L1}}
304+
nvvm.prefetch level = L2 uniform, %gen_ptr : !llvm.ptr
305+
llvm.return
306+
}
307+
308+
// -----
309+
310+
llvm.func @nvvm_prefetch_uniform_with_invalid_addr_space(%global_ptr: !llvm.ptr<1>) {
311+
// expected-error @below {{prefetch to uniform cache requires a generic pointer}}
312+
nvvm.prefetch level = L1 uniform, %global_ptr : !llvm.ptr<1>
305313
llvm.return
306314
}

0 commit comments

Comments
 (0)