blob: 7f5e159151cfbf61b2157ba8ff2e0a86208f3cdb [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 Belevich52cc4872015-05-07 19:34:16 +00005// Make sure that all parts of GPU code init/cleanup are there:
6// * constant unnamed string with the kernel name
Artem Beleviche9582752015-05-11 18:35:58 +00007// CHECK: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
Artem Belevich52cc4872015-05-07 19:34:16 +00008// * constant unnamed string with GPU binary
9// CHECK: private unnamed_addr constant{{.*}}\00"
10// * constant struct that wraps GPU binary
11// CHECK: @__cuda_fatbin_wrapper = internal constant { i32, i32, i8*, i8* }
Artem Belevich8d062ad2015-05-07 21:06:03 +000012// CHECK: { i32 1180844977, i32 1, {{.*}}, i8* null }
Artem Belevich52cc4872015-05-07 19:34:16 +000013// * variable to save GPU binary handle after initialization
14// CHECK: @__cuda_gpubin_handle = internal global i8** null
15// * Make sure our constructor/destructor was added to global ctor/dtor list.
16// CHECK: @llvm.global_ctors = appending global {{.*}}@__cuda_module_ctor
17// CHECK: @llvm.global_dtors = appending global {{.*}}@__cuda_module_dtor
18
Peter Collingbournefa4d6032011-10-06 18:51:56 +000019// Test that we build the correct number of calls to cudaSetupArgument followed
20// by a call to cudaLaunch.
21
22// CHECK: define{{.*}}kernelfunc
23// CHECK: call{{.*}}cudaSetupArgument
24// CHECK: call{{.*}}cudaSetupArgument
25// CHECK: call{{.*}}cudaSetupArgument
26// CHECK: call{{.*}}cudaLaunch
27__global__ void kernelfunc(int i, int j, int k) {}
Artem Belevich52cc4872015-05-07 19:34:16 +000028
29// Test that we've built correct kernel launch sequence.
30// CHECK: define{{.*}}hostfunc
31// CHECK: call{{.*}}cudaConfigureCall
Artem Beleviche9582752015-05-11 18:35:58 +000032// CHECK: call{{.*}}kernelfunc
Artem Belevich52cc4872015-05-07 19:34:16 +000033void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }
34
35// Test that we've built a function to register kernels
36// CHECK: define internal void @__cuda_register_kernels
37// CHECK: call{{.*}}cudaRegisterFunction(i8** %0, {{.*}}kernelfunc
38
39// Test that we've built contructor..
40// CHECK: define internal void @__cuda_module_ctor
41// .. that calls __cudaRegisterFatBinary(&__cuda_fatbin_wrapper)
42// CHECK: call{{.*}}cudaRegisterFatBinary{{.*}}__cuda_fatbin_wrapper
43// .. stores return value in __cuda_gpubin_handle
44// CHECK-NEXT: store{{.*}}__cuda_gpubin_handle
45// .. and then calls __cuda_register_kernels
46// CHECK-NEXT: call void @__cuda_register_kernels
47
48// Test that we've created destructor.
49// CHECK: define internal void @__cuda_module_dtor
50// CHECK: load{{.*}}__cuda_gpubin_handle
51// CHECK-NEXT: call void @__cudaUnregisterFatBinary
52