0Pricing
CUDA Academy · درس

إنشاء Streams واستخدامها

أصدر مهام مستقلة إلى قوائم انتظار متعددة.

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

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

Independent Work Queues

A non-default stream is your own work queue. Two streams run independently, so the GPU can make progress on both at once. 🧵

The Stream Handle

A stream lives in a cudaStream_t handle. You create it once, pass it to your calls, and destroy it when you are done.

cudaStream_t stream;

Creating a Stream

Call cudaStreamCreate to make a fresh stream. It allocates the queue the driver uses to schedule that stream's work.

cudaStreamCreate(&stream);

Launching a Kernel in a Stream

A kernel's launch config has a fourth argument: shared memory size, then the stream. Pass your stream to queue the kernel there.

kernel<<<grid, block, 0, stream>>>(d_data);

Two Streams, Two Tasks

Put one job on streamA and another on streamB. With no dependency between them, the GPU is free to run both concurrently.

kA<<<g, b, 0, streamA>>>(a);
kB<<<g, b, 0, streamB>>>(d);

Async by Nature

Stream calls are asynchronous: the host returns immediately and keeps going. The GPU works through the queue on its own time.

Waiting on One Stream

Use cudaStreamSynchronize to block the host until just that stream finishes, instead of waiting on the whole device.

cudaStreamSynchronize(stream);

Checking Without Blocking

Want a peek? cudaStreamQuery returns cudaSuccess if the stream is done and cudaErrorNotReady if it is still busy, without stalling you.

cudaStreamQuery(stream);

Cleaning Up

When a stream is no longer needed, release it with cudaStreamDestroy. Pending work still completes before the handle is freed.

cudaStreamDestroy(stream);

Non-Blocking Streams

Create a stream with the cudaStreamNonBlocking flag so it does not implicitly synchronize with the legacy default stream.

cudaStreamCreateWithFlags(&s, cudaStreamNonBlocking);

More Streams, More Overlap

Spreading independent chunks over several streams lets the scheduler keep the engines fed. Beyond a few, returns diminish as hardware fills up.

Quick Check

How do you queue a kernel into a specific stream?

Recap

You can now create streams, launch kernels in them, sync or query, and destroy them. Independent streams unlock real concurrency. ✨

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

هل درس «إنشاء Streams واستخدامها» مجاني؟

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

ماذا ستتعلم في «إنشاء Streams واستخدامها»؟

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

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

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

كم من الوقت يستغرق درس «إنشاء Streams واستخدامها»؟

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

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

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

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

  1. مأزق Default Stream
  2. إنشاء Streams واستخدامها
  3. الأحداث لقياس الوقت والمزامنة
  4. تداخل النسخ والحساب
← العودة إلى CUDA Academy