A GPU thread private storage capacity allocation method and device based on PTX static analysis

By using a PTX-based static analysis method, the upper bound of events per thread is accurately derived and a compact layout is generated, which solves the problem of improper storage capacity allocation in GPU instrumentation and improves storage efficiency and execution efficiency.

CN123178089APending Publication Date: 2026-11-27GUILIN UNIV OF ELECTRONIC TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611556871.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-09
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies struggle to efficiently and accurately allocate private storage capacity to each thread during GPU instrumentation, leading to excessive space reservations or inconsistent counting results, which impacts execution and storage efficiency.

Method used

By using a static analysis method based on PTX, the PTX kernel is parsed, a program usage graph is constructed, the upper bound of events for each thread is derived, and a compact private storage layout is generated. Lock-free writing is performed using static base addresses to avoid atomic allocation of cross-thread records. The addressing rules of adjacent threads with equal capacity are merged to ensure truncation and marking when overflow occurs.

Benefits of technology

It achieves precise private storage capacity allocation, reduces storage space requirements and execution time, and improves the efficiency of the instrumentation process and storage utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178089A_ABST
    Figure CN123178089A_ABST
Patent Text Reader

Abstract

The application discloses a GPU thread private storage capacity allocation method and device based on PTX static analysis. The method parses PTX and constructs a program usage graph, divides control classes according to related coordinates, performs control slicing on selected emission points, executes abstract interpretation and bounded path exploration on a bounded power set domain, and derives the upper bound of each thread memory access event before execution. After CTA capacity mode deduplication, the addressing rules of adjacent equal-capacity threads in a block are merged, the private offset is calculated according to the capacity class, and the device descriptor is reduced from O(N) to O(N_CTA). Threads write in a lock-free manner using a static base address, and overflow is truncated. The actual event is returned by optional scanning aggregation. In experiments, the reserved space and completion time of the uniform upper bound are 2.77 and 2.559 times that of the method, and the thread-level descriptor is 256 times that of the method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of GPU compilation optimization and static program analysis technology, and relates to a method, device and computer-readable storage medium for allocating GPU thread private storage capacity based on PTX static analysis. Background Technology

[0002] GPU fine-grained memory instrumentation requires saving memory access events for each thread, such as records generated by memory trace probes. The branching of thread execution and input data affect the number of events, and the actual number cannot often be directly determined before kernel execution, making it difficult to pre-apply a fixed-length record layout. Events still need to be written to each thread's private storage.

[0003] The dynamic counting scheme first runs a counting subkernel to record the attempt status of each thread, then allocates space according to the counting results and runs the actual capture kernel. This requires two startups, and the counting process itself incurs overhead; the scheduling of the two executions may also be different, causing the counting results to be inconsistent with the actual capture.

[0004] Another approach is to set the same upper bound for each thread based on the maximum possible number of events, but this increases space reservation. The tested uniform upper bound scheme has 2.77 times the reserved space and 2.559 times the completion time of the capacity-based scheme. Maintaining independent descriptors per thread increases metadata, with the number of descriptors reaching 256 times that of the capacity-based scheme. Discarding records when the buffer is full also fails to preserve complete events.

[0005] Existing GPU static analysis tools each have their own objectives. GPUVerify uses two-thread reduction to verify data races, GPUCheck uses data flow and symbol analysis to check for thread divergence and unmergeable accesses, GPUDrano detects unmergeable memory accesses, and out-of-bounds checking tools use compile-time analysis to verify memory safety. These tools are geared towards correctness or performance diagnostics, but they do not generate private memory layouts based on the thread-wise upper bound of instrumentation events. Static trace extraction reduces the amount of dynamic recording by reconstructing the control flow stack; estimating the sampling buffer by coefficients only provides a rough size and cannot directly provide a precise thread-wise upper bound.

[0006] Abstract interpretation can deduce program bounds without executing the program, but it has not yet been used for the aforementioned GPU instrumentation of private event space allocation. When used for this task, it is also necessary to handle thread hierarchy, predicate execution, barrier synchronization, and bounded path exploration, and to enter a rejection or rollback process when the program cannot be analyzed. Summary of the Invention

[0007] This invention provides a method and apparatus for allocating GPU thread-private storage capacity based on PTX static analysis. This method does not perform a pre-count traversal, accurately derives the upper bound of thread-by-thread events and generates a compact layout before kernel execution, eliminating atomic and redundant descriptors in cross-thread record allocation.

[0008] The method of the present invention includes the following steps: S1. Analyze the PTX kernel and construct the program usage graph, pre-compute control-dependent register closures, and divide control classes according to relevant coordinates. S2. Perform control slicing on selected emission points, perform abstract interpretation and bounded path exploration on the bounded power set domain, and derive the upper bound of events for each thread; capacity analysis fails if any path cannot be fully explored. S3. Deduplicate the CTA capacity vector, merge the addressing rules of adjacent threads with equal capacity within each mode, and calculate private offsets according to capacity class. S4. Complete probe descent, define private registers using private counts, event indices, base addresses, and predicates as part of a mask; threads write to static base addresses without locking, and truncate upon overflow. S5. Collect events, optionally scanning and aggregating actual events before posting them back.

[0009] The present invention has the following beneficial effects: (1) In a kernel with 656 CTAs, 256 threads per CTA, and a total of 3,946,496 memory access events, Figure 2 Compare device descriptors, Figure 3 Compare the reserved record area. The capacity-based scheme uses a 10,496-byte device descriptor, reserving 126.288 MB, with a completion time of 5,780.71 microseconds. The uniform upper bound scheme, although using only a 16-byte descriptor, reserves 349.307 MB, 2.77 times that of the capacity-based scheme, with a completion time of 14,793.10 microseconds, 2.559 times longer. The thread-based scheme uses a 2,686,976-byte descriptor, 256 times that of the capacity-based scheme, with the same 126.288 MB reserved record area, and a completion time of 5,786.55 microseconds.

[0010] (2) The capacity class addressing saves the descriptor by CTA, and the 16N bytes of the thread table T are reduced to 16 times the CTA number bytes of the capacity class C. The device descriptor changes from O(N) per thread to O(N_CTA) per thread block, while the host capacity artifact remains O(N).

[0011] (3) Each thread directly locates the private slot using a static base address, without needing to record the atomic allocation across threads. The probe continuously accumulates the number of attempted events, and when the capacity is insufficient, it only retains the prefix within the capacity and sets an overflow flag. Compared to the record space layout U, the amount saved is 32(N b_max−∑b_i) bytes.

[0012] (4) When writing exceeds the upper bound, the data is truncated and an overflow is marked to avoid out-of-bounds access. Synthetic record tests cover integer wraparound, overflow, and boundary conditions to verify the truncation and marking logic.

[0013] (5) Optional scan aggregation only transmits back the actual events that occur, shortening the completion time in low-density configurations and can be used in conjunction with static capacity reservation. Attached Figure Description

[0014] Figure 1 The flowchart for program capacity derivation and thread-private instrumentation is as follows: the upper part shows the five-stage analysis, generation and execution process, and the lower part shows the CTA capacity layout, private address calculation and 32-byte event recording example. Figure 2 Comparison diagram of device descriptor space for capacity-based addressing (C), uniform upper bound (U), and per-thread table (T); Figure 3 Comparison of reserved record space for capacity-based addressing C, uniform upper bound U, and thread-by-thread table T under the same number of actual events. Detailed Implementation

[0015] The specific embodiments are described below with reference to the accompanying drawings. These embodiments and drawings are used to explain the principles and processes of the present invention and do not constitute a limitation on the scope of protection.

[0016] Example 1: Capacity Analysis and Private Instrumentation Process (corresponding to) Figure 1 (Upper part)

