0Pricing
Mojo Academy · درس

اختيار عرض SIMD

طابق العرض مع مسارات العتاد

اختيار عرض SIMD درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Width Decides Throughput

The SIMD width is how many lanes you process per instruction. Picking it well is key to real performance.

Hardware Has Fixed Lanes

Your CPU has vector registers of a fixed size. A good SIMD width matches the lanes that hardware can run at once.

Too Narrow Wastes Power

A width of 1 ignores the CPU's vector units entirely. You leave most of the chip's throughput sitting idle.

var slow = SIMD[DType.float32, 1](2.0)

Too Wide Spills Over

If a width is larger than the hardware supports, Mojo splits it into smaller chunks. That still works but adds overhead.

Let Mojo Tell You

Mojo can report the ideal width for a type on this machine through simdwidthof, so you do not have to guess.

from sys import simdwidthof
alias w = simdwidthof[DType.float32]()

Use It as a Parameter

Because simdwidthof is known at compile time, you can feed it straight into a SIMD type as its width.

alias Vec = SIMD[DType.float32, simdwidthof[DType.float32]()]

Width Depends on DType

Smaller elements fit more lanes in the same register. So float32 usually gets a bigger native width than float64.

Portable by Design

Using simdwidthof means your code adapts to each machine automatically. The same source stays fast and portable.

Multiples of Width Are Easy

Data that comes in clean multiples of your width vectorizes neatly, with no leftover lanes to handle as a remainder.

Mind the Leftovers

When a count is not a multiple of the width, a few tail elements remain. You finish those with a small scalar step.

Start with the Native Width

A safe default is simdwidthof for your DType. Measure later, but the native width is almost always a strong start.

Quick Check

You want a SIMD width that fits this CPU's float32 lanes without hardcoding a guess. What helps?

Recap

Match the SIMD width to the hardware: simdwidthof gives the native lane count per DType, and a scalar tail cleans up leftover elements. 🎯

الأسئلة الشائعة

هل درس «اختيار عرض SIMD» مجاني؟

نعم — نص درس «اختيار عرض SIMD» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «اختيار عرض SIMD»؟

طابق العرض مع مسارات العتاد تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «اختيار عرض SIMD»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. التعرّف على نوع SIMD
  2. حساب SIMD عنصرًا بعنصر
  3. اختيار عرض SIMD
  4. توجيه حلقة باستخدام المتجهات
← العودة إلى Mojo Academy