تصميم مسار المعالجة
المراحل والمخازن المؤقتة وتدفق البيانات
تصميم مسار المعالجة درس مجاني في CUDA Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في CUDA Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة CUDA Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Think in Stages
A real image pipeline is a chain of stages: load, blur, sharpen, color-correct, save. Each stage is one clear transformation you can reason about alone. 🧩
Data Flows One Way
Pixels move forward through the pipeline: each stage reads the previous output and produces the next input. This one-way data flow keeps the design simple to follow.
Buffers Hold the In-Between
Between two stages you need a place to park pixels. A buffer is just a device array that one kernel writes and the next kernel reads. Plan a buffer per boundary.
float* d_stage1;
cudaMalloc(&d_stage1, width * height * sizeof(float));Ping-Pong Two Buffers
You rarely need a fresh buffer per stage. Ping-pong between two buffers: read from one, write to the other, then swap. Two buffers serve a whole chain.
std::swap(d_in, d_out);One Kernel Per Stage, For Now
Start with one kernel per stage. It is the clearest design and the easiest to verify. You will fuse stages later once each one is correct.
Map Pixels to Threads
The natural mapping is one thread per pixel. A 2D grid covers width and height, so each thread owns exactly one (x, y) location to process.
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;Index With Row Pitch
Images are stored row by row. Turn (x, y) into a flat offset with row-major indexing so every thread reads the right pixel.
int idx = y * width + x;Guard the Image Borders
Your grid is rounded up, so some threads fall outside the image. A simple bounds check keeps them from touching memory they should not.
if (x >= width || y >= height) return;Choose a 2D Block Shape
A block like 16x16 or 32x8 gives good coverage and warp-friendly rows. Pick a 2D block shape that divides the image cleanly when you can.
dim3 block(16, 16);
dim3 grid((width+15)/16, (height+15)/16);Allocate Once, Reuse Often
Allocating device memory is costly, so do it once before the loop. Reuse the same buffers for every frame instead of malloc and free each time.
Sketch Before You Code
Draw the stages, their buffers, and the arrows between them first. A clear diagram of data flow catches design mistakes long before any kernel runs. ✏️
Quick Check
You have a chain of stages. How do you avoid allocating a new buffer for every stage?
Recap
You designed a pipeline as one-way stages joined by buffers, mapped one thread per pixel with a 2D grid, and learned to ping-pong buffers and sketch the flow first. 🎯
الأسئلة الشائعة
هل درس «تصميم مسار المعالجة» مجاني؟
نعم — نص درس «تصميم مسار المعالجة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة CUDA Academy، انتقل إلى CoddyKit PRO. تتضمن دورة CUDA Academy 4 دروس في المجموع.
ماذا ستتعلم في «تصميم مسار المعالجة»؟
المراحل والمخازن المؤقتة وتدفق البيانات تتمرن على CUDA Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ CUDA Academy؟
لا تُشترط خبرة سابقة. CUDA Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «تصميم مسار المعالجة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس CUDA Academy هذا؟
نعم. كل درس في CUDA Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تصميم مسار المعالجة
- دمج المرشحات في نواة واحدة
- بث البلاطات للصور الكبيرة
- حلّل، حسّن، ثم أطلق