[0017] Figure 1 The first half consists of five stages: PTX parsing and control slicing, abstract execution and conservative capacity, capacity class and private layout, PTX generation and single execution, and count verification and completion return. Inputs include the PTX, emission shape, scalars, and selected sites. After parsing, the control dependency register closure R* is calculated, predicates and control dependencies related to capacity are preserved; control classes are divided according to relevant coordinates, and representative threads are selected for abstract interpretation and bounded path exploration. The maximum cumulative event count at the termination exit is taken as b_i. Capacity analysis is rejected when unsupported semantics, unresolvable control flow, current path repetition, or budget exhaustion are encountered. The capacity stage deduplicates CTA capacity vectors and merges addressing rules of adjacent threads with equal capacity within the pattern. The analysis product binds the PTX hash, analyzer hash, emission shape, scalars, and sites, generating uniform upper bounds, thread-wise tables, or capacity class addresses, and compiling the PTX. Before execution, functions, shapes, shared memory, and scalars are checked; unsupported atoms result in rejection. Each captured kernel under test is executed only once. The probe stores the attempt count at the supported exit and checks if e_i ≤ b_i after execution. If an overflow occurs, the marker is incomplete and the capture is rejected. Alternatively, K-scanning can be used to gather valid prefixes and complete synchronous backhaul.

[0018] Example 2: Abstract Domain, Control Slice, and Path Exploration (corresponding) Figure 1 The first two stages).

[0019] Defined in section 2, the bounded register field is D_b = {A⊆BV_b : |A|≤64}∪{⊤}, where BV_b is the set of b-bit specific values. If neither A nor B is ⊤ and |A∪B|≤64, the merged result is A∪B; otherwise, ⊤ is used; γ(A) = A, γ(⊤) = BV_b. The register state uses the product field, with predicate values ​​being a subset of {0,1}; floating-point and shuffle results are taken at the top. For supported unknown unsigned x, when 1≤m≤64, x mod m takes the values ​​{0,…,m−1}. Equation (8) calculates the control slice: R_0 is the set of instruction predicate registers, R_{k+1}=R_k∪⋃_(dst(u)∩R_k≠∅)src(u), and R* is the smallest fixed point of the rule on R⊇R_0. Threads sharing related coordinate components reuse the same control class analysis. Events are only accumulated when the predicate of the selected station is enabled. Control paths remain independent, path counts are not merged at the junction, and unknown predicates are conservatively forked. Recursive calls are not supported; analysis fails if the current path is repeated (pc, abstract state) or the budget is exhausted. Proposition 2 states that if the abstract pass covers the concrete semantics and all paths are explored, the initial abstract state contains the concrete state, each transformation retains the inclusion, and conservative forking covers the concrete predicate selection. By path induction, the number of concrete events does not exceed the maximum value of the termination count b_i, i.e., e_i≤b_i.

[0020] Example 3: CTA capacity layout and private address calculation (corresponding) Figure 1 (Lower left part)

[0021] Figure 1The lower-left portion illustrates capacity-class addressing with a 256-thread CTA. The capacities of four adjacent 64-thread intervals are 3, 9, 17, and 65, with starting threads 0, 64, 128, and 192, predecessor capacity slot counts 0, 192, 768, and 1856, and a total capacity of 6016 slots. The intervals reuse addressing rules, and each thread still exclusively occupies its own record area. The thread table T allocates a private half-open interval [B_i, B_i+b_i) for thread i. The capacity-class scheme deduplicates the CTA capacity vector and merges the addressing rules of adjacent threads with equal capacity within a pattern. Let the starting point of CTA c be A_c, the starting local thread of interval r be s_r, the capacity be b_r, and the total number of slots in preceding intervals be R_r, then B_(c,t)=A_c+R_r+(t−s_r)b_r=∑_(j<global(c,t))b_j. The three additive terms respectively account for predecessor CTAs, predecessor intervals, and predecessor threads within the current interval, so C and T generate the same private interval. C stores a 16-byte base address / pattern descriptor per CTA, while T stores a 16-byte base address / capacity descriptor per thread; patterns and interval constants are reduced to addressing rules, reducing the size of device descriptors from 16N bytes to 16 times the number of CTAs in bytes, while the host capacity artifact remains O(N). Record space is reserved for pre-bound blocks supported by each thread according to b_i slots, saving 32(N b_max−∑b_i) bytes compared to the uniform record layout U.

