2016-03-03 05:03:20 +08:00
|
|
|
// RUN: echo "GPU binary would be here" > %t
|
2018-04-20 21:04:45 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
|
|
|
|
// RUN: -fcuda-include-gpubinary %t -o - \
|
2018-07-12 04:26:20 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s --check-prefixes=ALL,NORDC,CUDA,CUDANORDC
|
2018-04-20 21:04:45 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
|
|
|
|
// RUN: -fcuda-include-gpubinary %t -o - -DNOGLOBALS \
|
2018-07-12 04:26:20 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s -check-prefixes=NOGLOBALS,CUDANOGLOBALS
|
2018-04-20 21:04:45 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: -fgpu-rdc -fcuda-include-gpubinary %t -o - \
|
2018-07-12 04:26:20 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s --check-prefixes=ALL,RDC,CUDA,CUDARDC
|
2018-04-20 21:04:45 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - \
|
2018-07-12 04:26:20 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s -check-prefix=NOGPUBIN
|
2011-10-07 02:51:56 +08:00
|
|
|
|
2018-04-25 09:10:37 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
|
|
|
|
// RUN: -fcuda-include-gpubinary %t -o - -x hip\
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s --check-prefixes=ALL,NORDC,HIP,HIPEF
|
2018-04-25 09:10:37 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
|
|
|
|
// RUN: -fcuda-include-gpubinary %t -o - -DNOGLOBALS -x hip \
|
2018-07-12 04:26:20 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s -check-prefixes=NOGLOBALS,HIPNOGLOBALS
|
2018-04-25 09:10:37 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: -fgpu-rdc -fcuda-include-gpubinary %t -o - -x hip \
|
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s --check-prefixes=ALL,NORDC,HIP,HIPEF
|
2018-04-25 09:10:37 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - -x hip\
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: | FileCheck -allow-deprecated-dag-overlap %s -check-prefixes=ALL,NORDC,HIP,HIPNEF
|
2018-04-25 09:10:37 +08:00
|
|
|
|
2014-04-29 06:21:28 +08:00
|
|
|
#include "Inputs/cuda.h"
|
2011-10-07 02:51:56 +08:00
|
|
|
|
2016-03-03 02:28:53 +08:00
|
|
|
#ifndef NOGLOBALS
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL-DAG: @device_var = internal global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
__device__ int device_var;
|
|
|
|
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL-DAG: @constant_var = internal global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
__constant__ int constant_var;
|
|
|
|
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL-DAG: @shared_var = internal global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
__shared__ int shared_var;
|
|
|
|
|
|
|
|
// Make sure host globals don't get internalized...
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL-DAG: @host_var = global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
int host_var;
|
|
|
|
// ... and that extern vars remain external.
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL-DAG: @ext_host_var = external global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
extern int ext_host_var;
|
|
|
|
|
2018-12-22 09:11:09 +08:00
|
|
|
// external device-side variables -> extern references to their shadows.
|
|
|
|
// ALL-DAG: @ext_device_var = external global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
extern __device__ int ext_device_var;
|
2018-12-22 09:11:09 +08:00
|
|
|
// ALL-DAG: @ext_device_var = external global i32
|
2016-03-03 02:28:50 +08:00
|
|
|
extern __constant__ int ext_constant_var;
|
|
|
|
|
2018-12-22 09:11:09 +08:00
|
|
|
// external device-side variables with definitions should generate
|
|
|
|
// definitions for the shadows.
|
|
|
|
// ALL-DAG: @ext_device_var_def = internal global i32 undef,
|
|
|
|
extern __device__ int ext_device_var_def;
|
|
|
|
__device__ int ext_device_var_def = 1;
|
|
|
|
// ALL-DAG: @ext_device_var_def = internal global i32 undef,
|
|
|
|
__constant__ int ext_constant_var_def = 2;
|
|
|
|
|
2016-03-03 02:28:50 +08:00
|
|
|
void use_pointers() {
|
|
|
|
int *p;
|
|
|
|
p = &device_var;
|
|
|
|
p = &constant_var;
|
|
|
|
p = &shared_var;
|
|
|
|
p = &host_var;
|
|
|
|
p = &ext_device_var;
|
|
|
|
p = &ext_constant_var;
|
|
|
|
p = &ext_host_var;
|
|
|
|
}
|
|
|
|
|
2015-05-08 03:34:16 +08:00
|
|
|
// Make sure that all parts of GPU code init/cleanup are there:
|
|
|
|
// * constant unnamed string with the kernel name
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
|
2015-05-08 03:34:16 +08:00
|
|
|
// * constant unnamed string with GPU binary
|
2018-06-08 19:17:08 +08:00
|
|
|
// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
|
2018-10-03 01:48:54 +08:00
|
|
|
// HIPEF: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
|
|
|
|
// HIPNEF: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
|
2018-05-18 23:07:56 +08:00
|
|
|
// CUDANORDC-SAME: section ".nv_fatbin", align 8
|
|
|
|
// CUDARDC-SAME: section "__nv_relfatbin", align 8
|
2015-05-08 03:34:16 +08:00
|
|
|
// * constant struct that wraps GPU binary
|
2018-05-18 23:07:56 +08:00
|
|
|
// ALL: @__[[PREFIX:cuda|hip]]_fatbin_wrapper = internal constant
|
|
|
|
// ALL-SAME: { i32, i32, i8*, i8* }
|
|
|
|
// CUDA-SAME: { i32 1180844977, i32 1,
|
|
|
|
// HIP-SAME: { i32 1212764230, i32 1,
|
|
|
|
// CUDA-SAME: i8* getelementptr inbounds ({{.*}}@[[FATBIN]], i64 0, i64 0),
|
2018-10-03 01:48:54 +08:00
|
|
|
// HIPEF-SAME: i8* getelementptr inbounds ({{.*}}@[[FATBIN]], i64 0, i64 0),
|
|
|
|
// HIPNEF-SAME: i8* @[[FATBIN]],
|
2018-05-18 23:07:56 +08:00
|
|
|
// ALL-SAME: i8* null }
|
|
|
|
// CUDA-SAME: section ".nvFatBinSegment"
|
|
|
|
// HIP-SAME: section ".hipFatBinSegment"
|
2015-05-08 03:34:16 +08:00
|
|
|
// * variable to save GPU binary handle after initialization
|
2018-07-21 06:45:24 +08:00
|
|
|
// CUDANORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
|
2018-10-03 01:48:54 +08:00
|
|
|
// HIPNEF: @__[[PREFIX]]_gpubin_handle = linkonce hidden global i8** null
|
2018-04-20 21:04:45 +08:00
|
|
|
// * constant unnamed string with NVModuleID
|
2018-06-08 19:17:08 +08:00
|
|
|
// RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
|
2018-05-18 23:07:56 +08:00
|
|
|
// CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
|
2018-04-20 21:04:45 +08:00
|
|
|
// * Make sure our constructor was added to global ctor list.
|
2018-04-25 09:10:37 +08:00
|
|
|
// ALL: @llvm.global_ctors = appending global {{.*}}@__[[PREFIX]]_module_ctor
|
2018-04-20 21:04:45 +08:00
|
|
|
// * Alias to global symbol containing the NVModuleID.
|
|
|
|
// RDC: @__fatbinwrap[[MODULE_ID]] = alias { i32, i32, i8*, i8* }
|
2018-04-25 09:10:37 +08:00
|
|
|
// RDC-SAME: { i32, i32, i8*, i8* }* @__[[PREFIX]]_fatbin_wrapper
|
2015-05-08 03:34:16 +08:00
|
|
|
|
2011-10-07 02:51:56 +08:00
|
|
|
// Test that we build the correct number of calls to cudaSetupArgument followed
|
|
|
|
// by a call to cudaLaunch.
|
|
|
|
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL: define{{.*}}kernelfunc
|
2018-04-25 09:10:37 +08:00
|
|
|
// ALL: call{{.*}}[[PREFIX]]SetupArgument
|
|
|
|
// ALL: call{{.*}}[[PREFIX]]SetupArgument
|
|
|
|
// ALL: call{{.*}}[[PREFIX]]SetupArgument
|
|
|
|
// ALL: call{{.*}}[[PREFIX]]Launch
|
2011-10-07 02:51:56 +08:00
|
|
|
__global__ void kernelfunc(int i, int j, int k) {}
|
2015-05-08 03:34:16 +08:00
|
|
|
|
|
|
|
// Test that we've built correct kernel launch sequence.
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL: define{{.*}}hostfunc
|
2018-04-25 09:10:37 +08:00
|
|
|
// ALL: call{{.*}}[[PREFIX]]ConfigureCall
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL: call{{.*}}kernelfunc
|
2015-05-08 03:34:16 +08:00
|
|
|
void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }
|
2016-03-03 02:28:53 +08:00
|
|
|
#endif
|
2015-05-08 03:34:16 +08:00
|
|
|
|
2016-03-03 02:28:50 +08:00
|
|
|
// Test that we've built a function to register kernels and global vars.
|
2018-04-25 09:10:37 +08:00
|
|
|
// ALL: define internal void @__[[PREFIX]]_register_globals
|
|
|
|
// ALL: call{{.*}}[[PREFIX]]RegisterFunction(i8** %0, {{.*}}kernelfunc
|
|
|
|
// ALL-DAG: call{{.*}}[[PREFIX]]RegisterVar(i8** %0, {{.*}}device_var{{.*}}i32 0, i32 4, i32 0, i32 0
|
|
|
|
// ALL-DAG: call{{.*}}[[PREFIX]]RegisterVar(i8** %0, {{.*}}constant_var{{.*}}i32 0, i32 4, i32 1, i32 0
|
2018-12-22 09:11:09 +08:00
|
|
|
// ALL-DAG: call{{.*}}[[PREFIX]]RegisterVar(i8** %0, {{.*}}ext_device_var_def{{.*}}i32 0, i32 4, i32 0, i32 0
|
|
|
|
// ALL-DAG: call{{.*}}[[PREFIX]]RegisterVar(i8** %0, {{.*}}ext_constant_var_def{{.*}}i32 0, i32 4, i32 1, i32 0
|
2018-04-20 21:04:45 +08:00
|
|
|
// ALL: ret void
|
|
|
|
|
|
|
|
// Test that we've built a constructor.
|
2018-04-25 09:10:37 +08:00
|
|
|
// ALL: define internal void @__[[PREFIX]]_module_ctor
|
|
|
|
|
|
|
|
// In separate mode it calls __[[PREFIX]]RegisterFatBinary(&__[[PREFIX]]_fatbin_wrapper)
|
2018-07-21 06:45:24 +08:00
|
|
|
// HIP only register fat binary once.
|
|
|
|
// HIP: load i8**, i8*** @__hip_gpubin_handle
|
|
|
|
// HIP-NEXT: icmp eq i8** {{.*}}, null
|
|
|
|
// HIP-NEXT: br i1 {{.*}}, label %if, label %exit
|
|
|
|
// HIP: if:
|
2018-04-25 09:10:37 +08:00
|
|
|
// NORDC: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
|
|
|
|
// .. stores return value in __[[PREFIX]]_gpubin_handle
|
|
|
|
// NORDC-NEXT: store{{.*}}__[[PREFIX]]_gpubin_handle
|
|
|
|
// .. and then calls __[[PREFIX]]_register_globals
|
2018-07-21 06:45:24 +08:00
|
|
|
// HIP-NEXT: br label %exit
|
|
|
|
// HIP: exit:
|
|
|
|
// HIP-NEXT: load i8**, i8*** @__hip_gpubin_handle
|
2018-04-25 09:10:37 +08:00
|
|
|
// NORDC-NEXT: call void @__[[PREFIX]]_register_globals
|
2018-06-28 02:32:51 +08:00
|
|
|
// * In separate mode we also register a destructor.
|
|
|
|
// NORDC-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
|
2018-04-25 09:10:37 +08:00
|
|
|
|
|
|
|
// With relocatable device code we call __[[PREFIX]]RegisterLinkedBinary%NVModuleID%
|
|
|
|
// RDC: call{{.*}}__[[PREFIX]]RegisterLinkedBinary[[MODULE_ID]](
|
|
|
|
// RDC-SAME: __[[PREFIX]]_register_globals, {{.*}}__[[PREFIX]]_fatbin_wrapper
|
2018-04-20 21:04:45 +08:00
|
|
|
// RDC-SAME: [[MODULE_ID_GLOBAL]]
|
2015-05-08 03:34:16 +08:00
|
|
|
|
|
|
|
// Test that we've created destructor.
|
2018-04-25 09:10:37 +08:00
|
|
|
// NORDC: define internal void @__[[PREFIX]]_module_dtor
|
|
|
|
// NORDC: load{{.*}}__[[PREFIX]]_gpubin_handle
|
2018-07-21 06:45:24 +08:00
|
|
|
// CUDANORDC-NEXT: call void @__[[PREFIX]]UnregisterFatBinary
|
|
|
|
// HIP-NEXT: icmp ne i8** {{.*}}, null
|
|
|
|
// HIP-NEXT: br i1 {{.*}}, label %if, label %exit
|
|
|
|
// HIP: if:
|
|
|
|
// HIP-NEXT: call void @__[[PREFIX]]UnregisterFatBinary
|
|
|
|
// HIP-NEXT: store i8** null, i8*** @__hip_gpubin_handle
|
|
|
|
// HIP-NEXT: br label %exit
|
|
|
|
// HIP: exit:
|
2015-05-08 03:34:16 +08:00
|
|
|
|
2018-04-25 09:10:37 +08:00
|
|
|
// There should be no __[[PREFIX]]_register_globals if we have no
|
2016-03-03 02:28:53 +08:00
|
|
|
// device-side globals, but we still need to register GPU binary.
|
|
|
|
// Skip GPU binary string first.
|
2018-06-08 19:17:08 +08:00
|
|
|
// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
|
2018-10-03 01:48:54 +08:00
|
|
|
// HIPNOGLOBALS: @{{.*}} = internal constant{{.*}}
|
2018-04-25 09:10:37 +08:00
|
|
|
// NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
|
2018-05-18 23:07:56 +08:00
|
|
|
// NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
|
2018-04-25 09:10:37 +08:00
|
|
|
// NOGLOBALS: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
|
|
|
|
// NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals
|
|
|
|
// NOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
|
|
|
|
// NOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
|
2016-03-03 02:28:53 +08:00
|
|
|
|
|
|
|
// There should be no constructors/destructors if we have no GPU binary.
|
2018-04-25 09:10:37 +08:00
|
|
|
// NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals
|
|
|
|
// NOGPUBIN-NOT: define internal void @__[[PREFIX]]_module_ctor
|
|
|
|
// NOGPUBIN-NOT: define internal void @__[[PREFIX]]_module_dtor
|