التشغيل بأقواس الزوايا الثلاثية
استدعِ نواة باستخدام >>.
التشغيل بأقواس الزوايا الثلاثية درس مجاني في CUDA Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في CUDA Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة CUDA Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Launching Is Different
You do not call a kernel like a normal function. You launch it, telling the GPU how many threads to spin up at the same time. 🚀
The <<< >>> Syntax
The launch uses CUDA's special triple angle brackets. Inside them you give a launch configuration before the normal argument list.
myKernel<<<blocks, threads>>>(args);First Number: Blocks
The first value sets how many blocks launch. A block is a group of threads that run together and share fast on-chip memory.
myKernel<<<4, threads>>>(args); // 4 blocksSecond Number: Threads per Block
The second value sets threads per block. Total threads launched equals blocks times threads per block.
myKernel<<<4, 256>>>(args); // 1024 threadsArguments Come After
After the brackets, you pass the kernel's normal arguments in parentheses, just like any C++ call.
doubleIt<<<1, 256>>>(devicePtr);Launches Are Asynchronous
A launch is asynchronous: the CPU queues the work and keeps going immediately. The GPU runs the kernel in the background.
Configs Can Be Variables
The launch numbers do not have to be literals. You often compute the block count from your data size at runtime.
int blocks = (n + 255) / 256;
add<<<blocks, 256>>>(c, a, b, n);Using dim3 for 2D
For grids and blocks in 2D or 3D, you use a dim3 value. It bundles x, y, and z sizes into the launch.
dim3 threads(16, 16);
blur<<<grid, threads>>>(img);Picking Threads per Block
A safe default for threads per block is 128 or 256. Values must be multiples of 32 and stay at or below 1024.
kernel<<<blocks, 128>>>(data);A Bad Config Fails
If you ask for too many threads per block, the launch fails silently. You must check for errors right after launching.
kernel<<<1, 2048>>>(p); // too big, failsRead It Left to Right
Read a launch as: run this kernel across this many blocks of this many threads, with these arguments. Simple once it clicks.
vectorAdd<<<grid, block>>>(c, a, b, n);Quick Check
Time to check the launch configuration.
Recap: The Launch
You launch with kernel<<
الأسئلة الشائعة
هل درس «التشغيل بأقواس الزوايا الثلاثية» مجاني؟
نعم — نص درس «التشغيل بأقواس الزوايا الثلاثية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة CUDA Academy، انتقل إلى CoddyKit PRO. تتضمن دورة CUDA Academy 4 دروس في المجموع.
ماذا ستتعلم في «التشغيل بأقواس الزوايا الثلاثية»؟
استدعِ نواة باستخدام >>. تتمرن على CUDA Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ CUDA Academy؟
لا تُشترط خبرة سابقة. CUDA Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «التشغيل بأقواس الزوايا الثلاثية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس CUDA Academy هذا؟
نعم. كل درس في CUDA Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تشريح النواة
- التشغيل بأقواس الزوايا الثلاثية
- استخدام printf داخل النواة
- شرح cudaDeviceSynchronize