Skip to content

Suppress warning: calling a constexpr __host__ function from a __host__ __device__ function is not allowed warning#49197

Closed
r-barnes wants to merge 1 commit intopytorch:masterfrom
r-barnes:export-D25440771
Closed

Suppress warning: calling a constexpr __host__ function from a __host__ __device__ function is not allowed warning#49197
r-barnes wants to merge 1 commit intopytorch:masterfrom
r-barnes:export-D25440771

Conversation

@r-barnes
Copy link
Copy Markdown
Contributor

Summary:
Compiling currently gives a number of these warnings:

caffe2/c10/util/TypeCast.h(39): warning: calling a constexpr __host__ function from a __host__ __devic
e__ function is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow thi
s.
          detected during:
            instantiation of "dest_t c10::static_cast_with_inter_type<dest_t, src_t>::apply(src_t) [wi
th dest_t=c10::complex<double>, src_t=__nv_bool]"
(157): here
            instantiation of "To c10::convert<To,From>(From) [with To=c10::complex<double>, From=__nv_
bool]"
(169): here
            instantiation of "To c10::checked_convert<To,From>(From, const char *) [with To=c10::compl
ex<double>, From=__nv_bool]"
caffe2/c10/core/Scalar.h(63): here

caffe2/c10/util/TypeCast.h(39): warning: calling a constexpr __host__ function from a __host__ __device__ function is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
          detected during:
            instantiation of "dest_t c10::static_cast_with_inter_type<dest_t, src_t>::apply(src_t) [with dest_t=c10::complex<double>, src_t=int64_t]"
(157): here
            instantiation of "To c10::convert<To,From>(From) [with To=c10::complex<double>, From=int64_t]"
(169): here
            instantiation of "To c10::checked_convert<To,From>(From, const char *) [with To=c10::complex<double>, From=int64_t]"
caffe2/c10/core/Scalar.h(63): here

Here, we take the compiler up on its suggestion and use the --expt-relaxed-constexpr flag.

As noted here either #pragma nv_exec_check_disable or #pragma hd_warning_disable could also be used. This would have less over-all impact on the code (since using the flag applies to all files touched by NVCC within this target); however, their effects are not as well documented as constexpr.

Test Plan:
Compiling

buck build mode/dev-nosan -c=python.package_style=inplace dper3/dper3_models/experimental/pytorch/ads:ads_model_generation_script

shows this warning.

We rely on sandcastle for testing here.

Reviewed By: xw285cornell

Differential Revision: D25440771

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D25440771

…t__ __device__ function is not allowed` warning (pytorch#49197)

Summary:
Pull Request resolved: pytorch#49197

Compiling currently gives a number of these warnings:
```
caffe2/c10/util/TypeCast.h(27): warning: calling a constexpr __host__ function from a __host__ __device__ function is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
          detected during:
            instantiation of "decltype(auto) c10::maybe_real<true, src_t>::apply(src_t) [with src_t=c10::complex<double>]"
(57): here
            instantiation of "uint8_t c10::static_cast_with_inter_type<uint8_t, src_t>::apply(src_t) [with src_t=c10::complex<double>]"
(157): here
            instantiation of "To c10::convert<To,From>(From) [with To=uint8_t, From=c10::complex<double>]"
(169): here
            instantiation of "To c10::checked_convert<To,From>(From, const char *) [with To=uint8_t, From=c10::complex<double>]"
caffe2/c10/co
```
Here we fix this by adding `C10_HOST_DEVICE` to the offending function.

Test Plan:
Compiling
```
buck build mode/dev-nosan -c=python.package_style=inplace dper3/dper3_models/experimental/pytorch/ads:ads_model_generation_script
```
shows this warning.

We rely on sandcastle for testing here.

Reviewed By: xw285cornell

Differential Revision: D25440771

fbshipit-source-id: c5a75ea1d9dd512d4e3a0c77353e3a9a74131616
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D25440771

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 1133428.

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…t__ __device__ function is not allowed` warning (pytorch#49197)

Summary:
Pull Request resolved: pytorch#49197

Compiling currently gives a number of these warnings:
```
caffe2/c10/util/TypeCast.h(27): warning: calling a constexpr __host__ function from a __host__ __device__ function is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
          detected during:
            instantiation of "decltype(auto) c10::maybe_real<true, src_t>::apply(src_t) [with src_t=c10::complex<double>]"
(57): here
            instantiation of "uint8_t c10::static_cast_with_inter_type<uint8_t, src_t>::apply(src_t) [with src_t=c10::complex<double>]"
(157): here
            instantiation of "To c10::convert<To,From>(From) [with To=uint8_t, From=c10::complex<double>]"
(169): here
            instantiation of "To c10::checked_convert<To,From>(From, const char *) [with To=uint8_t, From=c10::complex<double>]"
caffe2/c10/co
```
Here we fix this by adding `C10_HOST_DEVICE` to the offending function.

Test Plan:
Compiling
```
buck build mode/dev-nosan -c=python.package_style=inplace dper3/dper3_models/experimental/pytorch/ads:ads_model_generation_script
```
shows this warning.

We rely on sandcastle for testing here.

Reviewed By: xw285cornell

Differential Revision: D25440771

fbshipit-source-id: 876c412eb06e8837978061cc4793abda42fac821
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants