Context switching policy

hello,
I’m recently studying policies of GPU. AFAIK, GPU does not have context switching overhead since each thread allocated to SM has its own registers. Then, I got to wonder if cache miss happens on L1, does thread wait until the data is brought to l1 cache? or just context switching happens and SM gets to run without any stop?
please tell me if there is a way for me to know the number of context switching.
Also, I want to know what is the real meaning of active warp. is it warps that are currently running? Then since SM consists only 128 cores, num of max active warps should be 4, but I’m not so sure.

Sorry for many questions, thank you in advance!

If there are no eligible warps ready to run then yes, the warp will stall until either the data becomes available or another warp becomes available.

If there is an eligible warp, then it will replace the current one.

You may find Greg’s replies in this thread helpful.

NVIDIA GPUs are collections of asynchronous engines. Engines include:

  1. GR (or graphics engine) that contains the 3D, 2D, and compute pipelines. In some data center GPUs and GPUs with MIG the GR engine may only contain a compute pipe.
  2. Asynchronous Copy Engines
  3. Video Engines (NVDEC, NVENC, NVJPG, OFA)
  4. Display Engine

Multiple GPU contexts timeslice on engines. When an engine switches between two GPUs contexts there is an engine context switch which requires saving the current engine state to the outgoing context and restoring the engine state for the new context.

The SM does not “context switch”. When the compute work distributor launches a thread block (CTA) the hardware allocates all of the required resources including cta slot, shared memory, barriers, warp slots, warp registers, etc. Warps are launched on a SM sub-partition and assigned to the sub-partitions warp scheduler. The warp is considered active once all warp resources are allocated and the warp scheduler can active schedule the warp. The warp remains active until the warp completes. A warp completes either after an EXIT instruction and all instructions have completed or temporarily for a GR engine context switch that used instruction level preemption (transparent to developer).

The warp scheduler maintains state for all warps. On each cycle a warp slot for a warp scheduler is in one of the following states:

  • unallocated
  • allocated == active (smsp__warps_active)
    • stalled - see warp stall reasons (smsp__warps_issue_stalled_{reason, excluding selected and not_selected}
    • eligible - see warp stall reasons (smsp__warps_issue_stalled_{selected, not_selected}
      • not selected
      • selected

On each cycle the warp scheduler can pick any active eligible warp. The selected warp reports smsp__warps_issue_selected == smsp__inst_issued. If multiple warps were eligible, then the eligible warps that were not selected report smsp__warps_issue_not_selected. There is no overhead or work to switch between warps. No state is saved or restored. There are no performance counters to even track how many times the warp scheduler selects a different warp as it is free and fundamental to the architecture.

In your last statement you mention “cores”. CUDA “Core”, Tensor “Core”, RT “Core”, … are not CPU cores. These are marketing terms for comparison between chips. A CUDA Core is a measure of the number of FP32 thread instructions that issued each cycle and best relate to the width of the FP32 instruction pipe.