Skip to content

Commit fe2e0c5

Browse files
committed
[GPU] Derive LoRA MAX_GEMMA_SGK from actual rank to bound opt-kernel SLM
1 parent fe39ae8 commit fe2e0c5

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • src/plugins/intel_gpu/src/graph/impls/ocl_v2

src/plugins/intel_gpu/src/graph/impls/ocl_v2/lora.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,18 @@ class LoraOptBase : public LoraRefBase<LT> {
193193
[[nodiscard]] static size_t get_max_gemma_sgk(const RuntimeParams& params) {
194194
size_t max_workgroup_size = params.get_device_info().max_work_group_size;
195195
size_t lora_count = LoraRefBase<LT>::get_lora_count(params);
196-
size_t max_gemma_sgk = max_workgroup_size / min_lora_rank / lora_count;
197-
return max_gemma_sgk;
196+
// MAX_GEMMA_SGK is the compile-time upper bound of GEMMA_SGK and sets the row count
197+
// of the second-token fma_buff[MAX_GEMMA_SGK * MAX_LORA_RANK] SLM buffer. GEMMA_SGK
198+
// itself never exceeds max_work_group_size / (lora_rank * lora_count), so deriving the
199+
// bound from min_lora_rank (16) over-allocates the buffer by lora_rank / 16 rows and,
200+
// for large ranks with wider accumulators (e.g. rank 256 in f32), overflows the 64KB
201+
// local-memory budget => clBuildProgram CL_OUT_OF_RESOURCES. Use the actual rank so the
202+
// SLM footprint stays ~max_work_group_size elements regardless of rank.
203+
const auto& state_alpha_lo = params.input_layouts[3];
204+
size_t lora_rank = extract_channel(ChannelName::FEATURE, state_alpha_lo);
205+
size_t rank_divisor = std::max<size_t>(lora_rank, min_lora_rank);
206+
size_t max_gemma_sgk = max_workgroup_size / rank_divisor / lora_count;
207+
return std::max<size_t>(max_gemma_sgk, 1ul);
198208
}
199209

200210
[[nodiscard]] static size_t is_first_token(const RuntimeParams& params) {

0 commit comments

Comments
 (0)