[0022] Example 4: Probe Reduction and Lock-Free Private Writes (corresponding to Figure 1 the lower-right portion and the last two stages).

[0023] Figure 1 The lower-right portion lists event fields and thread-private slots. The probe uses unsigned 64-bit counts, event indices, base addresses, and 32-bit predicate participation masks. clock64 and effective addresses are collected at enabled sites: first j=e_i is fetched, then e_i is incremented; a record is written to base+32j only when j<b_i, where base already includes 32B_i. Each record is 32 bytes, including a 64-bit timestamp, a 64-bit effective address, and 32-bit fields for site, thread, predicate participation mask, and access width. The mask is generated from the original predicate and activemask via ballot. All supported exits write counts to a separate 8-byte per-thread array; when the count exceeds capacity, incomplete capture is flagged. Record addresses are calculated from pre-allocated thread-private base addresses, eliminating the need for cross-thread record allocation atomics. The optional scheme K calculates q_i=min(e_i,b_i) and flags overflow, scans to obtain Q_i=∑_(j<i)q_j, aggregates records at B_i+k to Q_i+k for 0≤k<q_i, and uses 16 bytes to carry length / error feedback.

[0024] Example 5: Verification of Device Descriptors and Reserved Record Space (corresponding to Figure 2 , Figure 3 ).

[0025] Verification was performed using a controlled irregular memory access event kernel, emitting 656 CTAs, with 256 threads per CTA. Within each CTA, four 64-thread intervals generated 3, 9, 17, and 65 events respectively, each event being 32 bytes, for a total of 3,946,496 events. The capacity class, uniform upper bound, and the actual number of events per thread table were the same.

[0026] Figure 2 The device descriptor spaces are compared separately and displayed on a logarithmic axis in KiB. The capacity class C stores 16 bytes of descriptors per CTA, totaling 10,496 bytes, or 10.25 KiB; the thread-by-thread table T stores 16 bytes of descriptors per thread, totaling 2,686,976 bytes, or 2624.00 KiB, which is 256 times that of C; the uniform upper bound U only requires 16 bytes of descriptors, 0.0015 times that of C. C and T generate the same thread-private intervals; the difference lies in the rule reuse of descriptors.

[0027] Figure 3 Compare the reserved record areas. Both capacity class C and per-thread table T are reserved at 32∑b_i bytes, totaling 126.288 MB; the uniform upper bound U is reserved at 32Nb_max bytes, totaling 349.307 MB, which is 2.77 times that of C. The diagram only counts the record area and does not include descriptors, attempt count arrays, host buffers, or other runtime allocations.

[0028] In the same controlled experiment, the capacity-class C kernel executed in 598.08 microseconds with a completion time of 5,780.71 microseconds; the uniform upper bound U kernel executed in 639.20 microseconds (1.0688 times that of C) with a completion time of 14,793.10 microseconds (2.559 times that of C); and the thread-table T kernel executed in 598.84 microseconds (1.0013 times that of C) with a completion time of 5,786.55 microseconds (1.0010 times that of C). Scanning aggregation at low density significantly shortened the completion time; at full density, the time taken was 1.0532 times that of the non-aggregated scheme, requiring an additional 354.685 MB of device capacity. The capacity class obtains the same reserved space as the thread table with fewer descriptors, while reducing the space required for uniform upper bound and collection time.

Claims

1. A method for allocating GPU thread-private storage capacity based on PTX static analysis, characterized in that, comprising the following steps: S1. Parse a PTX kernel, construct a program usage graph containing instructions, registers, and launch points, and partition control classes according to associated coordinates; S2. Perform control slicing on a selected launch point, execute abstract interpretation and bounded path exploration on a bounded powerset abstract domain, and derive an upper bound b_i of per-thread memory access events before GPU kernel execution; S3. Reserve a private event interval [B_i, B_i + b_i) for thread i, deduplicate CTA capacity vectors, merge addressing rules of adjacent equal-capacity threads within a mode, and calculate private offsets by capacity class, such that the size of a device descriptor is reduced from O(N) per thread to O(N_CTA) per thread block; S4. Threads write to private slots using static base addresses without locks, truncate writes and set an overflow flag when exceeding the upper bound; S5. Collect events in the private slots and output the events.

