| 1 |
// REQUIRES: x86-registered-target |
| 2 |
// REQUIRES: nvptx-registered-target |
| 3 |
|
| 4 |
// RUN: %clang_cc1 -std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda -emit-llvm -o - %s | FileCheck --check-prefix=DEVICE %s |
| 5 |
// RUN: echo "GPU binary would be here" > %t |
| 6 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -target-sdk-version=8.0 -fcuda-include-gpubinary %t -emit-llvm -o - %s | FileCheck --check-prefix=HOST %s |
| 7 |
|
| 8 |
// Accessing nvvm intrinsics in this way no longer works. |
| 9 |
// XFAIL: * |
| 10 |
|
| 11 |
struct textureReference { |
| 12 |
int desc; |
| 13 |
}; |
| 14 |
|
| 15 |
enum ReadMode { |
| 16 |
ElementType = 0, |
| 17 |
NormalizedFloat = 1 |
| 18 |
}; |
| 19 |
|
| 20 |
template <typename T, int dim = 1, enum ReadMode mode = ElementType> |
| 21 |
struct __attribute__((device_builtin_texture_type)) texture : public textureReference { |
| 22 |
}; |
| 23 |
|
| 24 |
// On the device side, texture references are represented as `i64` handles. |
| 25 |
// DEVICE: @tex ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 |
| 26 |
// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 |
| 27 |
// On the host side, they remain in the original type. |
| 28 |
// HOST: @tex = internal global %struct.texture |
| 29 |
// HOST: @norm = internal global %struct.texture |
| 30 |
// HOST: @0 = private unnamed_addr constant [4 x i8] c"tex\00" |
| 31 |
// HOST: @1 = private unnamed_addr constant [5 x i8] c"norm\00" |
| 32 |
texture<float, 2, ElementType> tex; |
| 33 |
texture<float, 2, NormalizedFloat> norm; |
| 34 |
|
| 35 |
struct v4f { |
| 36 |
float x, y, z, w; |
| 37 |
}; |
| 38 |
|
| 39 |
__attribute__((device)) v4f tex2d_ld(texture<float, 2, ElementType>, float, float) asm("llvm.nvvm.tex.unified.2d.v4f32.f32"); |
| 40 |
__attribute__((device)) v4f tex2d_ld(texture<float, 2, NormalizedFloat>, int, int) asm("llvm.nvvm.tex.unified.2d.v4f32.s32"); |
| 41 |
|
| 42 |
// DEVICE-LABEL: float @_Z3fooff(float noundef %x, float noundef %y) |
| 43 |
// DEVICE: call i64 @llvm.nvvm.texsurf.handle.internal.p1i64(i64 addrspace(1)* @tex) |
| 44 |
// DEVICE: call %struct.v4f @llvm.nvvm.tex.unified.2d.v4f32.f32(i64 %{{.*}}, float noundef %{{.*}}, float noundef %{{.*}}) |
| 45 |
// DEVICE: call i64 @llvm.nvvm.texsurf.handle.internal.p1i64(i64 addrspace(1)* @norm) |
| 46 |
// DEVICE: call %struct.v4f @llvm.nvvm.tex.unified.2d.v4f32.s32(i64 %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}) |
| 47 |
__attribute__((device)) float foo(float x, float y) { |
| 48 |
return tex2d_ld(tex, x, y).x + tex2d_ld(norm, int(x), int(y)).x; |
| 49 |
} |
| 50 |
|
| 51 |
// HOST: define internal void @[[PREFIX:__cuda]]_register_globals |
| 52 |
// Texture references need registering with correct arguments. |
| 53 |
// HOST: call void @[[PREFIX]]RegisterTexture(i8** %0, i8*{{.*}}({{.*}}@tex{{.*}}), i8*{{.*}}({{.*}}@0{{.*}}), i8*{{.*}}({{.*}}@0{{.*}}), i32 2, i32 0, i32 0) |
| 54 |
// HOST: call void @[[PREFIX]]RegisterTexture(i8** %0, i8*{{.*}}({{.*}}@norm{{.*}}), i8*{{.*}}({{.*}}@1{{.*}}), i8*{{.*}}({{.*}}@1{{.*}}), i32 2, i32 1, i32 0) |
| 55 |
|
| 56 |
// They also need annotating in metadata. |
| 57 |
// DEVICE: !0 = !{i64 addrspace(1)* @tex, !"texture", i32 1} |
| 58 |
// DEVICE: !1 = !{i64 addrspace(1)* @norm, !"texture", i32 1} |