# Questions about "globaltimer", functionality, accessing and configuring

**URL:** <https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268>\
**Category:** CUDA Programming and Performance\
**Created:** [August 22, 2024, 4:04pm UTC](https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268 "2024-08-22T16:04:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjwilkens](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tjwilkens](https://forums.developer.nvidia.com/u/tjwilkens)\
**Post date:** [August 22, 2024, 4:04pm UTC](https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268/1 "2024-08-22T16:04:23Z")

</div>

> [@Measuring Execution Time Inside a GPU Kernel](https://forums.developer.nvidia.com/t/measuring-execution-time-inside-a-gpu-kernel/278106):
>
> Hi everyone, I am currently working on optimizing my GPU kernels and have a couple of questions regarding performance measurement: In-Kernel Time Measurement: Is there a way to accurately measure the time elapsed inside a GPU kernel from the perspective of the GPU itself? Function-Level Profiling in NSIGHT: I am familiar with using NSIGHT for profiling the overall performance of GPU kernels. However, I’m wondering if there’s a feature or method within one of the NSIGHT profilers (like NSI…

Looking at the conversation above, I saw use of a “globaltimer” that can be used for timing. Some questions follow:

1. how can I access this in cuda in C/C++
2. is this clock synchronized across all SMs. As I understand it clock() and clock64() don’t return a clock value that is from a “synchronized” clock value across the SMs.
3. at what rate does the timer tick? On x86 it’s ~20MHz and it increments by a clock rate that doesn’t vary with pstate. This is nice because you can use the TSC (time stamp clock) to determine time expired.
4. can I modify this clock rate in CUDA with some calls to apis, or some other functionality.
5. The post above says NSIGHT ramps this timer from 1MHz to 30+MHz.. which is nice. Is there a way of doing this without NSIGHT.  
Many thanks for any helpful feedback.

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [August 22, 2024, 5:01pm UTC](https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268/2 "2024-08-22T17:01:12Z")

</div>

> [@tjwilkens](#):
>
> how can I access this in cuda in C/C++

[1](https://stackoverflow.com/questions/43008430/how-to-convert-cuda-clock-cycles-to-milliseconds/64948716#64948716) [2](https://stackoverflow.com/questions/77771384/how-to-use-the-globaltimer-register-in-cuda)

> [@tjwilkens](#):
>
> is this clock synchronized across all SMs.

yes

> [@tjwilkens](#):
>
> at what rate does the timer tick?

From the previous linked article:

> The default resolution is 32ns with update every µs. The NVIDIA performance tools force the update to every 32 ns (or 31.25 MHz).

> [@tjwilkens](#):
>
> The post above says NSIGHT ramps this timer from 1MHz to 30+MHz… which is nice. Is there a way of doing this without NSIGHT.

> [@tjwilkens](#):
>
> can I modify this clock rate in CUDA with some calls to apis, or some other functionality.

Not that I know of, barring usage of profiling tools such as CUPTI or the profilers.

---

<div class="post-metadata">

**Author:** ![tjwilkens](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tjwilkens](https://forums.developer.nvidia.com/u/tjwilkens)\
**Post date:** [August 23, 2024, 8:40pm UTC](https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268/3 "2024-08-23T20:40:06Z")

</div>

Many thanks Robert. I can not at least monitor the freq of operation to some degree of accuracy. A shame you can’t increase the update freq on the globaltimer from 1MHz to 30+.

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [August 23, 2024, 10:18pm UTC](https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268/4 "2024-08-23T22:18:23Z")

</div>

`__clock64()` offers much higher resolution, albeit not synchronized across SMs.

---

<div class="post-metadata">

**Author:** ![CU\_Steve](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CU\_Steve](https://forums.developer.nvidia.com/u/CU_Steve)\
**Post date:** [August 23, 2024, 11:28pm UTC](https://forums.developer.nvidia.com/t/questions-about-globaltimer-functionality-accessing-and-configuring/304268/5 "2024-08-23T23:28:05Z")

</div>

See also:  
[https://nvidia.github.io/cccl/libcudacxx/standard\_api/time\_library.html](https://nvidia.github.io/cccl/libcudacxx/standard_api/time_library.html)

It currently uses %globaltimer.  
If you just want to try it without getting into the details, you could use the code below.

```auto
#include <cstdint>
#include <cuda/std/chrono>
__device__ inline int64_t NS_Clock() {
  auto TimeSinceEpoch_ns = cuda::std::chrono::duration_cast<cuda::std::chrono::nanoseconds>( cuda::std::chrono::system_clock::now().time_since_epoch() );
  return static_cast<int64_t>( TimeSinceEpoch_ns.count() );
}

```
