$2 के ESP32-S3 पर SIMD से computer vision acceleration
(shraiwi.github.io)- कम कीमत वाले ESP32-S3 के 128-bit SIMD instructions से FAST feature detector को accelerate किया गया, जिससे QVGA(320×240) फ्रेम को लगभग 6ms में प्रोसेस किया जा सका
- यह chip अधिकतम 240MHz dual-core CPU, WiFi, Bluetooth Low Energy वाला microcontroller है, और इसके technical reference manual में सीमित SIMD support शामिल है
- implementation का मुख्य बिंदु FAST corner pre-test में 16 8-bit pixels को एक साथ प्रोसेस करना है, लेकिन unaligned reads और signed comparison की सीमाओं को bypass करना पड़ा
- unsigned 8-bit pixels को signed comparison के अनुकूल बनाने के लिए
x - 128 == x ^ 0x80गुण का उपयोग कर values को 0x80 XOR से transform किया गया - test throughput 5.1MP/s से 11.2MP/s तक बढ़ा, और ESP32-S3 पर 30fps VGA stream प्रोसेसिंग भी संभव स्तर तक पहुंच गई
ESP32-S3 पर FAST feature detector acceleration
- ESP32-S3 के लिए SIMD-accelerated FAST feature detector implement किया गया, और इसने baseline implementation की तुलना में लगभग 2x performance दी
- एक QVGA(320×240) फ्रेम को प्रोसेस करने में लगभग 6ms लगते हैं
- ESP32-S3 एक सस्ता microcontroller है, लेकिन इसमें अधिकतम 240MHz dual-core CPU, WiFi, और Bluetooth Low Energy शामिल हैं
- ESP32-S3 technical reference manual में सीमित SIMD instruction support की पुष्टि की जा सकती है
कम चर्चित SIMD instructions और implementation की तैयारी
- ESP32-S3 के SIMD instructions कोई secret feature नहीं हैं, लेकिन वे अपेक्षाकृत कम जाने जाते रहे हैं
- संदर्भ के लिए तीन उदाहरण दिए गए हैं
- Larry Bank’s blog: feature exploration और minimal example प्रदान करता है
esp-dsp: convolution, FFT जैसी DSP प्रकृति की functionality के लिए इस्तेमाल होने वाली Espressif libraryesp-dl: on-chip AI acceleration के लिए इस्तेमाल होने वाली Espressif library
- implementation के दौरान ESP32-S3 assembly की बुनियादी संरचना सीखी गई, और अपना basic register allocator
basmभी लिखा गया
FAST corner pre-test का SIMD processing तरीका
- FAST feature detector का corner pre-test पूर्व, पश्चिम, उत्तर, दक्षिण दिशा के pixels sample करके यह जांचता है कि कम से कम 3 “extreme” pixels हैं या नहीं
- यहां extreme pixel वह है जिसका center pixel से absolute difference किसी निश्चित threshold से अधिक हो
- क्योंकि प्रत्येक vector register में 16 8-bit values स्टोर हो सकती हैं, इसे इस तरह बनाया गया कि एक बार में 16 pixels का extrema count निकाला जा सके
- पूर्व, पश्चिम, उत्तर, दक्षिण प्रत्येक दिशा से चार pixel chunks sample किए जाते हैं और उन्हें संबंधित center pixels से compare किया जाता है
ESP32-S3 SIMD की सीमाएं और workaround
- पहली सीमा यह है कि ISA direct misaligned read की अनुमति नहीं देता
- यदि center pixel aligned हो, तो east और west blocks unaligned हो जाते हैं
- दो adjacent registers को जोड़ने और फिर आंशिक slice निकालने वाले instruction से east और west blocks प्राप्त किए जाते हैं
- दूसरी सीमा यह है कि ESP32-S3 केवल signed 8-bit comparisons implement करता है
- pixel data unsigned 8-bit में store होती है, इसलिए उसे सीधे signed मानने पर
[128, 255]range[-128, -1]में non-linear mapping बनाती है - इस स्थिति में comparison operations सही तरीके से काम नहीं करते
- pixel data unsigned 8-bit में store होती है, इसलिए उसे सीधे signed मानने पर
unsigned pixels को signed comparison के अनुकूल बनाना
- pixel values को
[0, 255]से[-128, 127]में shift करना जरूरी है, ताकि comparison और arithmetic अर्थपूर्ण तरीके से काम कर सकें - पहली नज़र में 128 घटाना पर्याप्त लग सकता है, लेकिन ESP32-S3 के SIMD arithmetic operations सभी saturating arithmetic हैं, इसलिए समस्या आती है
- 127 से बड़े pixel values सही underflow नहीं करते, बल्कि
-128पर clamp हो जाते हैं
- 127 से बड़े pixel values सही underflow नहीं करते, बल्कि
- समाधान यह है कि subtraction instruction के बिना parallel रूप से 128 घटाया जाए
- signed 8-bit में सबसे ऊपरी bit का positional value
-128होता है x - 128सबसे ऊपरी bit को flip करने के बराबर है- इसलिए
x - 128 == x ^ 0x80संबंध का उपयोग किया गया
- signed 8-bit में सबसे ऊपरी bit का positional value
- हर बार unsigned 8-bit value load करते समय उसे
0x80के साथ XOR करके ऐसी linear range में बदला जाता है जहां arithmetic और comparison संभव हों
performance परिणाम और real-time processing की संभावना
- इन दो workaround techniques के जरिए SIMD-accelerated FAST corner pre-test implement किया गया
- समान operations के संयोजन से SIMD-accelerated scoring function भी लिखा गया, लेकिन उसके विवरण शामिल नहीं हैं
- tests में FAST feature detector throughput 5.1MP/s से 11.2MP/s तक बढ़ी
- throughput पहले की तुलना में लगभग 220% स्तर तक पहुंची
- यह performance real-time computer vision workloads के लिए स्वीकार्य सीमा में है, और ESP32-S3 को 30fps VGA stream आसानी से प्रोसेस करने योग्य बनाती है
1 टिप्पणियां
Hacker News की राय
क्योंकि बड़ी कंपनियां स्थानीय farms का शोषण करती हैं और व्यावहारिक रूप से क्षेत्रीय monopoly बनाए रखती हैं, जिससे farms को अपनी असली कीमत से काफी कम दाम पर उन्हीं कंपनियों को बेचने के लिए मजबूर होना पड़ता है
दुनिया भर की सरकारें नागरिकों की निगरानी के लिए ऐसी चीजें अरबों की संख्या में खरीद रही हैं, और Big Brother जबरदस्त economies of scale बना रहा है
computer vision के लिए low-cost Zynq जैसा लगता है
https://wiki.sipeed.com/hardware/en/tang/Tang-Nano-4K/Nano-4...
https://www.aliexpress.us/item/3256806880637138.html
S3 variant अपना थोड़ा extra cost पूरी तरह justify करता है, क्योंकि इसमें SIMD और FPU हैं, इसलिए यह आसानी से single-digit गुना तेज हो जाता है
https://github.com/espressif/esp-dl/tree/master/examples/fac...
human detection 54ms में—यह हैरान करने वाला है: https://github.com/espressif/esp-tflite-micro?tab=readme-ov-...
हम कई vendors के साथ सीधे काम करके dozens of microcontroller और CPU architectures, special accelerators (neuromorphic computing सहित), और edge GPUs पर deep learning, computer vision, और digital signal processing workloads को low-level पर optimize करते हैं
ESP32 भी शामिल है: https://docs.edgeimpulse.com/docs/edge-ai-hardware/mcu/espre...
TensorFlow, PyTorch, JAX models upload करें और laptop पर Python की कुछ lines से optimized C++ library तुरंत मिल जाती है—यह काफी कमाल है
model training के लिए Studio भी है, और embedded hardware की range पर अच्छी तरह चलने के लिए design की गई architectures तथा target device की latency और memory usage के हिसाब से best model खोजने वाली hardware-aware hyperparameter optimization भी देता है
Features from accelerated segment test: https://en.wikipedia.org/wiki/Features_from_accelerated_segm...
जानना चाहता हूं कि इस price range के chips में भी TPU जैसी functionality है या नहीं
Neon ARMv7 और ARMv8 का optional SIMD instruction extension है, इसलिए Pi Zero और उससे ऊपर में SIMD extension होता है
Orrin Nano 40 TOPS का है, इसलिए मेरी समझ में यह Copilot+ के लिए पर्याप्त स्तर का है। "A PCIe Coral TPU Finally Works on Raspberry Pi 5" https://news.ycombinator.com/item?id=38310063
https://phys.org/news/2024-06-infrared-visible-device-2d-mat... के अनुसार, infrared 1550nm wavelength को 622nm visible light में up-convert किया गया, और output light wave को मौजूदा silicon-based cameras से detect किया जा सकता है
यह process coherence बनाए रखता है, इसलिए कहा जाता है कि input infrared frequency में कोई खास pattern engrave करने पर वह नए output frequency में अपने-आप transfer हो जाता है
"Show HN: PicoVGA Library – VGA/TV Display on Raspberry Pi Pico" https://news.ycombinator.com/item?id=35117847#35120403
https://news.ycombinator.com/item?id=40275530
"Designing a SIMD Algorithm from Scratch" https://news.ycombinator.com/item?id=38450374
ESP32-S3 के SIMD instructions शायद quantized AI model inference को accelerate करने के लिए design किए गए हैं(https://github.com/espressif/esp-dl), और इसमें FFT जैसी signal processing भी शामिल है
ML inference में मदद करने वाले specific instructions होने के अर्थ में इसे TPU जैसा भी कहा जा सकता है। उदाहरण के लिए EE.VRELU.Sx ReLU operation करता है
लेकिन ऐसे instructions इस्तेमाल करने पर भी CPU time खर्च होता है, और आमतौर पर TPU एक अलग processing core के रूप में asynchronously काम करता है, इसलिए यह ARM NEON के ज्यादा करीब है
software और documentation काफी अच्छी थी, लेकिन अफसोस कि यह ज्यादा व्यापक रूप से नहीं फैला
आजकल RV1103("LuckFox"), BL808("Ox64/Pine64"), CV1800B/SG20002("MilkV") पर आधारित low-cost development boards आसानी से मिल जाते हैं, और सभी में basic TPU जैसा कुछ मौजूद है
हालांकि ये Linux boards के रूप में design किए गए हैं, इसलिए TPU से जुड़ी चीजें बेहद abstracted हैं और internal documentation लगभग न के बराबर है; इसलिए यह बिल्कुल unclear है कि यह असली TPU है या clever code optimization से की गई नकल
पहली नजर में MicroPython काफी approachable लगता है, लेकिन सोच रहा हूं कि उस code को WebAssembly में port करना कितना आसान होगा
device use case को https://micropython.org/unicorn/ पर आजमा सकते हैं
client-side development के लिए इसे PyScript में इस्तेमाल किया जा सकता है, और JavaScript/DOM bridge भी है
https://pyscript.net/tech-preview/micropython/about.html
ESP32 पर Rust का no-std भी अनुभव के हिसाब से बुरा नहीं है, लेकिन खासकर Wi-Fi/networking या camera जैसे components से जोड़ने वाले हिस्से अभी कम polished हैं
दूसरे comment की तरह, Rust में भी SIMD और assembly support पर्याप्त है
गहराई में जाने से पहले Rust embedded या Rust ESP32 chat room में पूछ लेना अच्छा रहेगा
ढेर सारा SIMD डालकर साथ में SMT-4 या SMT-8 इस्तेमाल करें तो threads latency को hide कर सकते हैं, जिससे performance per area बेहतर होने की संभावना है