---
title: "workgroup_size: attribute, TypeShade language reference"
description: "workgroup_size, an attribute in the TypeShade language reference. Optionally states the workgroup size of each loop that does not reduce in a kernel function…"
url: https://typeshade.dev/reference/attributes/workgroup_size/
language: en
---

# `@workgroup_size`

Attribute

Optionally states the workgroup size of each loop that does not reduce in a kernel function, an exported function that takes an array with no size or a 2D storage texture, as one extent: `@workgroup_size([128]) export function scale(xs: array<f32>) { … }`.

`@workgroup_size([n])` states the workgroup size the loops of the kernel function it marks run in on WebGPU.

## Compare examples

Compare a loop under the default, under 128 and a loop that reduces. The reducing loop runs at 256 whatever is written.

**Example program**`@workgroup_size([128]) export function scale(xs: array<f32>): void { for (let i = 0; i < xs.length; i++) { xs[i] = xs[i] * 2.; } }`

**Example 1`no @workgroup_size`**

**Result**

`64`

**Example 2`@workgroup_size([128])`**

**Result**

`128`

**Example 3`a loop that reduces`**

**Result**

`256`

The examples are calculation models and do not run GPU work. The reference below gives the syntax of the attribute. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it when the loops of a kernel function should run in workgroups of another size than the default of 64.

## Inputs and limits

It takes one extent, and only a kernel function takes it. A kernel function with a loop that reduces refuses it (TS8077).

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related attributes

- [`@compute`](https://typeshade.dev/reference/attributes/compute/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

## Syntax

```ts
declare function workgroup_size(size: readonly [x: number]): (target: Function, context?: unknown) => void
```

## Parameters

- `size` `readonly [x: number]`

The declaration also names what the TypeScript decorator runtime hands a decorator, `target` and `context`. A call passes neither.

## Description

Without it the compiler chooses the size, and a loop that reduces runs at 256 whatever is written. An entry takes its size as `@compute([128])`.

## See also

- [Attributes](https://typeshade.dev/reference/attributes/)
