0Pricing
CUDA Academy · درس

الجلب المسبق باستخدام cudaMemPrefetchAsync

انقل الصفحات قبل الحاجة إليها.

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

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

Stop Paying for Faults

Instead of waiting for slow first-touch faults, you can move pages early. cudaMemPrefetchAsync sends managed data to a device before the kernel needs it.

The Basic Call

You name the pointer, the byte count, and the destination device. This one prefetch migrates the whole range up front in a single efficient move.

cudaMemPrefetchAsync(data, n * sizeof(float), 0);

Pick the Destination

The third argument is the device id. Pass a GPU number to stage data on that GPU, ready for the kernel you are about to launch.

int dev = 0;
cudaMemPrefetchAsync(data, bytes, dev);

Prefetch Back to the CPU

Use the special id cudaCpuDeviceId to pull results back to the host. Do it before CPU code reads them to avoid a wave of faults.

cudaMemPrefetchAsync(data, bytes, cudaCpuDeviceId);

It Is Asynchronous

The Async in the name is real: the call returns immediately and runs in a stream. Your CPU keeps working while pages migrate in the background.

Overlap With Compute

Because it rides a stream, a prefetch can overlap with other kernels. Stage the next chunk while the current one is still being processed.

cudaMemPrefetchAsync(next, bytes, dev, stream);

One Move Beats Many Faults

A single bulk prefetch is far cheaper than thousands of tiny faults. You trade scattered overhead for one contiguous high-bandwidth transfer.

Prefetch the Right Range

Only stage what the kernel actually touches. Prefetching a huge buffer the kernel barely reads just wastes bandwidth and GPU memory.

A Two-Sided Pattern

A clean rhythm emerges: prefetch to the GPU, launch the kernel, prefetch results back. This keeps migration off the critical path on both ends.

Measure, Do Not Guess

Add a prefetch, then check Nsight for fewer faults and tighter timelines. Let profiling confirm the win rather than trusting intuition.

Convenience Plus Control

Prefetching keeps the single-pointer ease of managed memory while giving you back control over timing. You get the best of both styles.

Quick Check

Let us confirm what prefetching buys you.

Recap: Prefetching

You learned to stage pages early with cudaMemPrefetchAsync, picking a GPU or cudaCpuDeviceId. It overlaps in streams and beats faulting. Great job! ✨

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

هل درس «الجلب المسبق باستخدام cudaMemPrefetchAsync» مجاني؟

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

ماذا ستتعلم في «الجلب المسبق باستخدام cudaMemPrefetchAsync»؟

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

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

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

كم من الوقت يستغرق درس «الجلب المسبق باستخدام cudaMemPrefetchAsync»؟

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

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

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

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

  1. مؤشر واحد على الجانبين
  2. ترحيل الصفحات عند الطلب
  3. الجلب المسبق باستخدام cudaMemPrefetchAsync
  4. التلميحات عبر cudaMemAdvise
← العودة إلى CUDA Academy