Currently clang treats host var address as constant in device compilation,
which causes const vars initialized with host var address promoted to
device variables incorrectly and results in undefined symbols.
This patch fixes that.
Differential D118153
[CUDA][HIP] Do not treat host var address as constant in device compilation yaxunl on Jan 25 2022, 8:20 AM. Authored by
Details Currently clang treats host var address as constant in device compilation, This patch fixes that.
Diff Detail Event TimelineComment Actions LGTM. Do we need to do anything special about __managed__ vars?
Comment Actions Right __managed__ var is special. Its address is set by runtime, therefore it is not a constant. nvcc does not treat it as constant either. https://godbolt.org/z/jK534MxfG I will fix it. BTW I just found a regression related to templates in CodeGenCUDA/host-used-device-var.cu. I will fix that and update this patch. Comment Actions Fix the regression in lit tests. Basically in device compilation we still evaluate constant expression for host functions or host template instantiation. If we just disallow host variable in any constant expressions we will get errors in template class instantiation which use host variables as non-type template arguments. Therefore we should only disallow host variables in constant expressions in situations when we are sure that allowing them will lead to issues, e.g. when promoting const variables. A CUDAConstantEvaluationContext is introduced in ASTContext to control this. Comment Actions @rsmith -- is there anything else we need to worry about when it comes to treating pointers as constant values (or not)?
|
Nit: Negations are my pet peeve. I think if (!(A||B||C||D...)) would be easier to read -- not (this or that or that) has only N+1 operations to keep in one's head vs 2*N in not this, and not that, and not that, and..... In this case it's not too bad, so I'll leave it up to you which form you prefer.