TX2 platform: code performance is not as expected

Hello,
This code will output two values, representing the address of a static variable. The two output values should be equal, but tested on the TX2 platform, they are not equal. It is now expected that the problem lies in the cu cpp mixed compilation, but no relevant official samples have been found. Please also help locate the problem.
Thank you
bug_code.tar.gz (547 Bytes)

Please don’t put such trivially simple code in a tar archive. You can easily paste it inline in your posting (example is given below). When I compile and run your code on a GTX960, I get matching output. If you see something different on a TX2 (I’m not sure why that would be - there is no GPU involvement in this code, and it is all compiled by the host compiler), you might want to ask your question on the TX2 forum.

I’m also a little confused about your statements:

First of all, there is an official sample code called cppIntegration that shows mixed compilation of .cpp and .cu files (and there are other sample codes that do this as well), and furthermore, the structure of your code does not make use of anything in the .cpp file at all:

$ cat main1.cu
#include "timer.h"

int main() {
          Timer tm;
          tm.f1();
          tm.f2();
          return 0;
}

$ cat main2.cpp
#include "timer.h"

int f() {
          Timer tm;
          tm.f1();
 //       tm.f2();
          return 0;
          }
$ cat timer.h
#pragma once
#include <iostream>

static int TimerT;

class Timer {
         public:
                   void f1() {
                               std::cout << (long)(&TimerT) << std::endl;
                                 }

                     void f2() {
                                 std::cout << (long)(&TimerT) << std::endl;
                                   }
};
$

Nothing in your code calls the f() function, so your code in the main2.cpp file should be irrelevant. Here is the output I see:

$ nvcc -o main main1.cu main2.cpp
$ ./main
4794012
4794012
$

As proof that the code in main2.cpp is irrelevant, we can successfully compile your code with:

nvcc -o main main1.cu

and observe the same result.

Thanks!
Please use cmakelists.txt in the tar.gz to compile the project.I can produce the problem on a 1080ti, which shows the problem is nothing with the platform, but with the compilation method.
The main1.cu and main2.cpp both include the timer.h, which will effect the static variable. The sample is purified from a bigger project containing .cu and .cpp files, which has the same problem because of the compilation method.

If you think the issue is specific to CMake, this is not the right forum for that. If you believe the issue is not specific to CMake, then please demonstrate it using the command line tools provided by NVIDIA. NVIDIA does not provide or support CMake.

I don’t think this is an onerous request. This is a trivially simple code, and your cmakelists.txt is also trivial.

My suggestion is that you provide a full console documentation of what you are doing, as I have shown in my response. Even if there is an observation as you describe (I can see how it would happen if you use the Timer class in separate compilation units - in spite of what you may think about static) I don’t believe the code you uploaded has the possibility to show that. I think you uploaded some version of the code which is not what you intended.

If you want to follow that suggestion, I will take another look. If not, perhaps someone else will be able to help.

Thank you very much!