blob: 81d23a2990d7ffc8be28dbe89907c1437c671d48 [file] [log] [blame]
Artem Belevich52cc4872015-05-07 19:34:16 +00001// RUN: %clang_cc1 -emit-llvm %s -fcuda-include-gpubinary %s -o - | FileCheck %s
Peter Collingbournefa4d6032011-10-06 18:51:56 +00002
Eli Bendersky3468d9d2014-04-28 22:21:28 +00003#include "Inputs/cuda.h"
Peter Collingbournefa4d6032011-10-06 18:51:56 +00004
Artem Belevich42e19492016-03-02 18:28:50 +00005// CHECK-DAG: @device_var = internal global i32
6__device__ int device_var;
7
8// CHECK-DAG: @constant_var = internal global i32
9__constant__ int constant_var;
10
11// CHECK-DAG: @shared_var = internal global i32
12__shared__ int shared_var;
13
14// Make sure host globals don't get internalized...
15// CHECK-DAG: @host_var = global i32
16int host_var;
17// ... and that extern vars remain external.
18// CHECK-DAG: @ext_host_var = external global i32
19extern int ext_host_var;
20
21// Shadows for external device-side variables are *definitions* of
22// those variables.
23// CHECK-DAG: @ext_device_var = internal global i32
24extern __device__ int ext_device_var;
25// CHECK-DAG: @ext_device_var = internal global i32
26extern __constant__ int ext_constant_var;
27
28void use_pointers() {
29 int *p;
30 p = &device_var;
31 p = &constant_var;
32 p = &shared_var;
33 p = &host_var;
34 p = &ext_device_var;
35 p = &ext_constant_var;
36 p = &ext_host_var;
37}
38
Artem Belevich52cc4872015-05-07 19:34:16 +000039// Make sure that all parts of GPU code init/cleanup are there:
40// * constant unnamed string with the kernel name
Artem Beleviche9582752015-05-11 18:35:58 +000041// CHECK: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
Artem Belevich52cc4872015-05-07 19:34:16 +000042// * constant unnamed string with GPU binary
43// CHECK: private unnamed_addr constant{{.*}}\00"
44// * constant struct that wraps GPU binary
45// CHECK: @__cuda_fatbin_wrapper = internal constant { i32, i32, i8*, i8* }
Artem Belevich8d062ad2015-05-07 21:06:03 +000046// CHECK: { i32 1180844977, i32 1, {{.*}}, i8* null }
Artem Belevich52cc4872015-05-07 19:34:16 +000047// * variable to save GPU binary handle after initialization
48// CHECK: @__cuda_gpubin_handle = internal global i8** null
49// * Make sure our constructor/destructor was added to global ctor/dtor list.
50// CHECK: @llvm.global_ctors = appending global {{.*}}@__cuda_module_ctor
51// CHECK: @llvm.global_dtors = appending global {{.*}}@__cuda_module_dtor
52
Peter Collingbournefa4d6032011-10-06 18:51:56 +000053// Test that we build the correct number of calls to cudaSetupArgument followed
54// by a call to cudaLaunch.
55
56// CHECK: define{{.*}}kernelfunc
57// CHECK: call{{.*}}cudaSetupArgument
58// CHECK: call{{.*}}cudaSetupArgument
59// CHECK: call{{.*}}cudaSetupArgument
60// CHECK: call{{.*}}cudaLaunch
61__global__ void kernelfunc(int i, int j, int k) {}
Artem Belevich52cc4872015-05-07 19:34:16 +000062
63// Test that we've built correct kernel launch sequence.
64// CHECK: define{{.*}}hostfunc
65// CHECK: call{{.*}}cudaConfigureCall
Artem Beleviche9582752015-05-11 18:35:58 +000066// CHECK: call{{.*}}kernelfunc
Artem Belevich52cc4872015-05-07 19:34:16 +000067void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }
68
Artem Belevich42e19492016-03-02 18:28:50 +000069// Test that we've built a function to register kernels and global vars.
70// CHECK: define internal void @__cuda_register_globals
Artem Belevich52cc4872015-05-07 19:34:16 +000071// CHECK: call{{.*}}cudaRegisterFunction(i8** %0, {{.*}}kernelfunc
Artem Belevich42e19492016-03-02 18:28:50 +000072// CHECK-DAG: call{{.*}}cudaRegisterVar(i8** %0, {{.*}}device_var{{.*}}i32 0, i32 4, i32 0, i32 0
73// CHECK-DAG: call{{.*}}cudaRegisterVar(i8** %0, {{.*}}constant_var{{.*}}i32 0, i32 4, i32 1, i32 0
74// CHECK-DAG: call{{.*}}cudaRegisterVar(i8** %0, {{.*}}ext_device_var{{.*}}i32 1, i32 4, i32 0, i32 0
75// CHECK-DAG: call{{.*}}cudaRegisterVar(i8** %0, {{.*}}ext_constant_var{{.*}}i32 1, i32 4, i32 1, i32 0
76// CHECK: ret void
Artem Belevich52cc4872015-05-07 19:34:16 +000077
78// Test that we've built contructor..
79// CHECK: define internal void @__cuda_module_ctor
80// .. that calls __cudaRegisterFatBinary(&__cuda_fatbin_wrapper)
81// CHECK: call{{.*}}cudaRegisterFatBinary{{.*}}__cuda_fatbin_wrapper
82// .. stores return value in __cuda_gpubin_handle
83// CHECK-NEXT: store{{.*}}__cuda_gpubin_handle
Artem Belevich42e19492016-03-02 18:28:50 +000084// .. and then calls __cuda_register_globals
85// CHECK-NEXT: call void @__cuda_register_globals
Artem Belevich52cc4872015-05-07 19:34:16 +000086
87// Test that we've created destructor.
88// CHECK: define internal void @__cuda_module_dtor
89// CHECK: load{{.*}}__cuda_gpubin_handle
90// CHECK-NEXT: call void @__cudaUnregisterFatBinary
91