الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها
وزّع القيم للقراءة فقط بكلفة منخفضة.
الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها درس مجاني في CUDA Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في CUDA Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة CUDA Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
A Space for Read-Only Values
Constant memory is a small region built for data that every thread reads but none of them ever writes during a kernel.
Declaring It
You mark a global-scope array with the __constant__ qualifier. It lives outside any function, visible to all your kernels.
__constant__ float weights[256];It Is Genuinely Small
Total constant memory is only 64 KB on typical GPUs. It is meant for coefficients and parameters, not for large datasets.
Filling It from the Host
You write to constant memory from the CPU using cudaMemcpyToSymbol, since kernels themselves cannot modify it.
cudaMemcpyToSymbol(weights, h_w,
256 * sizeof(float));Backed by a Special Cache
Reads flow through a dedicated constant cache on each multiprocessor. A cached value comes back almost as fast as a register.
The Broadcast Superpower
When a whole warp reads the same address, the hardware does one fetch and broadcasts it to all 32 threads in a single step. 📡
Same Address Is the Key
The win depends on uniform access. If threads in a warp read different constant addresses, those reads serialize and the speedup is lost.
Reading It Looks Normal
Inside a kernel you read constant memory like any array. The compiler quietly routes the access through the fast constant cache.
__global__ void k(float *out, int i) {
out[i] = weights[0] * 2.0f;
}A Perfect Fit for Filters
Convolution kernels and lookup tables shine here, because every thread reuses the same small set of coefficients over and over.
Set Once, Reuse Often
You typically upload to constant memory a single time, then launch many kernels that all read those unchanging values cheaply.
When Not to Use It
Skip constant memory if your data is large or if threads read scattered addresses. In those cases plain global memory serves you better.
Quick Check
When does constant memory give its biggest speedup?
Recap: Small, Cached, Broadcast
You learned constant memory is a tiny read-only space whose cache broadcasts uniform reads to a whole warp. Use it for small, shared values. ✨
الأسئلة الشائعة
هل درس «الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها» مجاني؟
نعم — نص درس «الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة CUDA Academy، انتقل إلى CoddyKit PRO. تتضمن دورة CUDA Academy 4 دروس في المجموع.
ماذا ستتعلم في «الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها»؟
وزّع القيم للقراءة فقط بكلفة منخفضة. تتمرن على CUDA Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ CUDA Academy؟
لا تُشترط خبرة سابقة. CUDA Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس CUDA Academy هذا؟
نعم. كل درس في CUDA Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- السجلات والذاكرة المحلية
- مقايضات الذاكرة العامة
- الذاكرة الثابتة وذاكرة التخزين المؤقت الخاصة بها
- نموذج ذهني للهرمية