Nvidia GPU: 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 Nvidia, 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
The code is follows.

main1.cu:

#include "timer.h"

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

main2.cpp:

#include "timer.h"

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

time.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;
  }
};

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(main)

find_package(CUDA)

#set(CUDA_NVCC_FLAGS -O3)

cuda_add_executable(main main1.cu main2.cpp)

@robert.maynard

A couple of points:

  1. When testing the linked code locally I see the expected and correct behavior of the static variable address being the same
  2. If a problem did exist it would be located with how the nvcc compiler interacts with the host compiler. I recommend asking for help in https://forums.developer.nvidia.com/

Thank you very much, Are you using cmakelist to compile? I use nvcc to compile the value is the same, but use cmakelists to compile, there will be different values

Uhm, thats exactly what you asked for. By making the int in the header static, you told every translation unit thay includes the header to have unique copy of the variable, that’s how static storage spexifier works.