Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Дотянуться до кремния. HighLoad Python: SIMD, G...

Дотянуться до кремния. HighLoad Python: SIMD, GPU – Пётр Андреев, PythoNN

Avatar for Sobolev Nikita

Sobolev Nikita

September 21, 2025
Tweet

More Decks by Sobolev Nikita

Other Decks in Programming

Transcript

  1. МФТИ - ФОПФ’19, ФПМИ’21: - CPython Internals - classic ML

    (sems) tech-проекты фин.сектор ВШЭ, Иннополис CPython music
  2. автор tg: @PyotrAndreev 8 Transistor Internals silicon wafer / crystal

    manufacturing Что сегодня на обед ?
  3. автор tg: @PyotrAndreev 9 Transistor Internals silicon wafer / crystal

    manufacturing Что сегодня на обед ?
  4. автор tg: @PyotrAndreev 10 Transistor Internals silicon wafer / crystal

    manufacturing Что сегодня на обед ?
  5. автор tg: @PyotrAndreev 11 Transistor Internals silicon wafer / crystal

    manufacturing SMT / SIMD GPU +industry +future Что сегодня на обед ?
  6. автор tg: @PyotrAndreev 16 Transistor Internals silicon wafer / crystal

    manufacturing / sand -> wafer / time / crystalline silicon • Time: days-month • 1420°C • 265kg ≈ 300mm x 2m
  7. автор tg: @PyotrAndreev 17 Transistor Internals silicon wafer / crystal

    manufacturing / sand -> wafer / time / crystalline silicon to Instagram: • Time: days-month • 1420°C • 265kg ≈ 300mm x 2m
  8. автор tg: @PyotrAndreev 18 Transistor Internals silicon wafer / crystal

    manufacturing / sand -> wafer / time / crystalline silicon to Instagram: • Time: days-month • 1420°C • 265kg ≈ 300mm x 2m
  9. автор tg: @PyotrAndreev 21 Transistor Silicon wafer: • ultra clean,

    выращенная • 30 sm • ≈$100 buy here Internals making micro-chip
  10. автор tg: @PyotrAndreev 22 Transistor Silicon wafer: • ultra clean,

    выращенная • 30 sm • ≈$100 buy here Internals making micro-chip
  11. автор tg: @PyotrAndreev 23 Transistor Silicon wafer: • ultra clean,

    выращенная • 30 sm • ≈$100 buy here Internals making micro-chip
  12. автор tg: @PyotrAndreev 24 Transistor Silicon wafer: • ultra clean,

    выращенная • 30 sm • ≈$100 buy here Internals making micro-chip
  13. автор tg: @PyotrAndreev 27 Photo-lithograph Internals making micro-chip TSMC Netherlands

    Germany Taiwan $170M <- ASML: EUV-сканеры <- Carl Zeiss SMT: оптика
  14. автор tg: @PyotrAndreev 28 Photo-lithograph Internals making micro-chip / chip

    manufacturing • 13nm – EUV • $300th – photo mask cost • ≈25kW - light energy (initial)
  15. автор tg: @PyotrAndreev 29 Photo-lithograph Internals making micro-chip / chip

    manufacturing • 13nm – EUV • $300th – photo mask cost • ≈25kW - light energy (initial)
  16. автор tg: @PyotrAndreev 30 Photo-lithograph Internals making micro-chip / chip

    manufacturing • 13nm – EUV • $300th – photo mask cost • ≈25kW - light energy (initial)
  17. автор tg: @PyotrAndreev 31 Photo-lithograph Internals making micro-chip / chip

    manufacturing • 13nm – EUV • $300th – photo mask cost • ≈25kW - light energy (initial)
  18. автор tg: @PyotrAndreev 32 Photo-lithograph Internals making micro-chip / chip

    manufacturing • 13nm – EUV • $300th – photo mask cost • ≈25kW - light energy (initial)
  19. автор tg: @PyotrAndreev 33 Photo-lithograph Internals making micro-chip / chip

    manufacturing • 13nm – EUV • $300th – photo mask cost • ≈25kW - light energy (initial) chips on 300mm wafer: (in the end) • or ≈100 GPUs • or ≈200 CPUs • or ≈1000 DRAM
  20. автор tg: @PyotrAndreev 37 Photo-lithograph Internals ≈ 100$ ≈ 150

    000$ 3 months ≈1000steps ≈200 CPUs 1 CPU: ≈26B transistors
  21. автор tg: @PyotrAndreev 38 Photo-lithograph Internals ≈ 100$ ≈ 150

    000$ wafer 125 gram ≈ gold gram x10 ≈ 1kg of gold PRICE: 3 months ≈1000steps ≈200 CPUs 1 CPU: ≈26B transistors
  22. автор tg: @PyotrAndreev 39 Photo-lithograph Internals ≈ 100$ ≈ 150

    000$ wafer 125 gram ≈ gold gram x10 ≈ 1kg of gold PRICE: 3 months ≈1000steps ≈200 CPUs 1 CPU: ≈26B transistors monthly: 50th wafers ≈ $7.5B
  23. автор tg: @PyotrAndreev 44 TSMC In time infestor report /

    A14 process / specialty technology / 3D fabric И куда мы движемся?
  24. автор tg: @PyotrAndreev 45 TSMC In time infestor report /

    A14 process / specialty technology / 3D fabric Technology: • tech-process И куда мы движемся?
  25. автор tg: @PyotrAndreev 46 TSMC History TSMC Tech Symposium Produce

    chips ≥ min тех.процесс Страшный график:
  26. автор tg: @PyotrAndreev 47 TSMC History TSMC Tech Symposium Produce

    chips ≥ min тех.процесс Страшный график:
  27. автор tg: @PyotrAndreev 48 TSMC RoadMap TSMC Tech Symposium Source

    маркетинга: Each year: faster: 20% energy: less consumption
  28. автор tg: @PyotrAndreev 49 TSMC RoadMap TSMC Tech Symposium Source

    маркетинга: Each year: faster: 20% energy: less consumption
  29. автор tg: @PyotrAndreev 50 TSMC RoadMap TSMC Tech Symposium Source

    маркетинга: Each year: faster: 20% energy: less consumption
  30. автор tg: @PyotrAndreev 51 TSMC RoadMap TSMC Tech Symposium Source

    маркетинга: Each year: faster: 20% energy: less consumption
  31. Logic Gates: transistor combinations автор tg: @PyotrAndreev 70 Transistor Architectures

    transistors in CPU / simple CPU Transistors: elementary Math: sum, mul, … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations
  32. Logic Gates: transistor combinations автор tg: @PyotrAndreev 71 Transistor Architectures

    transistors in CPU / simple CPU Transistors: Chip: elementary Math: sum, mul, … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations
  33. Logic Gates: transistor combinations автор tg: @PyotrAndreev 72 Transistor Architectures

    transistors in CPU / simple CPU Transistors: Chip: elementary Math: sum, mul, … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations Всё для чего?
  34. Logic Gates: transistor combinations автор tg: @PyotrAndreev 73 Transistor Architectures

    transistors in CPU / simple CPU Transistors: Chip: elementary Math: sum, mul, … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations Всё для чего?
  35. автор tg: @PyotrAndreev 74 Transistor Future <A10: 2D materials /

    transistor roadmap / Interuniversity Microelectronics Centre Сложное будущее:
  36. автор tg: @PyotrAndreev 75 Transistor Future <A10: 2D materials /

    transistor roadmap / Interuniversity Microelectronics Centre Сложное будущее:
  37. автор tg: @PyotrAndreev 76 Marketing Internals Each year: faster: 20%

    energy: less consumption Простой слайд:
  38. автор tg: @PyotrAndreev 77 processing units Internals CPU architecture /

    CPU works / G/CPU schemes GPU: много, просто, одновременно CPU: мало, сложно, быстро
  39. автор tg: @PyotrAndreev 78 processing units Internals • ≤ 128

    ядер – решение общих задача • сильные ядра + предсказание ветвлений, большие кеши • параллельность: ядра + векторизация + … • лучше для: одной большой задачи за раз CPU architecture / CPU works / G/CPU schemes GPU: много, просто, одновременно CPU: мало, сложно, быстро
  40. автор tg: @PyotrAndreev 79 processing units Internals • ≤ 128

    ядер – решение общих задача • сильные ядра + предсказание ветвлений, большие кеши • параллельность: ядра + векторизация + … • лучше для: одной большой задачи за раз CPU architecture / CPU works / G/CPU schemes • ~ 100 спец.ядер: • оптимизация: пропускная способность • параллельность: ~ 10th потоков • лучше для: many the same independent simple tasks GPU: много, просто, одновременно CPU: мало, сложно, быстро
  41. автор tg: @PyotrAndreev 80 CPU Internals $ python3 -c 'print(1+1)'

    2 $ python3 -m timeit -s '1000' -c 1000 50000000 loops, best of 5: 5.31 nsec per loop
  42. автор tg: @PyotrAndreev 81 CPU Internals elementary Math: sum, mul,

    … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations $ python3 -c 'print(1+1)' 2 $ python3 -m timeit -s '1000' -c 1000 50000000 loops, best of 5: 5.31 nsec per loop
  43. автор tg: @PyotrAndreev 82 CPU Internals elementary Math: sum, mul,

    … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations $ python3 -c 'print(1+1)' 2 $ python3 -m timeit -s '1000' -c 1000 50000000 loops, best of 5: 5.31 nsec per loop Byte-codes C compiled CPython for CPU
  44. автор tg: @PyotrAndreev 83 CPU Internals elementary Math: sum, mul,

    … Units: logic gate combinations IP Core: unit combinations Core: IP Core combinations $ python3 -c 'print(1+1)' 2 $ python3 -m timeit -s '1000' -c 1000 50000000 loops, best of 5: 5.31 nsec per loop Byte-codes ISA Instruction Set Architecture = CPU language micro-ops CPU decodes ISA to µ-ops C compiled CPython for CPU
  45. автор tg: @PyotrAndreev 84 CPU SMT/Hyper-Threading in core 1 core

    – many logical cores. Each logical has independent: • счётчики команд, физ.регистры но общие: • исполнительные блоки, кэши, буферы Площадь кристалла ограничена: -дублирование и межъядерная инфра энергопотребление/выделение тепла в рамках logical cores is 10–40% compute power: • L2/L3-miss, TLB-miss, mispredict, … Оба лог.ядра конкурируют за общие ресурсы. два аппаратных контекста и общий исполнительный тракт SMT — физически реализованная многопоточность внутри одного ядра logic core SP: указатель стека IP: счётчик команд GPR, флаги/статус, контекст предсказателя, … core logic core SP: указатель стека IP: счётчик команд GPR, флаги/статус, контекст предсказателя, … scheduler, branch predictor, TLB, блоки исполнения, кэши, шины, частота, термобюджет, Load/Store Unit, SIMD* cache-miss
  46. автор tg: @PyotrAndreev 85 CPU: SIMD AVX/SVE Сколько «чисел» влезает

    в вектор (примерно, зависит от выбранного формата) • 128 бит (NEON/XMM): 16×int8, 8×int16, 4×float32, 2×float64 • 256 бит (YMM): 32×int8, 16×int16, 8×float32, 4×float64 • 512 бит (ZMM): 64×int8, 32×int16, 16×float32, 8×float64 • SVE 2048 бит: 256×int8 или 32×float64. где SIMD упирается в память и когда стоит идти в кластер/шардинг
  47. автор tg: @PyotrAndreev 88 Benchmarks maths out = sin(a*b +

    c) + sqrt(|a-b|) pure_python.py 0.043s / N=2*105 / float32 numba_simd.py 0.012s / N=107 / float32
  48. автор tg: @PyotrAndreev 90 PyCuda Internals 1. от сообщества: А.Клекнер

    2. питонячая обёртка над CUDA -> верхнеуровневый доступ к API CUDA pycuda: github / doc