nitinpanj's picture
Add code.passage.json
ca3651e verified
Raw History Blame Contribute Delete
14.7 kB
{"code": {"text": "<|im_start|>system\nReasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.<|im_end|>\n<|im_start|>user\n// ===== runtime/ops/GDN.cpp =====\n#include \"ops/GDN.hpp\"\n\n#include \"metal/abi/ExecutionGeometry.h\"\n#include \"metal/abi/GDN.h\"\n#include \"ops/LaneBindings.hpp\"\n\n#include <cstddef>\n#include <stdexcept>\n#include <utility>\n#include <vector>\n\nnamespace splash::ops {\nnamespace {\n\nstatic_assert(offsetof(GDNDecodeBatchParams, conv_layer_bytes) == 16);\nstatic_assert(offsetof(GDNBatchCommitParams, conv_layer_bytes) == 32);\n\nenum class KernelLayout : uint8_t { Value48, Value32 };\n\n[[nodiscard]] KernelLayout kernelShape(const GdnShape &shape) {\n if (!shape.valid())\n throw std::invalid_argument(\"invalid GDN shape\");\n GdnShape geometry = shape;\n geometry.sigmoidGate = false;\n if (geometry == GdnShape{16, 48, 128, 10240, 16640})\n return KernelLayout::Value48;\n if (geometry == GdnShape{16, 32, 128, 8192, 12544})\n return KernelLayout::Value32;\n throw std::invalid_argument(\"unsupported compiled GDN shape\");\n}\n\n[[nodiscard]] const char *kernelName(KernelLayout shape,\n const char *value48,\n const char *value32) noexcept {\n return shape == KernelLayout::Value48 ? value48 : value32;\n}\n\n} // namespace\n\nvoid GDN::addPrefill(metal::CommandGraph &graph, GdnPrefillBuffers buffers,\n GdnShape shape, uint32_t tokens) {\n if (!tokens)\n throw std::invalid_argument(\"invalid GDN prefill geometry\");\n const KernelLayout kernel = kernelShape(shape);\n const GDNPreparePrefillParams prepare{tokens, shape.packedWidth,\n shape.sigmoidGate ? 1u : 0u};\n graph.add(kernelName(kernel, \"prefill_gdn_prepare\",\n \"prefill_gdn_prepare_vh32\"),\n {buffers.packed, buffers.convolutionWeights,\n buffers.convolutionIn, buffers.convolutionOut, buffers.queries,\n buffers.keys, buffers.values, buffers.decayWeights,\n buffers.timeBias, buffers.decay, buffers.beta},\n prepare, {uint64_t{tokens} * shape.keyHeads, 1, 1},\n {shape.headDimension, 1, 1});\n graph.add(kernelName(kernel, \"prefill_gdn_scan\",\n \"prefill_gdn_scan_vh32\"),\n {buffers.queries, buffers.keys, buffers.values, buffers.decay,\n buffers.beta, buffers.recurrentIn, buffers.recurrentOut,\n buffers.recurrentRows},\n GDNPrefillParams{tokens},\n {uint64_t{shape.valueHeads} * shape.headDimension /\n SPLASH_GDN_SCAN_STATE_ROWS,\n 1, 1},\n {SPLASH_GDN_SCAN_THREADS, 1, 1});\n graph.add(kernelName(kernel, \"prefill_gdn_gate\",\n \"prefill_gdn_gate_vh32\"),\n {buffers.recurrentRows, buffers.packed, buffers.mixerNorm,\n buffers.hidden},\n prepare, {uint64_t{tokens} * shape.valueHeads, 1, 1},\n {128, 1, 1});\n}\n\nvoid GDN::addDecode(metal::CommandGraph &graph, GdnDecodeBuffers buffers,\n GdnShape shape, uint32_t lanes, uint32_t layer,\n GdnStateStrides state) {\n if (!lanes || lanes > SPLASH_MAXIMUM_BATCH_WIDTH || !state.valid())\n throw std::invalid_argument(\"invalid GDN decode geometry\");\n const KernelLayout kernel = kernelShape(shape);\n std::vector<metal::MetalBuffer> bindings{buffers.packed,\n buffers.convolutionWeights};\n bindings.reserve(20);\n appendLaneBindings(bindings, buffers.currentStates, buffers.nextStates);\n bindings.insert(bindings.end(),\n {buffers.mixed, buffers.decayWeights, buffers.timeBias,\n buffers.decay, buffers.beta, buffers.recurrent,\n buffers.mixerNorm, buffers.hidden, buffers.arrived,\n buffers.generation});\n const GDNDecodeBatchParams params{shape.sigmoidGate ? 1u : 0u,\n shape.packedWidth,\n lanes,\n layer,\n state.convolutionLayerBytes,\n state.recurrentLayerBytes,\n state.convolutionStateBytes};\n graph.add(kernelName(kernel, \"verify_gdn_fused\", \"verify_gdn_fused_vh32\"),\n std::move(bindings), params, {shape.valueHeads, lanes, 1});\n}\n\nvoid GDN::addCommit(metal::CommandGraph &graph, GdnCommitBuffers buffers,\n GdnShape shape, uint32_t layers, uint32_t lanes,\n GdnStateStrides state) {\n if (!layers || !lanes || lanes > SPLASH_MAXIMUM_BATCH_WIDTH ||\n !state.valid())\n throw std::invalid_argument(\"invalid GDN commit geometry\");\n const KernelLayout kernel = kernelShape(shape);\n std::vector<metal::MetalBuffer> bindings{\n buffers.packed, buffers.mixed, buffers.decay, buffers.beta};\n bindings.reserve(13);\n appendLaneBindings(bindings, buffers.currentStates, buffers.nextStates);\n bindings.push_back(buffers.retainedCounts);\n constexpr uint32_t rows = SPLASH_TARGET_VERIFY_ROWS;\n const GDNBatchCommitParams params{shape.valueHeads,\n shape.packedWidth,\n lanes,\n rows * shape.packedWidth,\n rows * shape.convolutionDimension,\n rows * shape.valueHeads,\n rows * shape.valueHeads,\n 0,\n state.convolutionLayerBytes,\n state.recurrentLayerBytes,\n state.convolutionStateBytes};\n graph.add(kernelName(kernel, \"verify_gdn_commit\",\n \"verify_gdn_commit_vh32\"),\n std::move(bindings), params,\n {shape.valueHeads, layers, lanes});\n}\n\n} // namespace splash::ops\n\n\nExplain what this code does, then list any bugs you see.<|im_end|>\n<|im_start|>assistant\n<think>\n", "ids": [248045, 8678, 198, 24342, 286, 4879, 369, 716, 310, 830, 11553, 13, 5044, 1683, 15060, 1472, 279, 3274, 11, 9307, 1328, 30800, 11, 2814, 47675, 25605, 11, 321, 60445, 55404, 11, 27224, 11, 321, 30246, 303, 279, 1534, 4087, 13, 248046, 198, 248045, 846, 198, 320, 29738, 15135, 14, 3595, 15328, 30237, 6982, 29738, 198, 1032, 328, 3595, 15328, 30237, 6251, 1, 271, 1032, 328, 52195, 14, 24289, 14, 19678, 20153, 834, 1, 198, 1032, 328, 52195, 14, 24289, 15328, 30237, 834, 1, 198, 1032, 328, 3595, 7199, 2077, 51066, 6251, 1, 271, 1032, 361, 66, 64157, 29, 198, 1032, 361, 91247, 29, 198, 1032, 361, 29887, 29, 198, 1032, 361, 3112, 29, 271, 2159, 33486, 476, 3595, 313, 198, 2159, 313, 271, 1911, 16065, 7, 18634, 6489, 30237, 31489, 20428, 4714, 11, 5508, 12316, 12164, 8, 606, 220, 16, 21, 1174, 198, 1911, 16065, 7, 18634, 6489, 30237, 20428, 32332, 4714, 11, 5508, 12316, 12164, 8, 606, 220, 18, 17, 1174, 271, 8746, 523, 35393, 2106, 535, 2535, 23, 516, 313, 4997, 19, 23, 11, 4997, 18, 17, 19455, 271, 15050, 79493, 4891, 35393, 2106, 9705, 11948, 2654, 469, 16884, 11948, 594, 11882, 8, 313, 198, 220, 413, 1451, 11882, 19961, 2072, 198, 262, 2430, 1407, 476, 11469, 8753, 437, 11469, 469, 30237, 5893, 4876, 198, 220, 469, 16884, 11948, 16547, 283, 5893, 26, 198, 220, 16547, 81160, 40912, 283, 867, 26, 198, 220, 413, 318, 14837, 606, 469, 16884, 11948, 90, 16, 21, 11, 220, 19, 23, 11, 220, 16, 17, 23, 11, 220, 16, 15, 17, 19, 15, 11, 220, 16, 21, 21, 19, 15, 5242, 198, 262, 460, 35393, 2106, 476, 1094, 19, 23, 26, 198, 220, 413, 318, 14837, 606, 469, 16884, 11948, 90, 16, 21, 11, 220, 18, 17, 11, 220, 16, 17, 23, 11, 220, 23, 16, 24, 17, 11, 220, 16, 17, 20, 19, 19, 5242, 198, 262, 460, 35393, 2106, 476, 1094, 18, 17, 26, 198, 220, 2430, 1407, 476, 11469, 8753, 437, 78349, 19095, 469, 30237, 5893, 4876, 198, 92, 271, 15050, 79493, 4891, 713, 1122, 348, 22524, 657, 16247, 5283, 2106, 5893, 11, 198, 10275, 713, 1122, 348, 927, 19, 23, 11, 198, 10275, 713, 1122, 348, 927, 18, 17, 8, 19958, 313, 198, 220, 460, 5893, 606, 35393, 2106, 476, 1094, 19, 23, 907, 869, 19, 23, 535, 869, 18, 17, 26, 198, 92, 271, 92, 434, 4325, 271, 972, 469, 30237, 476, 698, 28999, 473, 1212, 20667, 476, 3926, 10886, 594, 4293, 11, 469, 16884, 28999, 473, 35021, 26502, 11, 198, 3696, 469, 16884, 11948, 5893, 11, 2535, 18, 17, 516, 10885, 8, 313, 198, 220, 413, 1451, 29567, 8, 198, 262, 2430, 1407, 476, 11469, 8753, 437, 11469, 469, 30237, 829, 7320, 16547, 4876, 198, 220, 713, 35393, 2106, 9705, 283, 9705, 11948, 25103, 1174, 198, 220, 713, 469, 30237, 48887, 28999, 473, 4714, 10236, 90, 29567, 11, 5893, 541, 10866, 3218, 11, 198, 2475, 5893, 81160, 40912, 907, 220, 16, 84, 535, 220, 15, 84, 10738, 198, 220, 4618, 1316, 53303, 657, 53303, 11, 328, 29554, 473, 1824, 16884, 45877, 487, 198, 5015, 328, 29554, 473, 1824, 16884, 45877, 2200, 71, 18, 17, 3842, 198, 309, 313, 58396, 541, 10866, 11, 26502, 25131, 3111, 53761, 11, 198, 1734, 26502, 25131, 3111, 623, 11, 26502, 25131, 3111, 2575, 11, 26502, 16773, 4547, 11, 198, 1734, 26502, 8850, 11, 26502, 10341, 11, 26502, 27114, 347, 53761, 11, 198, 1734, 26502, 6177, 79706, 11, 26502, 27114, 347, 11, 26502, 59844, 2069, 198, 309, 10236, 11, 313, 2416, 21, 19, 516, 90, 29567, 92, 348, 5893, 4582, 1465, 7421, 11, 220, 16, 11, 220, 16, 2069, 198, 309, 313, 11882, 15569, 25287, 11, 220, 16, 11, 220, 16, 13685, 198, 220, 4618, 1316, 53303, 657, 53303, 11, 328, 29554, 473, 1824, 16884, 27915, 487, 198, 5015, 328, 29554, 473, 1824, 16884, 27915, 2200, 71, 18, 17, 3842, 198, 309, 313, 58396, 16773, 4547, 11, 26502, 8850, 11, 26502, 10341, 11, 26502, 27114, 347, 11, 198, 1734, 26502, 59844, 11, 26502, 1280, 3127, 623, 11, 26502, 1280, 3127, 2575, 11, 198, 1734, 26502, 1280, 3127, 8752, 2069, 198, 309, 38315, 25391, 1062, 473, 4714, 90, 29567, 2069, 198, 309, 313, 2416, 21, 19, 516, 90, 11882, 2733, 1465, 7421, 92, 348, 5893, 15569, 25287, 593, 198, 336, 62512, 9255, 2559, 30237, 40474, 10515, 60612, 11, 198, 1734, 220, 16, 11, 220, 16, 2069, 198, 309, 313, 50, 2822, 9255, 2559, 30237, 40474, 54350, 11, 220, 16, 11, 220, 16, 13685, 198, 220, 4618, 1316, 53303, 657, 53303, 11, 328, 29554, 473, 1824, 16884, 52954, 487, 198, 5015, 328, 29554, 473, 1824, 16884, 52954, 2200, 71, 18, 17, 3842, 198, 309, 313, 58396, 1280, 3127, 8752, 11, 26502, 541, 10866, 11, 26502, 85262, 24201, 11, 198, 1734, 26502, 22003, 2069, 198, 309, 10236, 11, 313, 2416, 21, 19, 516, 90, 29567, 92, 348, 5893, 2733, 1465, 7421, 11, 220, 16, 11, 220, 16, 2069, 198, 309, 313, 16, 17, 23, 11, 220, 16, 11, 220, 16, 13685, 198, 92, 271, 972, 469, 30237, 476, 698, 31489, 1212, 20667, 476, 3926, 10886, 594, 4293, 11, 469, 16884, 31489, 35021, 26502, 11, 198, 493, 469, 16884, 11948, 5893, 11, 2535, 18, 17, 516, 31930, 11, 2535, 18, 17, 516, 6000, 11, 198, 493, 469, 16884, 1349, 2495, 3232, 1528, 8, 313, 198, 220, 413, 1451, 10399, 287, 1321, 31930, 835, 62512, 9255, 82426, 71492, 13547, 1321, 729, 2374, 19961, 2072, 198, 262, 2430, 1407, 476, 11469, 8753, 437, 11469, 469, 30237, 16401, 16547, 4876, 198, 220, 713, 35393, 2106, 9705, 283, 9705, 11948, 25103, 1174, 198, 220, 1407, 476, 3112, 27, 52195, 476, 63447, 3959, 29, 34519, 90, 58396, 541, 10866, 11, 198, 13857, 26502, 25131, 3111, 53761, 10738, 198, 220, 34519, 46904, 7, 17, 15, 1174, 198, 220, 8472, 95095, 51066, 69114, 793, 11, 26502, 4792, 22532, 11, 26502, 4381, 22532, 1174, 198, 220, 34519, 6811, 69114, 793, 4911, 1453, 198, 1638, 313, 58396, 721, 3179, 11, 26502, 27114, 347, 53761, 11, 26502, 6177, 79706, 11, 198, 4152, 26502, 27114, 347, 11, 26502, 59844, 11, 26502, 1280, 3127, 11, 198, 4152, 26502, 85262, 24201, 11, 26502, 22003, 11, 26502, 39728, 2150, 11, 198, 4152, 26502, 1257, 16744, 13685, 198, 220, 713, 469, 30237, 31489, 20428, 4714, 3506, 90, 11882, 81160, 40912, 907, 220, 16, 84, 535, 220, 15, 84, 11, 198, 1855, 5893, 541, 10866, 3218, 11, 198, 1855, 31930, 11, 198, 1855, 6000, 11, 198, 1855, 1528, 25131, 3111, 8915, 6858, 11, 198, 1855, 1528, 1280, 3127, 8915, 6858, 11, 198, 1855, 1528, 25131, 3111, 1349, 6858, 10738, 198, 220, 4618, 1316, 53303, 657, 53303, 11, 328, 12089, 1824, 16884, 736, 2506, 487, 328, 12089, 1824, 16884, 736, 2506, 2200, 71, 18, 17, 3842, 198, 309, 1407, 476, 3288, 69114, 793, 681, 3506, 11, 313, 11882, 2733, 1465, 7421, 11, 31930, 11, 220, 16, 13685, 198, 92, 271, 972, 469, 30237, 476, 698, 32332, 1212, 20667, 476, 3926, 10886, 594, 4293, 11, 469, 16884, 32332, 35021, 26502, 11, 198, 493, 469, 16884, 11948, 5893, 11, 2535, 18, 17, 516, 13224, 11, 2535, 18, 17, 516, 31930, 11, 198, 493, 469, 16884, 1349, 2495, 3232, 1528, 8, 313, 198, 220, 413, 1451, 42728, 1321, 729, 10399, 287, 1321, 31930, 835, 62512, 9255, 82426, 71492, 13547, 1321, 198, 406, 729, 2374, 19961, 2072, 198, 262, 2430, 1407, 476, 11469, 8753, 437, 11469, 469, 30237, 5099, 16547, 4876, 198, 220, 713, 35393, 2106, 9705, 283, 9705, 11948, 25103, 1174, 198, 220, 1407, 476, 3112, 27, 52195, 476, 63447, 3959, 29, 34519, 90, 198, 406, 26502, 541, 10866, 11, 26502, 721, 3179, 11, 26502, 27114, 347, 11, 26502, 59844, 10738, 198, 220, 34519, 46904, 7, 16, 18, 1174, 198, 220, 8472, 95095, 51066, 69114, 793, 11, 26502, 4792, 22532, 11, 26502, 4381, 22532, 1174, 198, 220, 34519, 2470, 3764, 1818, 19725, 59853, 2540, 61580, 1174, 198, 220, 18920, 2535, 18, 17, 516, 6761, 283, 62512, 9255, 28340, 54159, 60612, 26, 198, 220, 713, 469, 30237, 20428, 32332, 4714, 3506, 90, 11882, 2733, 1465, 7421, 11, 198, 1855, 5893, 541, 10866, 3218, 11, 198, 1855, 31930, 11, 198, 1855, 6761, 348, 5893, 541, 10866, 3218, 11, 198, 1855, 6761, 348, 5893, 25131, 3111, 25287, 11, 198, 1855, 6761, 348, 5893, 2733, 1465, 7421, 11, 198, 1855, 6761, 348, 5893, 2733, 1465, 7421, 11, 198, 1855, 220, 15, 11, 198, 1855, 1528, 25131, 3111, 8915, 6858, 11, 198, 1855, 1528, 1280, 3127, 8915, 6858, 11, 198, 1855, 1528, 25131, 3111, 1349, 6858, 10738, 198, 220, 4618, 1316, 53303, 657, 53303, 11, 328, 12089, 1824, 16884, 35145, 487, 198, 5015, 328, 12089, 1824, 16884, 35145, 2200, 71, 18, 17, 3842, 198, 309, 1407, 476, 3288, 69114, 793, 681, 3506, 11, 198, 309, 313, 11882, 2733, 1465, 7421, 11, 13224, 11, 31930, 13685, 198, 92, 271, 92, 434, 4325, 33486, 476, 3595, 1358, 814, 20139, 1092, 411, 1970, 1503, 11, 1179, 1103, 866, 21851, 488, 1436, 13, 248046, 198, 248045, 74455, 198, 248068, 198]}}