DPCT1057#

Message#

Variable <variable name> was used in host code and device code. <variable name> type was updated to be used in SYCL device code and new <host variable name> was generated to be used in host code. You need to update the host code manually to use the new <host variable name>.

Detailed Help#

If __constant__variable is used in both host code and device code (for example, the variable is included in two compilation units and they are compiled by different compilers), it will be migrated to a dpct::constant_memory object and a new host variable <host variable name>.

Suggestions to Fix#

You need to update the host code manually to use the new <host variable name>.

For example, this original CUDA* code:

 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}

is migrated using the following migration commands:

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

which results in the following migrated SYCL* code:

 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}

The migrated SYCL code is rewritten to address the DPCT1057 warning:

 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}