nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
158 stars 24 forks source link

can't compile Laplace-based code on Apple Silicon machine under devel #1372

Closed paciorek closed 10 months ago

paciorek commented 11 months ago

I'm getting compilation issues on my new M2 Mac when trying to run test-ADlaplace.R. Strangely there are warnings about the bitwise | that I thought we dealt with. Also, despite everything below seeming to be just warnings, the compilation fails.

Using 1.0.1 things seem fine, as does using devel on an Intel-based Mac.

Failure occurs on the first test case:

 m <- nimbleModel(
    nimbleCode({
      y ~ dnorm(a, sd = 2)
      a ~ dnorm(mu, sd = 3)
      mu ~ dnorm(0, sd = 5)
    }), data = list(y = 4), inits = list(a = -1, mu = 0),
    buildDerivs = TRUE
  )

  mLaplace <- buildLaplace(model = m)
  mLaplaceNoSplit <- buildLaplace(model = m, control = list(split = FALSE))
  cm <- compileNimble(m)
  cL <- compileNimble(mLaplace, mLaplaceNoSplit, project = m)
 cL <- compileNimble(mLaplace, mLaplaceNoSplit, project = m)
Compiling
  [Note] This may take a minute.
  [Note] On some systems there may be some compiler warnings that can be safely ignored.
Error: Failed to create the shared library.
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -DR_NO_REMAP   -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations  -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c P_6_AGHQuad.cpp -o P_6_AGHQuad.o
using C++ compiler: ‘Apple clang version 15.0.0 (clang-1500.0.40.1)’
using SDK: ‘MacOSX14.0.sdk’
P_6_AGHQuad.cpp:1588:5: warning: variable 'Interm_586' set but not used [-Wunused-but-set-variable]
int Interm_586;
    ^
P_6_AGHQuad.cpp:1647:5: warning: variable 'Interm_592' set but not used [-Wunused-but-set-variable]
int Interm_592;
    ^
P_6_AGHQuad.cpp:5200:5: warning: variable 'Interm_521' set but not used [-Wunused-but-set-variable]
int Interm_521;
    ^
P_6_AGHQuad.cpp:5201:5: warning: variable 'Interm_522' set but not used [-Wunused-but-set-variable]
int Interm_522;
    ^
P_6_AGHQuad.cpp:5236:5: warning: variable 'Interm_539' set but not used [-Wunused-but-set-variable]
int Interm_539;
    ^
P_6_AGHQuad.cpp:5237:5: warning: variable 'Interm_540' set but not used [-Wunused-but-set-variable]
int Interm_540;
    ^
P_6_AGHQuad.cpp:5243:5: warning: variable 'Interm_545' set but not used [-Wunused-but-set-variable]
int Interm_545;
    ^
P_6_AGHQuad.cpp:5244:5: warning: variable 'Interm_546' set but not used [-Wunused-but-set-variable]
int Interm_546;
    ^
