brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · f7ac5cc Raw
59 lines · plain
1// REQUIRES: x86-registered-target2// REQUIRES: nvptx-registered-target3 4// RUN: %clang_cc1 -std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda -emit-llvm -o - %s | FileCheck --check-prefix=DEVICE %s5// RUN: echo "GPU binary would be here" > %t6// 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 %s7 8// Accessing nvvm intrinsics in this way no longer works.9// XFAIL: *10 11struct textureReference {12  int desc;13};14 15enum ReadMode {16  ElementType = 0,17  NormalizedFloat = 118};19 20template <typename T, int dim = 1, enum ReadMode mode = ElementType>21struct __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 426// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, align 427// On the host side, they remain in the original type.28// HOST: @tex = internal global %struct.texture29// HOST: @norm = internal global %struct.texture30// 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"32texture<float, 2, ElementType> tex;33texture<float, 2, NormalizedFloat> norm;34 35struct 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_globals52// 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}59