Skip to content

Commit 32a6408

Browse files
committed
add an option in insertGpuAllocs to skip the func args copy
1 parent 1fd2e00 commit 32a6408

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

include/imex/Transforms/Passes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
#include <memory>
2020

2121
namespace imex {
22+
struct InsertGPUAllocsOptions;
2223
//===----------------------------------------------------------------------===//
2324
// Passes
2425
//===----------------------------------------------------------------------===//
2526
std::unique_ptr<mlir::Pass> createSerializeSPIRVPass();
2627
std::unique_ptr<mlir::Pass>
2728
createInsertGPUAllocsPass(const char *clientAPI = "vulkan");
29+
std::unique_ptr<mlir::Pass>
30+
createInsertGPUAllocsPass(const InsertGPUAllocsOptions &);
2831
std::unique_ptr<mlir::Pass> createSetSPIRVCapabilitiesPass();
2932
std::unique_ptr<mlir::Pass>
3033
createSetSPIRVAbiAttributePass(const char *clientAPI = "vulkan");

include/imex/Transforms/Passes.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def InsertGPUAllocs : Pass<"insert-gpu-allocs", "::mlir::func::FuncOp"> {
4141
Option<"clientAPI", "client-api", "std::string", /*default=*/"\"opencl\"",
4242
"The client API to use for inserting gpu allocs">,
4343
Option<"inRegions", "in-regions", "bool", "false",
44-
"Add gpu allocs only for memref.AllocOps within GPU regions">
44+
"Add gpu allocs only for memref.AllocOps within GPU regions">,
45+
Option<"isUsmArgs", "is-usm-args", "bool", "false",
46+
"Whether to use USM(unified shared memory) func args, in which the "
47+
"host and device could access the same buffer and there is no need "
48+
"to add memcpy explicitly">
4549
];
4650
}
4751

lib/Transforms/InsertGPUAllocs.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class InsertGPUAllocsPass final
4747
explicit InsertGPUAllocsPass() : m_clientAPI("vulkan") {}
4848
explicit InsertGPUAllocsPass(const mlir::StringRef &clientAPI)
4949
: m_clientAPI(clientAPI) {}
50+
explicit InsertGPUAllocsPass(const imex::InsertGPUAllocsOptions &options)
51+
: InsertGPUAllocsBase<InsertGPUAllocsPass>(options) {
52+
if (clientAPI == "opencl") {
53+
m_clientAPI = "opencl";
54+
}
55+
}
5056

5157
mlir::LogicalResult
5258
initializeOptions(mlir::StringRef options,
@@ -540,15 +546,17 @@ class InsertGPUAllocsPass final
540546
// This is the case where the inputs are passed as arguments to the
541547
// function. This code will add the IR for memory allocation on the device
542548
// with gpu.alloc and insert a memref.copy from host to device
543-
for (const auto &it : gpuBufferParams) {
544-
auto param = block.getArgument(it.first);
545-
if (isGpuAddrSpace(param))
546-
continue;
547-
auto access = getAccessType(param);
548-
access.hostRead = true;
549-
access.hostWrite = true;
550-
builder.setInsertionPointToStart(&block);
551-
add_gpu_alloc(builder, param, access, term);
549+
if (!isUsmArgs.getValue()) {
550+
for (const auto &it : gpuBufferParams) {
551+
auto param = block.getArgument(it.first);
552+
if (isGpuAddrSpace(param))
553+
continue;
554+
auto access = getAccessType(param);
555+
access.hostRead = true;
556+
access.hostWrite = true;
557+
builder.setInsertionPointToStart(&block);
558+
add_gpu_alloc(builder, param, access, term);
559+
}
552560
}
553561

554562
// CallOp Case: This is the case where the memref producer is coming
@@ -580,4 +588,8 @@ namespace imex {
580588
std::unique_ptr<mlir::Pass> createInsertGPUAllocsPass(const char *clientAPI) {
581589
return std::make_unique<InsertGPUAllocsPass>(clientAPI);
582590
}
591+
std::unique_ptr<mlir::Pass>
592+
createInsertGPUAllocsPass(const InsertGPUAllocsOptions &option) {
593+
return std::make_unique<InsertGPUAllocsPass>(option);
594+
}
583595
} // namespace imex

0 commit comments

Comments
 (0)