In file included from P_6_AGHQuad.cpp:6:
In file included from /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/EigenTypedefs.h:33:
In file included from /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigen.h:162:
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:227:6: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
  if(input.isMap() | (output.getNimType() != input.getNimType())) { 
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   ||
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:270:5: note: in instantiation of function template specialization 'copyNimArrToNimArrInternal<NimArr<1, double>, NimArr<2, double>>' requested here
    copyNimArrToNimArrInternal(output, input, size1, fillZeros, recycle);
    ^
P_6_AGHQuad.cpp:265:2: note: in instantiation of function template specialization 'assignNimArrToNimArr<NimArr<1, double>, NimArr<2, double>>' requested here
 assignNimArrToNimArr(theseInvTransformed, valuesAsMatrix, true, true, true, dd * dd);
 ^
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:227:6: note: cast one or both operands to int to silence this warning
  if(input.isMap() | (output.getNimType() != input.getNimType())) { 
     ^
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:227:6: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
  if(input.isMap() | (output.getNimType() != input.getNimType())) { 
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   ||
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:270:5: note: in instantiation of function template specialization 'copyNimArrToNimArrInternal<NimArr<1, CppAD::AD<double>>, NimArr<2, CppAD::AD<double>>>' requested here
    copyNimArrToNimArrInternal(output, input, size1, fillZeros, recycle);
    ^
P_6_AGHQuad.cpp:522:2: note: in instantiation of function template specialization 'assignNimArrToNimArr<NimArr<1, CppAD::AD<double>>, NimArr<2, CppAD::AD<double>>>' requested here
 assignNimArrToNimArr(theseInvTransformed, valuesAsMatrix, true, true, true, dd * dd);
 ^
P_6_AGHQuad.cpp:605:8: note: in instantiation of function template specialization 'parameterTransform::inverseTransform_AD2_<CppAD::AD<double>>' requested here
ANS_ = inverseTransform_AD2_(ARG1_transformedValues_AD_, recordingInfo_);
       ^
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:227:6: note: cast one or both operands to int to silence this warning
  if(input.isMap() | (output.getNimType() != input.getNimType())) { 
     ^
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:227:6: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
  if(input.isMap() | (output.getNimType() != input.getNimType())) { 
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   ||
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:270:5: note: in instantiation of function template specialization 'copyNimArrToNimArrInternal<NimArr<1, double>, NimArr<1, double>>' requested here
    copyNimArrToNimArrInternal(output, input, size1, fillZeros, recycle);
    ^
P_6_AGHQuad.cpp:1443:1: note: in instantiation of function template specialization 'assignNimArrToNimArr<NimArr<1, double>, NimArr<1, double>>' requested here
assignNimArrToNimArr(gr_logLik_wrt_p, Interm_567, true, true, true, npar);
^
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include/nimble/nimbleEigenNimArr.h:227:6: note: cast one or both operands to int to silence this warning
  if(input.isMap() | (output.getNimType() != input.getNimType())) { 
     ^
P_6_AGHQuad.cpp:690:62: warning: unused typedef 'EigenMapStrd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeEigenMapStrd EigenMapStrd_TYPE_;
                                                             ^
P_6_AGHQuad.cpp:691:58: warning: unused typedef 'MatrixXd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeMatrixXd MatrixXd_TYPE_;
                                                         ^
P_6_AGHQuad.cpp:921:62: warning: unused typedef 'EigenMapStrd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeEigenMapStrd EigenMapStrd_TYPE_;
                                                             ^
P_6_AGHQuad.cpp:922:58: warning: unused typedef 'MatrixXd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeMatrixXd MatrixXd_TYPE_;
                                                         ^
P_6_AGHQuad.cpp:1699:62: warning: unused typedef 'EigenMapStrd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeEigenMapStrd EigenMapStrd_TYPE_;
                                                             ^
P_6_AGHQuad.cpp:1700:58: warning: unused typedef 'MatrixXd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeMatrixXd MatrixXd_TYPE_;
                                                         ^
P_6_AGHQuad.cpp:1824:62: warning: unused typedef 'EigenMapStrd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeEigenMapStrd EigenMapStrd_TYPE_;
                                                             ^
P_6_AGHQuad.cpp:1825:58: warning: unused typedef 'MatrixXd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeMatrixXd MatrixXd_TYPE_;
                                                         ^
P_6_AGHQuad.cpp:1832:62: warning: unused typedef 'EigenMapStrd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeEigenMapStrd EigenMapStrd_TYPE_;
                                                             ^
P_6_AGHQuad.cpp:1833:58: warning: unused typedef 'MatrixXd_TYPE_' [-Wunused-local-typedef]
typedef typename EigenTemplateTypes<TYPE_>::typeMatrixXd MatrixXd_TYPE_;
perrydv commented 10 months ago

@paciorek I don't have immediate access to an M2 (or M1) Mac to test this on. The place where it comes up (line 227 of nimbleEigenNimArr.h) is in a templated function, meaning it is not compiled until it is used with specific types. My guess is that it is not compiled during package building and so was not caught when we cleaned up previous instances like this. And evidently the compiler setup on your M2 chooses to error instead of warn, which I have no idea about. Anyway it looks like it would be correct to replace "|" with "||" at that spot on line 227. I could be not seeing some deeper issue, but that might be all that is necessary.

paciorek commented 10 months ago

Changing to || caused that specific error to disappear. The warnings remain, and I think we should understand why they are happening. I'm going to wait on that until we figure out the next item below.

More importantly, I'm now getting compilation failure because nimbleCppADbaseClass.o (and corresponding .so file) is not being generated. I'm investigating that.

paciorek commented 10 months ago

Ok, the compilation goes fine (not sure what was happening with nimbleCppADbaseClass.o.

So the remaining question is the warnings about intermediate variables set but not used.

The warnings about typedefs are discussed in issue #1391

paciorek commented 10 months ago

I'm going to close this and open a new issue about the warnings about intermediate variables.