Skip to content
Merged
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
12 changes: 12 additions & 0 deletions test/Pipeline/warpforthc-options.forth
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\ RUN: %warpforthc -O3 --features=+ptx70 --mlir-print-ir-after-all --mlir-disable-threading %s -o %t.ptx 2>&1 | %FileCheck %s
\ RUN: %warpforthc --opt-level=0 --arch sm_80 --mlir-print-ir-after-all --mlir-disable-threading %s -o %t.ptx 2>&1 | %FileCheck %s --check-prefix=O0
\ RUN: %warpforthc --features=+ptx70 %s -o - | %FileCheck %s --check-prefix=PTX
\ RUN: %not %warpforthc -O4 %s -o %t.ptx 2>&1 | %FileCheck %s --check-prefix=BAD-OPT

\! kernel main
42

\ CHECK: #nvvm.target<O = 3, chip = "sm_70", features = "+ptx70"
\ O0: #nvvm.target<O = 0, chip = "sm_80"
\ PTX: .version 7.0
\ BAD-OPT: Cannot find option named '4'!
27 changes: 27 additions & 0 deletions tools/warpforthc/warpforthc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"

using namespace mlir;

Expand All @@ -42,6 +43,22 @@ static llvm::cl::opt<std::string, false, warpforth::NVVMChipParser>
targetArchitecture("arch", llvm::cl::desc("GPU architecture"),
llvm::cl::value_desc("sm_XX"), llvm::cl::init("sm_70"));

static llvm::cl::opt<std::string>
optLevel("O", llvm::cl::desc("Optimization level (0, 1, 2, or 3)"),
llvm::cl::value_desc("level"), llvm::cl::Prefix,
llvm::cl::init(""));
static llvm::cl::alias optLevelAlias("opt-level",
llvm::cl::desc("Alias for -O"),
llvm::cl::aliasopt(optLevel));

static llvm::cl::opt<std::string>
targetFeatures("features", llvm::cl::desc("NVVM target features"),
llvm::cl::value_desc("+ptxNN"), llvm::cl::init(""));

static llvm::cl::opt<std::string>
libdevicePath("libdevice", llvm::cl::desc("Path to the libdevice bitcode"),
llvm::cl::value_desc("path"), llvm::cl::init(""));

int main(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);
warpforth::registerConversionPasses();
Expand Down Expand Up @@ -85,6 +102,16 @@ int main(int argc, char **argv) {
if (failed(applyPassManagerCLOptions(pm)))
return 1;
warpforth::WarpForthPipelineOptions pipelineOptions;
std::string overrides;
llvm::raw_string_ostream overridesOS(overrides);
if (!optLevel.empty())
overridesOS << " opt-level=" << optLevel;
if (!targetFeatures.empty())
overridesOS << " features=" << targetFeatures;
if (!libdevicePath.empty())
overridesOS << " libdevice=" << libdevicePath;
if (failed(pipelineOptions.parseFromString(overrides)))
return 1;
pipelineOptions.chip = targetArchitecture.getValue();
warpforth::buildWarpForthPipeline(pm, pipelineOptions);
if (failed(pm.run(*module)))
Expand Down
Loading