0Pricing
Mojo Academy · درس

نقل البيانات من الجهاز وإليه

أدر عمليات نقل الذاكرة بين المضيف والجهاز

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

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

Two Separate Memories

The CPU and GPU each have their own memory. The GPU cannot read your host arrays until the data lives on the device.

Host and Device

We call the CPU side the host and the GPU side the device. Moving data between them is a core part of GPU work.

Allocating on the Device

First you reserve space on the GPU for your data. This device buffer is where inputs and outputs will live.

var d_a = ctx.enqueue_create_buffer[DType.float32](n)

Copying Inputs Over

Next you copy your host arrays into those device buffers. This upload gets the GPU the numbers it needs.

ctx.enqueue_copy(d_a, h_a)

Running the Kernel

With data on the device, you launch the kernel. It reads and writes the device buffers, never the host ones.

ctx.enqueue_function[kernel](grid_dim=blocks, block_dim=256)

Copying Results Back

The output sits on the GPU until you fetch it. A download copies the result buffer back into host memory.

ctx.enqueue_copy(h_out, d_out)

Work Is Queued, Not Instant

These calls are enqueued on the GPU, not finished at once. You must synchronize before trusting the results on the host.

ctx.synchronize()

The Round Trip

The full cycle is upload, compute, download. Picture data making a round trip from host to device and back.

Transfers Cost Time

Copying over the bus is slow compared to compute. Each transfer can erase your speedup if you do it too often.

Keep Data on the Device

Chain several kernels on the same buffers before copying back. Minimizing round trips keeps the GPU win intact.

Free What You Allocate

Device memory is limited, so release buffers you no longer need. Mojo's ownership rules help free them at the right time.

Quick Check

You want a GPU program to actually run faster end to end.

Recap

Upload inputs to the device, run the kernel, then download results and synchronize, while keeping costly transfers to a minimum. 🔁

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

هل درس «نقل البيانات من الجهاز وإليه» مجاني؟

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

ماذا ستتعلم في «نقل البيانات من الجهاز وإليه»؟

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

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

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

كم من الوقت يستغرق درس «نقل البيانات من الجهاز وإليه»؟

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

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

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

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

  1. لماذا نستخدم GPU لأعباء الذكاء الاصطناعي
  2. الخيوط والكتل والشبكات
  3. كتابة دالة نواة GPU
  4. نقل البيانات من الجهاز وإليه
← العودة إلى Mojo Academy