0Pricing
CUDA Academy · درس

تعداد اتجاه النسخ

استخدم cudaMemcpyKind بشكل صحيح.

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

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

The Fourth Argument

Every cudaMemcpy ends with a direction flag of type cudaMemcpyKind. It tells the runtime which way the bytes travel. 🧭

cudaMemcpy(dst, src, bytes, kind);

Host to Device

Use cudaMemcpyHostToDevice to upload inputs from CPU RAM into GPU memory before a kernel runs.

cudaMemcpy(d_a, h_a, bytes, cudaMemcpyHostToDevice);

Device to Host

Use cudaMemcpyDeviceToHost to download results from GPU memory back into CPU RAM after computing.

cudaMemcpy(h_c, d_c, bytes, cudaMemcpyDeviceToHost);

Device to Device

To copy between two GPU buffers without touching the CPU, reach for cudaMemcpyDeviceToDevice.

cudaMemcpy(d_b, d_a, bytes, cudaMemcpyDeviceToDevice);

Host to Host

There is even cudaMemcpyHostToHost, a plain CPU copy. You rarely need it since standard memcpy already does the job.

Let the Driver Decide

With cudaMemcpyDefault, the runtime infers direction from the pointers. It needs unified addressing to work safely.

cudaMemcpy(dst, src, bytes, cudaMemcpyDefault);

The Direction Must Match

The flag must agree with your real pointers. A device pointer with a HostToHost kind triggers an error or a crash.

A Common Mix-Up

Swapping HostToDevice and DeviceToHost is a frequent bug. The compiler stays silent, so read each call carefully. 🐛

Read It Like a Sentence

The enum name spells the data flow: HostToDevice means from host to device. Match it to your source and destination.

Pair It With the Pointers

Look at which buffer is the source and which is the destination, then pick the kind that names that exact path.

When in Doubt, Be Explicit

Prefer the named direction over cudaMemcpyDefault. Being explicit makes your intent obvious and catches mistakes sooner.

Quick Check

You are copying one device buffer into another device buffer, never touching the CPU. Which kind fits?

Recap

You met every cudaMemcpyKind: HostToDevice, DeviceToHost, DeviceToDevice, HostToHost, and Default. Match the flag to your pointers every time. 🎉

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

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

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

ماذا ستتعلم في «تعداد اتجاه النسخ»؟

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

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

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

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

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

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

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

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

  1. النقل من المضيف إلى الجهاز
  2. النقل من الجهاز إلى المضيف
  3. تعداد اتجاه النسخ
  4. عنق زجاجة النقل عبر PCIe
← العودة إلى CUDA Academy