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
11 changes: 4 additions & 7 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,11 @@ bool CIRGenModule::shouldEmitCUDAGlobalVar(const VarDecl *global) const {
// size and host-side address in order to provide access to
// their device-side incarnations.

if (global->getType()->isCUDADeviceBuiltinTextureType()) {
llvm_unreachable("NYI");
}

return !langOpts.CUDAIsDevice || global->hasAttr<CUDADeviceAttr>() ||
global->hasAttr<CUDAConstantAttr>() ||
global->hasAttr<CUDASharedAttr>() ||
global->getType()->isCUDADeviceBuiltinSurfaceType();
global->getType()->isCUDADeviceBuiltinSurfaceType() ||
global->getType()->isCUDADeviceBuiltinTextureType();
}

void CIRGenModule::emitGlobal(GlobalDecl gd) {
Expand Down Expand Up @@ -1212,7 +1209,6 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef mangledName, mlir::Type ty,
// initializer.
if (gv.isDeclaration()) {
getTargetCIRGenInfo().setTargetAttributes(d, gv, *this);

// External HIP managed variables needed to be recorded for transformation
// in both device and host compilations.
if (getLangOpts().CUDA && d && d->hasAttr<HIPManagedAttr>() &&
Expand Down Expand Up @@ -1493,7 +1489,8 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d,
// because they must not be initialized.
if (linkage != cir::GlobalLinkageKind::InternalLinkage &&
(d->hasAttr<CUDADeviceAttr>() || d->hasAttr<CUDAConstantAttr>() ||
d->getType()->isCUDADeviceBuiltinSurfaceType())) {
d->getType()->isCUDADeviceBuiltinSurfaceType() ||
d->getType()->isCUDADeviceBuiltinTextureType())) {
gv->setAttr(CUDAExternallyInitializedAttr::getMnemonic(),
CUDAExternallyInitializedAttr::get(&getMLIRContext()));
}
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ mlir::Type CIRGenTypes::convertType(QualType T) {
if (mlir::Type Ty =
CGM.getTargetCIRGenInfo().getCUDADeviceBuiltinSurfaceDeviceType())
return Ty;
llvm_unreachable("NYI");
} else if (T->isCUDADeviceBuiltinTextureType()) {
if (mlir::Type Ty =
CGM.getTargetCIRGenInfo().getCUDADeviceBuiltinTextureDeviceType())
return Ty;
llvm_unreachable("NYI");
}
}
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/CIR/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,16 @@ class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo {
public:
NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
: TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}

mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const override {
// On the device side, surface reference is represented as an object handle
// in 64-bit integer.
return cir::IntType::get(&getABIInfo().CGT.getMLIRContext(), 64, true);
}
mlir::Type getCUDADeviceBuiltinTextureDeviceType() const override {
// On the device side, texture reference is represented as an object handle
// in 64-bit integer.
return cir::IntType::get(&getABIInfo().CGT.getMLIRContext(), 64, true);
}

void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global,
CIRGenModule &cgm) const override {
if (const auto *vd = clang::dyn_cast_or_null<clang::VarDecl>(decl)) {
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CIR/CodeGen/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class TargetCIRGenInfo {
virtual mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const {
return nullptr;
}
virtual mlir::Type getCUDADeviceBuiltinTextureDeviceType() const {
return nullptr;
}
virtual ~TargetCIRGenInfo() {}
};

Expand Down
24 changes: 24 additions & 0 deletions clang/test/CIR/CodeGen/CUDA/texture.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target

// RUN: %clang_cc1 -fclangir -std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda -emit-llvm -o - %s | FileCheck --check-prefix=DEVICE-LLVM %s
// RUN: %clang_cc1 -fclangir -std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda -emit-cir -o - %s | FileCheck --check-prefix=DEVICE-CIR %s
// RUN: echo "GPU binary would be here" > %t

struct textureReference {
int desc;
};

enum ReadMode {
ElementType = 0,
NormalizedFloat = 1
};

template <typename T, int dim = 1, enum ReadMode mode = ElementType>
struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
};

texture<float, 2, NormalizedFloat> tex;

// DEVICE-LLVM: @tex = addrspace(1) externally_initialized global i64 undef, align 4
// DEVICE-CIR: cir.global external addrspace(offload_global) @tex = #cir.undef : !s64i {alignment = 4 : i64, cu.externally_initialized = #cir.cu.externally_initialized}
Loading