TensorTonic
Study Plans
Study Plan
Shared-Memory Bank Conflict Analyzer
GPU Programming
Easy

Analyze shared-memory bank conflicts for a group of active lanes. For lane iii, aia_iai​ is its byte address, www is bank_width_bytes, BBB is num_banks, and bib_ibi​ is its bank ID:

bi=⌊aiw⌋ mod B.b_i=\left\lfloor\frac{a_i}{w}\right\rfloor\bmod B.bi​=⌊wai​​⌋modB.

Floor rounds down, and modulo gives the remainder. In this model, a lane's conflict degree is the number of distinct addresses requested from its bank. Identical addresses share one broadcast and count once. Return a dictionary containing bank_ids and conflict_degree as one-dimensional NumPy int64 arrays, each matching the input length and lane order.

Loading visualization...

Examples

Input: byte_addresses = [0,4,8,12,16,20,24,28], num_banks = 32, bank_width_bytes = 4

Output: {"bank_ids":[0,1,2,3,4,5,6,7],"conflict_degree":[1,1,1,1,1,1,1,1]}

Explanation: Each four-byte word maps to a different bank, so every lane has conflict degree one.

Input: byte_addresses = [0,128,256,384], num_banks = 32, bank_width_bytes = 4

Output: {"bank_ids":[0,0,0,0],"conflict_degree":[4,4,4,4]}

Input: byte_addresses = [64,64,64,64], num_banks = 32, bank_width_bytes = 4

Output: {"bank_ids":[16,16,16,16],"conflict_degree":[1,1,1,1]}

Hint 1

np.unique finds distinct values in an array.

Hint 2

A Boolean mask selects the lanes belonging to one bank.

Requirements

  • Use NumPy and exact integer arithmetic.
  • Count repeated requests to the same address only once per bank.
  • Do not modify the input array.

Constraints

  • byte_addresses is a one-dimensional NumPy int64 array with 1 to 32 entries.
  • Every byte address is nonnegative.
  • num_banks and bank_width_bytes are positive Python integers, defaulting to 32 and 4.
  • The address array may be noncontiguous.
Try Similar Problems
Global-Memory Coalescing CounterEasyGPU Occupancy CalculatorMediumMeasure Kernel Timeline UtilizationMediumOrthogonalize a Muon Momentum UpdateEasyPerform Stable Exact DeduplicationEasyPatchify a Batch of ImagesEasyMixed-Precision Training Memory AccountantEasyAccount for ZeRO Memory by StageEasyImplement Symmetric INT8 QuantizationEasyEstimate Model Memory and Minimum GPU CountEasyImplement Per-Channel Weight QuantizationMediumAnalyze Prefill and Decode with the Roofline ModelMedium

Accepts: array

Accepts: number

Accepts: number

You must run your code first.

Shared-Memory Bank Conflict Analyzer

GPU Programming
Easy

Analyze shared-memory bank conflicts for a group of active lanes. For lane iii, aia_iai​ is its byte address, www is bank_width_bytes, BBB is num_banks, and bib_ibi​ is its bank ID:

bi=⌊aiw⌋ mod B.b_i=\left\lfloor\frac{a_i}{w}\right\rfloor\bmod B.bi​=⌊wai​​⌋modB.

Floor rounds down, and modulo gives the remainder. In this model, a lane's conflict degree is the number of distinct addresses requested from its bank. Identical addresses share one broadcast and count once. Return a dictionary containing bank_ids and conflict_degree as one-dimensional NumPy int64 arrays, each matching the input length and lane order.

Loading visualization...

Examples

Input: byte_addresses = [0,4,8,12,16,20,24,28], num_banks = 32, bank_width_bytes = 4

Output: {"bank_ids":[0,1,2,3,4,5,6,7],"conflict_degree":[1,1,1,1,1,1,1,1]}

Explanation: Each four-byte word maps to a different bank, so every lane has conflict degree one.

Input: byte_addresses = [0,128,256,384], num_banks = 32, bank_width_bytes = 4

Output: {"bank_ids":[0,0,0,0],"conflict_degree":[4,4,4,4]}

Input: byte_addresses = [64,64,64,64], num_banks = 32, bank_width_bytes = 4

Output: {"bank_ids":[16,16,16,16],"conflict_degree":[1,1,1,1]}

Hint 1

np.unique finds distinct values in an array.

Hint 2

A Boolean mask selects the lanes belonging to one bank.

Requirements

  • Use NumPy and exact integer arithmetic.
  • Count repeated requests to the same address only once per bank.
  • Do not modify the input array.

Constraints

  • byte_addresses is a one-dimensional NumPy int64 array with 1 to 32 entries.
  • Every byte address is nonnegative.
  • num_banks and bank_width_bytes are positive Python integers, defaulting to 32 and 4.
  • The address array may be noncontiguous.
Try Similar Problems
Global-Memory Coalescing CounterEasyGPU Occupancy CalculatorMediumMeasure Kernel Timeline UtilizationMediumOrthogonalize a Muon Momentum UpdateEasyPerform Stable Exact DeduplicationEasyPatchify a Batch of ImagesEasyMixed-Precision Training Memory AccountantEasyAccount for ZeRO Memory by StageEasyImplement Symmetric INT8 QuantizationEasyEstimate Model Memory and Minimum GPU CountEasyImplement Per-Channel Weight QuantizationMediumAnalyze Prefill and Decode with the Roofline ModelMedium

Accepts: array

Accepts: number

Accepts: number

You must run your code first.