llvm-project

Форк
0
82 строки · 2.9 Кб
1
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=com %s
2
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev,warn %s
3
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev,warn \
4
// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip %s
5
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev \
6
// RUN:   -Wno-gpu-maybe-wrong-side %s
7

8
#include "Inputs/cuda.h"
9

10
auto global_lambda = [] () { return 123; };
11

12
template<class F>
13
__global__ void kernel(F f) { f(); }
14
// dev-note@-1 3{{called by 'kernel<(lambda}}
15
// warn-note@-2 5{{called by 'kernel<(lambda}}
16

17
__host__ __device__ void hd(int x);
18

19
class A {
20
  int b;
21
public:
22
  void test() {
23
    [=](){ hd(b); }();
24

25
    [&](){ hd(b); }();
26

27
    kernel<<<1,1>>>([](){ hd(0); });
28

29
    kernel<<<1,1>>>([=](){ hd(b); });
30
    // warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
31

32
    kernel<<<1,1>>>([&](){ hd(b); });
33
    // warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
34

35
    kernel<<<1,1>>>([&] __device__ (){ hd(b); });
36
    // warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
37

38
    kernel<<<1,1>>>([&](){
39
      auto f = [&]{ hd(b); };
40
      // warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
41
      f();
42
    });
43

44
    auto lambda1 = [this] __device__ { hd(this->b); };
45
    // warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
46
    kernel<<<1,1>>>(lambda1);
47
  }
48
};
49

50
int main(void) {
51
  auto lambda_kernel = [&]__global__(){};
52
  // com-error@-1 {{kernel function 'operator()' must be a free function or static member function}}
53

54
  int b;
55
  [&](){ hd(b); }();
56

57
  [=, &b](){ hd(b); }();
58

59
  kernel<<<1,1>>>(global_lambda);
60

61
  kernel<<<1,1>>>([](){ hd(0); });
62

63
  kernel<<<1,1>>>([=](){ hd(b); });
64

65
  kernel<<<1,1>>>([b](){ hd(b); });
66

67
  kernel<<<1,1>>>([&](){ hd(b); });
68
  // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
69

70
  kernel<<<1,1>>>([=, &b](){ hd(b); });
71
  // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
72

73
  kernel<<<1,1>>>([&, b](){ hd(b); });
74

75
  kernel<<<1,1>>>([&](){
76
      auto f = [&]{ hd(b); };
77
      // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
78
      f();
79
  });
80

81
  return 0;
82
}
83

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.