GPU allocation
This example creates one candidate row for every compatible pool and workload pair. The model allocates integer GPU units while respecting capacity and demand on both sides.
Input tables
Section titled “Input tables”Download gpu_pools.csv and workloads.csv, or create them from the snippets below.
pool_id,capacity,mem_gb,cost1,8,24,2552,6,16,1803,4,32,218workload_id,demand,min_mem101,4,8102,1,8103,3,32Build candidate pairs
Section titled “Build candidate pairs”CREATE CANDIDATES pool_assignmentsDECISION KEY (pool_id, workload_id)AS ( SELECT pool_id, workload_id, capacity, demand, mem_gb, min_mem, cost FROM gpu_pools CROSS JOIN workloads WHERE mem_gb >= min_mem);The cross join creates possible assignments. The WHERE clause removes pools
without enough memory for a workload.
Allocate GPUs
Section titled “Allocate GPUs”DECIDE INTO allocationFROM pool_assignmentsDECISION COLUMNS ( gpus INTEGER BETWEEN 0 AND 6)SUBJECT TO CONSTRAINT capacity: SUM(gpus) <= capacity BY (pool_id), CONSTRAINT demand: SUM(gpus) = demand BY (workload_id)MINIMIZE SUM(cost * gpus);The capacity constraint is repeated for every pool. The demand constraint is repeated for every workload.
Run the model
Section titled “Run the model”./deql \ --register-files gpu_pools.csv,workloads.csv \ pools_candidates.deql \ pools_query.deqlThe minimum-cost solution places workloads 101 and 102 on pool 2, then serves workload 103 from pool 3.
pool_id workload_id capacity demand mem_gb min_mem cost gpus2 101 6 4 16 8 180 4.02 102 6 1 16 8 180 1.03 103 4 3 32 32 218 3.0
optimal · objective 1554 · highs