Coherent Printf Output via Thread Segmentation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

In multi-threaded processing, emitting coherent output from multiple threads for the printf function is challenging due to lack of coordination, resulting in unintelligible mixed characters and poor efficiency caused by execution divergence in single-instruction multiple-thread (SIMT) models.

Innovation Solution

Processing of the printf function is separated into two tasks: gathering per-thread data and formatting, where threads emit contiguous segments of format strings and data, which are then formatted by a display processor to produce a coherent stream.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If multiple threads access a single output stream simultaneously without coordination, then parallel execution capability is improved, but output coherence deteriorates resulting in unintelligible mixed characters

Engineering Contradiction:
Improveparallel execution capabilityVSAvoidoutput coherence
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

A buffer is introduced as an intermediary between multiple threads and the output stream. Each thread writes to its own designated portion of the buffer, and the buffer manages the coherent output. This mediator allows parallel access while maintaining output integrity through structured buffer management.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Adaptability or versatility

If multiple threads execute printf function with complex formatting codes, then formatting capability is improved, but execution efficiency deteriorates due to execution divergence in SIMT model

Engineering Contradiction:
Improveformatting capabilityVSAvoidexecution efficiency
Core Design Contradiction:
Adaptability or versatilityVSProductivity

Solution Approach 1:

The printf function execution is segmented into two distinct tasks: (1) gathering per-thread data and determining memory requirements, and (2) formatting the gathered data according to format strings. This segmentation allows the first task to execute in parallel across multiple threads while the second task handles the complex formatting logic, thereby reducing execution divergence and improving overall efficiency.

Inventive Principle:
Principle #1Segmentation

3Ease of operation

If each thread traverses and formats the printf string independently, then thread autonomy is improved, but execution time increases due to serialization

Engineering Contradiction:
Improvethread autonomyVSAvoidexecution time
Core Design Contradiction:
Ease of operationVSLoss of time

Solution Approach 1:

Each thread performs preliminary actions by gathering its data and determining the memory required before the actual formatting operation. This preliminary data preparation phase allows threads to work autonomously and in parallel, and only the final formatting step requires coordinated execution, thereby reducing overall execution time while maintaining thread autonomy where possible.

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS8752018B2Emitting coherent output from multiple threads for printf
Publication Date: 2014.06.10 NVIDIA CORP
  • US8752018B2 patent drawing
  • US8752018B2 patent drawing
  • US8752018B2 patent drawing

AI summary

One embodiment of the present invention sets forth a technique for emitting coherent output from multiple threads for the printf( ) function. Additionally, parallel (not divergent) execution of the threads for the printf( ) function is maintained when possible to improve run-time performance. Processing of the printf( ) function is separated into two tasks, gathering of the per thread data and formatting the gathered data according to the formatting codes for display. The threads emit a coherent stream of contiguous segments, where each segment includes the format string for the printf( ) function and the gathered data for a thread. The coherent stream is written by the threads and read by a display processor. The display processor executes a single thread to format the gathered data according to the format string for display.