2011-10-07 02:29:37 +08:00
|
|
|
//===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-10-07 02:29:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides an abstract class for CUDA code generation. Concrete
|
|
|
|
// subclasses of this implement code generation for specific CUDA
|
|
|
|
// runtime libraries.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
|
2011-10-07 02:29:37 +08:00
|
|
|
|
2019-06-17 20:51:36 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
2015-05-08 03:34:16 +08:00
|
|
|
namespace llvm {
|
|
|
|
class Function;
|
2016-03-03 02:28:50 +08:00
|
|
|
class GlobalVariable;
|
2015-05-08 03:34:16 +08:00
|
|
|
}
|
|
|
|
|
2011-10-07 02:29:37 +08:00
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class CUDAKernelCallExpr;
|
2020-03-06 01:59:33 +08:00
|
|
|
class NamedDecl;
|
2019-02-14 10:00:09 +08:00
|
|
|
class VarDecl;
|
2011-10-07 02:29:37 +08:00
|
|
|
|
|
|
|
namespace CodeGen {
|
|
|
|
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenModule;
|
2011-10-07 02:51:56 +08:00
|
|
|
class FunctionArgList;
|
2011-10-07 02:29:37 +08:00
|
|
|
class ReturnValueSlot;
|
|
|
|
class RValue;
|
|
|
|
|
|
|
|
class CGCUDARuntime {
|
|
|
|
protected:
|
|
|
|
CodeGenModule &CGM;
|
|
|
|
|
|
|
|
public:
|
2016-03-03 02:28:50 +08:00
|
|
|
// Global variable properties that must be passed to CUDA runtime.
|
2020-03-28 22:12:58 +08:00
|
|
|
class DeviceVarFlags {
|
|
|
|
public:
|
|
|
|
enum DeviceVarKind {
|
2020-03-28 03:47:12 +08:00
|
|
|
Variable, // Variable
|
|
|
|
Surface, // Builtin surface
|
|
|
|
Texture, // Builtin texture
|
|
|
|
};
|
2020-03-28 22:12:58 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned Kind : 2;
|
2020-03-28 03:47:12 +08:00
|
|
|
unsigned Extern : 1;
|
|
|
|
unsigned Constant : 1; // Constant variable.
|
|
|
|
unsigned Normalized : 1; // Normalized texture.
|
|
|
|
int SurfTexType; // Type of surface/texutre.
|
2020-03-28 22:12:58 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool N, int T)
|
|
|
|
: Kind(K), Extern(E), Constant(C), Normalized(N), SurfTexType(T) {}
|
|
|
|
|
|
|
|
DeviceVarKind getKind() const { return static_cast<DeviceVarKind>(Kind); }
|
|
|
|
bool isExtern() const { return Extern; }
|
|
|
|
bool isConstant() const { return Constant; }
|
|
|
|
bool isNormalized() const { return Normalized; }
|
|
|
|
int getSurfTexType() const { return SurfTexType; }
|
2016-03-03 02:28:50 +08:00
|
|
|
};
|
|
|
|
|
2011-10-07 02:29:37 +08:00
|
|
|
CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
|
|
|
|
virtual ~CGCUDARuntime();
|
|
|
|
|
|
|
|
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
|
|
|
|
const CUDAKernelCallExpr *E,
|
|
|
|
ReturnValueSlot ReturnValue);
|
2011-10-07 02:51:56 +08:00
|
|
|
|
2015-05-08 03:34:16 +08:00
|
|
|
/// Emits a kernel launch stub.
|
|
|
|
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
|
2019-02-14 10:00:09 +08:00
|
|
|
virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var,
|
2020-03-28 03:47:12 +08:00
|
|
|
bool Extern, bool Constant) = 0;
|
|
|
|
virtual void registerDeviceSurf(const VarDecl *VD, llvm::GlobalVariable &Var,
|
|
|
|
bool Extern, int Type) = 0;
|
|
|
|
virtual void registerDeviceTex(const VarDecl *VD, llvm::GlobalVariable &Var,
|
|
|
|
bool Extern, int Type, bool Normalized) = 0;
|
2015-05-08 03:34:16 +08:00
|
|
|
|
|
|
|
/// Constructs and returns a module initialization function or nullptr if it's
|
|
|
|
/// not needed. Must be called after all kernels have been emitted.
|
|
|
|
virtual llvm::Function *makeModuleCtorFunction() = 0;
|
|
|
|
|
|
|
|
/// Returns a module cleanup function or nullptr if it's not needed.
|
|
|
|
/// Must be called after ModuleCtorFunction
|
|
|
|
virtual llvm::Function *makeModuleDtorFunction() = 0;
|
2019-06-17 20:51:36 +08:00
|
|
|
|
2020-03-06 01:59:33 +08:00
|
|
|
/// Returns function or variable name on device side even if the current
|
|
|
|
/// compilation is for host.
|
|
|
|
virtual std::string getDeviceSideName(const NamedDecl *ND) = 0;
|
2011-10-07 02:29:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Creates an instance of a CUDA runtime class.
|
|
|
|
CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 02:29:37 +08:00
|
|
|
|
|
|
|
#endif
|