DPCT1057

メッセージ

<variable name> は、ホストコードとデバイスコードで使用されていました。<variable name> タイプは SYCL* デバイスコードで使用されるように更新され、新しい <host variable name> は、ホストコードで使用できるように生成されました。新しい <host variable name> を使用するように、手動でホストコードを更新する必要があります。

詳細な説明

__constant__variable 変数がホストコードとデバイスコードの両方で使用されている場合 (例えば、変数が 2 つのコンパイル単位に含まれており、異なるコンパイラーでコンパイルされる場合)、dpct::constant_memory オブジェクトと新しい <ホスト変数名> に移行されます。

修正方法の提案#

新しい <host variable name> を使用するように、手動でホストコードを更新する必要があります。

例えば、以下のオリジナル CUDA* コードについて考えてみます。


1// h.h: 
2#include <cuda_runtime.h> 
3#include <stdio.h> 
4 
5static __constant__ const float const_a = 10.f; 
6 
7// a.cu: 
8#include "h.h" 
9 
10__device__ void foo_device() { 
11 printf("%f\n", const_a); 
12} 
13 
14// b.c: 
15#include "h.h" 
16 
17void foo_host() { 
18 printf("%f\n", const_a); 
19}

上記のソースは次のコマンドラインを使用して移行されます。

1dpct --out-root out a.cu 2dpct --out-root out b.c --extra-arg=-xc

結果は、次の SYCL* コードに移行されます。


1// h.h: 
2#include <sycl/sycl.hpp> 
3#include <dpct/dpct.hpp> 
4#include <stdio.h> 
5 
6/* 
7DPCT1057:0: Variable const_a was used in host code and device code. const_a type was 
8updated to be used in SYCL device code and new const_a_host_ct1 was generated to be 
9used in host code.You need to update the host code manually to use the new 
10const_a_host_ct1.
11*/ 
12static const float const_a_host_ct1 = 10.f; 
13static dpct::constant_memory<const float, 0> const_a(10.f); 
14 
15// a.dp.cpp: 
16#include <sycl/sycl.hpp> 
17#include <dpct/dpct.hpp> 
18#include "h.h" 
19 
20void foo_device(const sycl::stream &stream_ct1, const float const_a) { 
21 /* 
22 DPCT1015:0: Output needs adjustment. 
23 */ 
24 stream_ct1 << "%f\n"; 
25} 
26 
27// b.c: 
28#include "h.h" 
29 
30void foo_host() { 
31 printf("%f\n", const_a); 
32}

移行された SYCL* コードは、DPCT1057 の警告に対処するため書き換えられています。


1// h.h: 
2#include <sycl/sycl.hpp> 
3#include <dpct/dpct.hpp> 
4#include <stdio.h> 
5 
6static const float const_a_host_ct1 = 10.f; 
7static dpct::constant_memory<const float, 0> const_a(10.f); 
8 
9// a.dp.cpp: 
10#include <sycl/sycl.hpp> 
11#include <dpct/dpct.hpp> 
12#include "h.h" 
13 
14void foo_device(const sycl::stream &stream_ct1, const float const_a) { 
15 stream_ct1 << const_a << "\n"; 
16} 
17 
18// b.c: 
19#include "h.h" 
20 
21void foo_host() { 
22 printf("%f\n", const_a_host_ct1); 
23}