2. The method according to claim 1, characterized in that, For an integer register of width b, the bounded powerset abstract domain is defined as D_b = {A ⊆ BV_b : |A| ≤ 64} ∪ {⊤}, where BV_b is a set of b-bit concrete values; when A and B are both not ⊤ and |A ∪ B| ≤ 64, A and B are merged into A ∪ B, otherwise the merged result is ⊤; the domain order is an inclusion relation, ⊤ is a maximum element, γ(A) = A, and γ(⊤) = BV_b; a register state is a product domain, and predicate values are subsets of {0, 1}; floating-point and shuffle results take the top value, and for an unsupported unknown unsigned x, when 1 ≤ m ≤ 64, x mod m takes {0, …, m − 1}.

3. The method according to claim 1, characterized in that, In S2, an instruction predicate register set is denoted as R_0, and a control dependence register closure R* is obtained by taking a minimum fixed point according to R_{k+1} = R_k ∪ ⋃_(dst(u) ∩ R_k ≠ ∅) src(u); threads sharing an associated coordinate component reuse the same control class analysis; events are accumulated only when a selected site predicate is enabled, path counts are not merged at control flow convergence, and unknown predicates are conservatively branched; recursive calls are not supported, and when (pc, abstract state) is repeated in a current path, semantics are unsupported, or a budget is exhausted, generation of a capacity artifact is rejected; after all paths are successfully explored, a maximum termination count is used as b_i.

4. The method according to claim 1, characterized in that, In S3, CTA capacity vectors are deduplicated for capacity class addressing, and addressing rules of adjacent equal-capacity threads are merged within a mode; assuming that a start point of a CTA c is A_c, a starting local thread of an interval r is s_r, a capacity of the interval r is b_r, and a total number of slots in preceding intervals is R_r, then B_(c,t) = A_c + R_r + (t − s_r) b_r = ∑_(j < global(c,t)) b_j; the number of bytes of the device descriptor is reduced from 16N of a thread table T to 16 times the number of CTAs of a capacity class C, and a host capacity artifact is still O(N).

5. The method according to claim 1, characterized in that, Record space is reserved for pre-bound blocks supported by each thread according to b_i slots, which saves 32(N b_max − ∑ b_i) bytes compared with a record space layout U; each 32-byte event record stores a 64-bit timestamp, a 64-bit effective address, and a 32-bit site, a 32-bit thread, a 32-bit predicate participation mask, and a 32-bit access width, and attempt counts are written into a separate 8-byte-per-thread array; a record address is directly calculated from a thread private base address and an event sequence number, and cross-thread record allocation atomics are not used.

6. The method according to claim 1, characterized in that, The S4 probe uses unsigned 64-bit counts, event indices, base addresses, and 32-bit predicate participation masks; after capturing the clock and valid address, take j = e_i, then increment e_i, and only write a 32-byte record to base + 32j if j < b_i; thread-private regions do not require cross-thread record allocation atomics, all supported exits save attempt counts, mark capture as incomplete when capacity is exceeded, and each output aggregation region is reserved separately.

7. The method according to claim 1, characterized in that, S5 can scan and aggregate to return only events that actually occurred; it reduces completion time at low density, takes about 1.05 times as long as the non-aggregated scheme at full density, and requires additional device capacity; static capacity reservation is used in combination with dynamic compression.

8. A GPU thread-private storage capacity allocation device based on PTX static analysis, characterized in that, Includes: A parsing module that parses PTX, builds a program usage graph, and divides control classes according to relevant coordinates; An analysis module that performs control slicing on selected emission points, executes abstract interpretation and bounded path exploration on a bounded powerset abstract domain, and derives an upper bound on per-thread memory access events; A capacity addressing module that deduplicates CTA capacity vectors, merges addressing rules for adjacent equal-capacity threads within a pattern, and calculates private offsets; a write module that performs lock-free writes to private slots using a static base address, truncating and marking when overflow occurs; A collection and output module that collects events and outputs them.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.