28#include "llvm/Support/InterleavedRange.h"
30#include "llvm/ADT/ScopeExit.h"
31#include "llvm/Config/Targets.h"
32#include "llvm/Support/DebugLog.h"
33#include "llvm/Support/FileSystem.h"
34#include "llvm/Support/FileUtilities.h"
35#include "llvm/Support/FormatVariadic.h"
36#include "llvm/Support/MemoryBuffer.h"
37#include "llvm/Support/Path.h"
38#include "llvm/Support/Process.h"
39#include "llvm/Support/Program.h"
40#include "llvm/Support/TargetSelect.h"
41#include "llvm/Support/Timer.h"
42#include "llvm/Support/raw_ostream.h"
51#ifndef __DEFAULT_CUDATOOLKIT_PATH__
52#define __DEFAULT_CUDATOOLKIT_PATH__ ""
60class NVVMTargetAttrImpl
61 :
public gpu::TargetAttrInterface::FallbackModel<NVVMTargetAttrImpl> {
63 std::optional<mlir::gpu::SerializedObject>
77 NVVMTargetAttr::attachInterface<NVVMTargetAttrImpl>(*ctx);
90 if (
const char *var = std::getenv(
"CUDA_ROOT"))
92 if (
const char *var = std::getenv(
"CUDA_HOME"))
94 if (
const char *var = std::getenv(
"CUDA_PATH"))
104 target.getO(), targetOptions.getInitialLlvmIRCallback(),
105 targetOptions.getLinkedLlvmIRCallback(),
106 targetOptions.getOptimizedLlvmIRCallback(),
107 targetOptions.getISACallback(), targetOptions.getLibraryOptions()),
124 static llvm::once_flag initializeBackendOnce;
125 llvm::call_once(initializeBackendOnce, []() {
127#if LLVM_HAS_NVPTX_TARGET
128 LLVMInitializeNVPTXTarget();
129 LLVMInitializeNVPTXTargetInfo();
130 LLVMInitializeNVPTXTargetMC();
131 LLVMInitializeNVPTXAsmPrinter();
146#if MLIR_NVVM_EMBED_LIBDEVICE
152 IntegerType::get(ctx, 8));
157 resourceManager.getBlobManager().lookup(
"_mlir_embedded_libdevice");
171 type, resourceManager.insert(
"_mlir_embedded_libdevice",
172 std::move(unmanagedBlob))));
175 if (!pathRef.empty()) {
177 path.insert(path.begin(), pathRef.begin(), pathRef.end());
178 pathRef = StringRef(path.data(), path.size());
179 if (!llvm::sys::fs::is_directory(pathRef)) {
181 <<
" does not exist or is not a directory.\n";
184 llvm::sys::path::append(path,
"nvvm",
"libdevice",
"libdevice.10.bc");
185 pathRef = StringRef(path.data(), path.size());
186 if (!llvm::sys::fs::is_regular_file(pathRef)) {
188 <<
" does not exist or is not a file.\n";
197std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
203 return std::move(bcFiles);
213 gpu::GPUModuleOp getOperation();
216 FailureOr<SmallVector<char, 0>> compileToBinary(StringRef ptxCode);
219 FailureOr<SmallVector<char, 0>> compileToBinaryNVPTX(StringRef ptxCode);
223 FailureOr<SmallVector<char, 0>>
224 moduleToObject(llvm::Module &llvmModule)
override;
229 std::optional<int64_t> getLLVMIRToISATimeInMs();
234 std::optional<int64_t> getISAToBinaryTimeInMs();
237 StringRef getISACompilerLog()
const;
240 using TmpFile = std::pair<llvm::SmallString<128>, llvm::FileRemover>;
243 std::optional<TmpFile> createTemp(StringRef name, StringRef suffix);
250 std::optional<std::string> findTool(StringRef tool);
256 std::optional<int64_t> llvmToISATimeInMs;
259 std::optional<int64_t> isaToBinaryTimeInMs;
262 std::string isaCompilerLog;
266NVPTXSerializer::NVPTXSerializer(
Operation &module, NVVMTargetAttr
target,
269 targetOptions(targetOptions), llvmToISATimeInMs(std::nullopt),
270 isaToBinaryTimeInMs(std::nullopt) {}
272std::optional<NVPTXSerializer::TmpFile>
273NVPTXSerializer::createTemp(StringRef name, StringRef suffix) {
274 llvm::SmallString<128> filename;
275 if (name.size() > 80)
276 name = name.substr(0, 80);
278 llvm::sys::fs::createTemporaryFile(name, suffix, filename);
280 getOperation().emitError() <<
"Couldn't create the temp file: `" << filename
281 <<
"`, error message: " << ec.message();
284 return TmpFile(filename, llvm::FileRemover(filename.c_str()));
287std::optional<int64_t> NVPTXSerializer::getLLVMIRToISATimeInMs() {
288 return llvmToISATimeInMs;
291std::optional<int64_t> NVPTXSerializer::getISAToBinaryTimeInMs() {
292 return isaToBinaryTimeInMs;
295StringRef NVPTXSerializer::getISACompilerLog()
const {
return isaCompilerLog; }
297gpu::GPUModuleOp NVPTXSerializer::getOperation() {
301std::optional<std::string> NVPTXSerializer::findTool(StringRef tool) {
304 StringRef pathRef = targetOptions.getToolkitPath();
305 SmallVector<char, 256> path;
306 if (!pathRef.empty()) {
307 path.insert(path.begin(), pathRef.begin(), pathRef.end());
308 llvm::sys::path::append(path,
"bin", tool);
309 if (llvm::sys::fs::can_execute(path))
310 return StringRef(path.data(), path.size()).str();
314 if (std::optional<std::string> toolPath =
315 llvm::sys::Process::FindInEnvPath(
"PATH", tool))
321 if (!pathRef.empty()) {
322 path.insert(path.begin(), pathRef.begin(), pathRef.end());
323 llvm::sys::path::append(path,
"bin", tool);
324 if (llvm::sys::fs::can_execute(path))
325 return StringRef(path.data(), path.size()).str();
327 getOperation().emitError()
328 <<
"Couldn't find the `" << tool
329 <<
"` binary. Please specify the toolkit "
330 "path, add the compiler to $PATH, or set one of the environment "
331 "variables in `NVVM::getCUDAToolkitPath()`.";
339 if (!
target.hasCmdOptions())
342 std::optional<mlir::NamedAttribute> cmdOptions =
target.getCmdOptions();
343 for (
Attribute attr : cast<ArrayAttr>(cmdOptions->getValue())) {
344 if (
auto strAttr = dyn_cast<StringAttr>(attr)) {
345 if constexpr (std::is_same_v<T, StringRef>) {
346 ptxasArgs.push_back(strAttr.getValue());
347 }
else if constexpr (std::is_same_v<T, const char *>) {
348 ptxasArgs.push_back(strAttr.getValue().data());
356FailureOr<SmallVector<char, 0>>
357NVPTXSerializer::compileToBinary(StringRef ptxCode) {
360 const bool createFatbin =
361 targetOptions.getCompilationTarget() == gpu::CompilationTarget::Fatbin;
364 std::optional<std::string> ptxasCompiler = findTool(
"ptxas");
367 std::optional<std::string> fatbinaryTool;
369 fatbinaryTool = findTool(
"fatbinary");
373 Location loc = getOperation().getLoc();
376 std::string basename =
377 llvm::formatv(
"mlir-{0}-{1}-{2}", getOperation().getNameAttr().getValue(),
378 getTarget().getTriple(), getTarget().getChip());
381 std::optional<TmpFile> ptxFile = createTemp(basename,
"ptx");
384 std::optional<TmpFile> logFile = createTemp(basename,
"log");
387 std::optional<TmpFile> binaryFile = createTemp(basename,
"bin");
392 std::string cubinFilename = (ptxFile->first +
".cubin").str();
393 cubinFile = TmpFile(cubinFilename, llvm::FileRemover(cubinFilename));
395 cubinFile.first = binaryFile->first;
401 llvm::raw_fd_ostream ptxStream(ptxFile->first, ec);
403 return emitError(loc) <<
"Couldn't open the file: `" << ptxFile->first
404 <<
"`, error message: " << ec.message();
406 ptxStream << ptxCode;
407 if (ptxStream.has_error())
408 return emitError(loc) <<
"An error occurred while writing the PTX to: `"
409 << ptxFile->first <<
"`.";
415 std::optional<StringRef> redirects[] = {
422 std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>> cmdOpts =
423 targetOptions.tokenizeCmdOptions();
426 std::string optLevel = std::to_string(this->optLevel);
427 SmallVector<StringRef, 12> ptxasArgs(
428 {StringRef(
"ptxas"), StringRef(
"-arch"), getTarget().getChip(),
429 StringRef(ptxFile->first), StringRef(
"-o"), StringRef(cubinFile.first),
430 "--opt-level", optLevel});
432 bool useFatbin32 =
false;
433 for (
const auto *cArg : cmdOpts.second) {
437 if (StringRef arg(cArg); arg !=
"-32")
438 ptxasArgs.push_back(arg);
447 StringRef chip = getTarget().getChip();
449 chip.consume_front(
"sm_"), chip.consume_front(
"compute_");
451 std::string cubinArg =
452 llvm::formatv(
"--image3=kind=elf,sm={0},file={1}", chip, cubinFile.first)
456 llvm::formatv(
"--image3=kind=ptx,sm={0},file={1}", chip, ptxFile->first)
458 SmallVector<StringRef, 6> fatbinArgs({StringRef(
"fatbinary"),
459 useFatbin32 ?
"-32" :
"-64", cubinArg,
460 ptxArg,
"--create", binaryFile->first});
463#define DEBUG_TYPE "serialize-to-binary"
464 LDBG() <<
"Tool invocation for module: " << getOperation().getNameAttr()
465 <<
"\nptxas executable:" << ptxasCompiler.value()
466 <<
"\nptxas args: " << llvm::interleaved(ptxasArgs,
" ");
468 LDBG() <<
"fatbin args: " << llvm::interleaved(fatbinArgs,
" ");
474 [&](StringRef toolName) -> FailureOr<SmallVector<char, 0>> {
475 if (message.empty()) {
476 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> toolStderr =
477 llvm::MemoryBuffer::getFile(logFile->first);
479 return emitError(loc) << toolName <<
" invocation failed. Log:\n"
480 << toolStderr->get()->getBuffer();
482 return emitError(loc) << toolName <<
" invocation failed.";
485 <<
" invocation failed, error message: " << message;
489 if (llvm::sys::ExecuteAndWait(ptxasCompiler.value(), ptxasArgs,
495 return emitLogError(
"`ptxas`");
497 if (
target.hasFlag(
"collect-compiler-diagnostics")) {
498 if (
auto logBuffer = llvm::MemoryBuffer::getFile(logFile->first))
499 isaCompilerLog = (*logBuffer)->getBuffer().str();
501#define DEBUG_TYPE "dump-sass"
503 std::optional<std::string> nvdisasm = findTool(
"nvdisasm");
504 SmallVector<StringRef> nvdisasmArgs(
505 {StringRef(
"nvdisasm"), StringRef(cubinFile.first)});
506 if (llvm::sys::ExecuteAndWait(nvdisasm.value(), nvdisasmArgs,
512 return emitLogError(
"`nvdisasm`");
513 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> logBuffer =
514 llvm::MemoryBuffer::getFile(logFile->first);
515 if (logBuffer && !(*logBuffer)->getBuffer().empty()) {
516 LDBG() <<
"Output:\n" << (*logBuffer)->getBuffer();
517 llvm::dbgs().flush();
524 if (createFatbin && llvm::sys::ExecuteAndWait(*fatbinaryTool, fatbinArgs,
530 return emitLogError(
"`fatbinary`");
533#define DEBUG_TYPE "serialize-to-binary"
535 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> logBuffer =
536 llvm::MemoryBuffer::getFile(logFile->first);
537 if (logBuffer && !(*logBuffer)->getBuffer().empty()) {
538 LDBG() <<
"Output:\n" << (*logBuffer)->getBuffer();
539 llvm::dbgs().flush();
545 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> binaryBuffer =
546 llvm::MemoryBuffer::getFile(binaryFile->first);
548 return emitError(loc) <<
"Couldn't open the file: `" << binaryFile->first
549 <<
"`, error message: "
550 << binaryBuffer.getError().message();
552 StringRef fatbin = (*binaryBuffer)->getBuffer();
553 return SmallVector<char, 0>(fatbin.begin(), fatbin.end());
556#if MLIR_ENABLE_NVPTXCOMPILER
557#include "nvPTXCompiler.h"
559#define RETURN_ON_NVPTXCOMPILER_ERROR(expr) \
561 if (auto status = (expr)) { \
562 emitError(loc) << llvm::Twine(#expr).concat(" failed with error code ") \
570#define RETURN_ON_NVFATBIN_ERROR(expr) \
572 auto result = (expr); \
573 if (result != nvFatbinResult::NVFATBIN_SUCCESS) { \
574 emitError(loc) << llvm::Twine(#expr).concat(" failed with error: ") \
575 << nvFatbinGetErrorString(result); \
580FailureOr<SmallVector<char, 0>>
581NVPTXSerializer::compileToBinaryNVPTX(StringRef ptxCode) {
582 Location loc = getOperation().getLoc();
583 nvPTXCompilerHandle compiler =
nullptr;
584 nvPTXCompileResult status;
588 std::string optLevel = std::to_string(this->optLevel);
589 std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>> cmdOpts =
590 targetOptions.tokenizeCmdOptions();
591 cmdOpts.second.insert(
592 cmdOpts.second.begin(),
593 {
"-arch", getTarget().getChip().data(),
"--opt-level", optLevel.c_str()});
598 RETURN_ON_NVPTXCOMPILER_ERROR(
599 nvPTXCompilerCreate(&compiler, ptxCode.size(), ptxCode.str().c_str()));
602 status = nvPTXCompilerCompile(compiler, cmdOpts.second.size(),
603 cmdOpts.second.data());
606 if (status != NVPTXCOMPILE_SUCCESS) {
607 RETURN_ON_NVPTXCOMPILER_ERROR(
608 nvPTXCompilerGetErrorLogSize(compiler, &logSize));
610 SmallVector<char> log(logSize + 1, 0);
611 RETURN_ON_NVPTXCOMPILER_ERROR(
612 nvPTXCompilerGetErrorLog(compiler, log.data()));
614 <<
"NVPTX compiler invocation failed, error log: " << log.data();
617 <<
"NVPTX compiler invocation failed with error code: " << status;
623 RETURN_ON_NVPTXCOMPILER_ERROR(
624 nvPTXCompilerGetCompiledProgramSize(compiler, &elfSize));
625 SmallVector<char, 0> binary(elfSize, 0);
626 RETURN_ON_NVPTXCOMPILER_ERROR(
627 nvPTXCompilerGetCompiledProgram(compiler, (
void *)binary.data()));
630 auto fetchInfoLog = [&]() -> SmallVector<char> {
632 if (nvPTXCompilerGetInfoLogSize(compiler, &size) != NVPTXCOMPILE_SUCCESS ||
635 SmallVector<char> log(size + 1, 0);
636 if (nvPTXCompilerGetInfoLog(compiler, log.data()) != NVPTXCOMPILE_SUCCESS)
641 if (
target.hasFlag(
"collect-compiler-diagnostics")) {
642 if (
auto log = fetchInfoLog(); !log.empty())
643 isaCompilerLog = log.data();
647#define DEBUG_TYPE "serialize-to-binary"
649 if (
auto log = fetchInfoLog(); !log.empty())
650 LDBG() <<
"NVPTX compiler invocation for module: "
651 << getOperation().getNameAttr()
652 <<
"\nArguments: " << llvm::interleaved(cmdOpts.second,
" ")
657 RETURN_ON_NVPTXCOMPILER_ERROR(nvPTXCompilerDestroy(&compiler));
659 if (targetOptions.getCompilationTarget() == gpu::CompilationTarget::Fatbin) {
660 bool useFatbin32 = llvm::any_of(cmdOpts.second, [](
const char *option) {
661 return llvm::StringRef(option) ==
"-32";
664 const char *cubinOpts[1] = {useFatbin32 ?
"-32" :
"-64"};
665 nvFatbinHandle handle;
667 auto chip = getTarget().getChip();
668 chip.consume_front(
"sm_");
670 RETURN_ON_NVFATBIN_ERROR(nvFatbinCreate(&handle, cubinOpts, 1));
671 RETURN_ON_NVFATBIN_ERROR(nvFatbinAddCubin(
672 handle, binary.data(), binary.size(), chip.data(),
nullptr));
673 RETURN_ON_NVFATBIN_ERROR(nvFatbinAddPTX(
674 handle, ptxCode.data(), ptxCode.size(), chip.data(),
nullptr,
nullptr));
677 RETURN_ON_NVFATBIN_ERROR(nvFatbinSize(handle, &fatbinSize));
678 SmallVector<char, 0> fatbin(fatbinSize, 0);
679 RETURN_ON_NVFATBIN_ERROR(nvFatbinGet(handle, (
void *)fatbin.data()));
680 RETURN_ON_NVFATBIN_ERROR(nvFatbinDestroy(&handle));
688FailureOr<SmallVector<char, 0>>
689NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
690 llvm::Timer moduleToObjectTimer(
691 "moduleToObjectTimer",
692 "Timer for perf llvm-ir -> isa and isa -> binary.");
693 llvm::scope_exit
clear([&]() { moduleToObjectTimer.clear(); });
695#define DEBUG_TYPE "serialize-to-llvm"
697 LDBG() <<
"LLVM IR for module: " << getOperation().getNameAttr();
698 LDBG() << llvmModule;
701 if (targetOptions.getCompilationTarget() == gpu::CompilationTarget::Offload)
704#if !LLVM_HAS_NVPTX_TARGET
705 return getOperation()->emitError(
706 "The `NVPTX` target was not built. Please enable it when building LLVM.");
710 FailureOr<llvm::TargetMachine *> targetMachine = getOrCreateTargetMachine();
711 if (
failed(targetMachine))
712 return getOperation().emitError()
713 <<
"Target Machine unavailable for triple " << triple
714 <<
", can't optimize with LLVM\n";
716 moduleToObjectTimer.startTimer();
717 FailureOr<SmallString<0>> serializedISA =
718 translateModuleToISA(llvmModule, **targetMachine,
719 [&]() {
return getOperation().emitError(); });
720 moduleToObjectTimer.stopTimer();
721 llvmToISATimeInMs = moduleToObjectTimer.getTotalTime().getWallTime() * 1000;
722 moduleToObjectTimer.clear();
723 if (
failed(serializedISA))
724 return getOperation().emitError()
725 <<
"Failed translating the module to ISA.";
728 isaCallback(*serializedISA);
730#define DEBUG_TYPE "serialize-to-isa"
731 LDBG() <<
"PTX for module: " << getOperation().getNameAttr() <<
"\n"
736 if (targetOptions.getCompilationTarget() == gpu::CompilationTarget::Assembly)
737 return SmallVector<char, 0>(serializedISA->begin(), serializedISA->end());
739 FailureOr<SmallVector<char, 0>>
result;
740 moduleToObjectTimer.startTimer();
742#if MLIR_ENABLE_NVPTXCOMPILER
743 result = compileToBinaryNVPTX(*serializedISA);
745 result = compileToBinary(*serializedISA);
748 moduleToObjectTimer.stopTimer();
749 isaToBinaryTimeInMs = moduleToObjectTimer.getTotalTime().getWallTime() * 1000;
750 moduleToObjectTimer.clear();
754std::optional<mlir::gpu::SerializedObject>
755NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
756 const gpu::TargetOptions &
options)
const {
758 assert(module &&
"The module must be non null.");
761 if (!mlir::isa<gpu::GPUModuleOp>(module)) {
762 module->emitError("Module must be a GPU module.");
765 NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute),
options);
767 std::optional<SmallVector<char, 0>>
result = serializer.run();
771 SmallVector<NamedAttribute, 4> properties;
772 auto llvmToISATimeInMs = serializer.getLLVMIRToISATimeInMs();
773 if (llvmToISATimeInMs.has_value())
774 properties.push_back(builder.getNamedAttr(
775 "LLVMIRToISATimeInMs", builder.getI64IntegerAttr(*llvmToISATimeInMs)));
776 auto isaToBinaryTimeInMs = serializer.getISAToBinaryTimeInMs();
777 if (isaToBinaryTimeInMs.has_value())
778 properties.push_back(
779 builder.getNamedAttr(
"ISAToBinaryTimeInMs",
780 builder.getI64IntegerAttr(*isaToBinaryTimeInMs)));
781 StringRef isaCompilerLog = serializer.getISACompilerLog();
782 if (!isaCompilerLog.empty())
783 properties.push_back(builder.getNamedAttr(
784 "ISACompilerLog", builder.getStringAttr(isaCompilerLog)));
786 return gpu::SerializedObject{std::move(*
result),
787 builder.getDictionaryAttr(properties)};
791NVVMTargetAttrImpl::createObject(Attribute attribute, Operation *module,
792 const mlir::gpu::SerializedObject &
object,
793 const gpu::TargetOptions &
options)
const {
794 auto target = cast<NVVMTargetAttr>(attribute);
795 gpu::CompilationTarget format =
options.getCompilationTarget();
796 DictionaryAttr objectProps;
798 SmallVector<NamedAttribute> properties =
799 llvm::to_vector(
object.getMetadata().getValue());
800 if (format == gpu::CompilationTarget::Assembly)
801 properties.push_back(
802 builder.getNamedAttr(
"O", builder.getI32IntegerAttr(
target.getO())));
804 if (StringRef section =
options.getELFSection(); !section.empty())
806 builder.getStringAttr(section)));
808 if (!properties.empty())
809 objectProps = builder.getDictionaryAttr(properties);
811 return builder.getAttr<gpu::ObjectAttr>(
813 builder.getStringAttr(
814 StringRef(
object.getObject().data(),
object.getObject().size())),
815 objectProps,
nullptr);
static void setOptionalCommandlineArguments(NVVMTargetAttr target, SmallVectorImpl< T > &ptxasArgs)
Adds optional command-line arguments to existing arguments.
const unsigned _mlir_embedded_libdevice_size
#define __DEFAULT_CUDATOOLKIT_PATH__
const unsigned char _mlir_embedded_libdevice[]
static llvm::ManagedStatic< PassManagerOptions > options
Attributes are known-constant values of operations.
MLIRContext * getContext() const
Return the context this attribute belongs to.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
The class represents an individual entry of a blob.
LogicalResult loadBitcodeFilesFromList(llvm::LLVMContext &context, ArrayRef< Attribute > librariesToLink, SmallVector< std::unique_ptr< llvm::Module > > &llvmModules, bool failureOnError=true)
Loads multiple bitcode files.
virtual FailureOr< SmallVector< char, 0 > > moduleToObject(llvm::Module &llvmModule)
Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode.
Operation & getOperation()
Returns the operation being serialized.
ModuleToObject(Operation &module, StringRef triple, StringRef chip, StringRef features={}, int optLevel=3, function_ref< void(llvm::Module &)> initialLlvmIRCallback={}, function_ref< void(llvm::Module &)> linkedLlvmIRCallback={}, function_ref< void(llvm::Module &)> optimizedLlvmIRCallback={}, function_ref< void(StringRef)> isaCallback={}, const llvm::cl::LibraryOptionsContext *libraryOptions=nullptr)
Operation & module
Module to transform to a binary object.
MLIRContext is the top-level object for a collection of MLIR operations.
void appendDialectRegistry(const DialectRegistry ®istry)
Append the contents of the given dialect registry to the registry associated with this context.
Dialect * getLoadedDialect(StringRef name)
Get a registered IR dialect with the given namespace.
Base class for all NVVM serializations from GPU modules into binary strings.
ArrayRef< Attribute > getLibrariesToLink() const
Returns the bitcode libraries to be linked into the gpu module after translation to LLVM IR.
SerializeGPUModuleBase(Operation &module, NVVMTargetAttr target, const gpu::TargetOptions &targetOptions={})
Initializes the toolkitPath with the path in targetOptions or if empty with the path in getCUDAToolki...
NVVMTargetAttr target
NVVM target attribute.
std::string toolkitPath
CUDA toolkit path.
SmallVector< Attribute > librariesToLink
List of LLVM bitcode to link into after translation to LLVM IR.
std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles(llvm::Module &module) override
Loads the bitcode files in librariesToLink.
LogicalResult appendStandardLibs()
Appends nvvm/libdevice.bc into librariesToLink.
static void init()
Initializes the LLVM NVPTX target by safely calling LLVMInitializeNVPTX* methods if available.
StringRef getToolkitPath() const
Returns the CUDA toolkit path.
NVVMTargetAttr getTarget() const
Returns the target attribute.
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
static AsmResourceBlob allocateInferAlign(ArrayRef< T > data, AsmResourceBlob::DeleterFn deleter={}, bool dataIsMutable=false)
This class represents a serialized object (GPU binary) with metadata (e.g.
This class serves as an opaque interface for passing options to the TargetAttrInterface methods.
void registerNVVMTargetInterfaceExternalModels(DialectRegistry ®istry)
Registers the TargetAttrInterface for the #nvvm.target attribute in the given registry.
StringRef getCUDAToolkitPath()
Searches & returns the path CUDA toolkit path, the search order is:
constexpr StringLiteral elfSectionName
Include the generated interface declarations.
DialectResourceBlobHandle< BuiltinDialect > DenseResourceElementsHandle
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
static ManagerInterface & getManagerInterface(MLIRContext *ctx)