0Pricing
CUDA Academy · درس

تشريح النواة

التوقيع ونوع الإرجاع وقاعدة void.

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

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

What a Kernel Is

A kernel is a single C++ function that runs on the GPU, executed at once by thousands of threads. You write it once, the hardware fans it out. 🚀

The __global__ Marker

You mark a kernel with the __global__ qualifier. It tells nvcc this function is called from the CPU but actually runs on the device.

__global__ void myKernel() {
    // runs on the GPU
}

Kernels Return void

Every kernel must return void. There is no return value to hand back, so results travel out through pointers to device memory instead.

__global__ void k() { /* void only */ }

Why Not Return a Value?

Thousands of threads run your kernel together, so a single return value would make no sense. Each thread writes its own slot of an output array.

Parameters Are by Value

Kernel parameters are copied to every thread, so pass small things: ints, sizes, and pointers. Never pass big objects by value.

__global__ void add(float* out, float* a, int n) {}

Pass Pointers, Not Arrays

To give a kernel an array, you pass a device pointer. The kernel reads and writes the GPU memory that pointer addresses.

__global__ void scale(float* data, float k) {}

Each Thread Picks Its Work

The same code runs in every thread, so each one uses its index to decide which element to touch. That is how one function covers a whole array.

int i = threadIdx.x; // who am I?

A Tiny Complete Kernel

Here is a full kernel: it doubles one element per thread. Notice the __global__ marker, the void return, and the pointer parameter all together.

__global__ void doubleIt(float* x) {
    int i = threadIdx.x;
    x[i] = x[i] * 2.0f;
}

Host Code Stays Separate

Your normal CPU function, often main, is host code. It sets things up and then asks the GPU to run the kernel.

int main() {
    // host side: prepare and launch
}

No Recursion or I/O Surprises

A kernel runs on hardware with tight rules, so keep it simple: avoid deep recursion and heavy standard-library calls inside it.

Naming Your Kernels

Treat a kernel like any function: give it a clear, verb-based name like vectorAdd. Good names make launches far easier to read.

__global__ void vectorAdd(float* c, float* a, float* b);

Quick Check

Let us check the kernel signature rules.

Recap: Kernel Anatomy

A kernel is a __global__ void function run by many threads. Pass pointers and small values, and let each thread use its index. Nicely done! 🎉

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

هل درس «تشريح النواة» مجاني؟

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

ماذا ستتعلم في «تشريح النواة»؟

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

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

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

كم من الوقت يستغرق درس «تشريح النواة»؟

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

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

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

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

  1. تشريح النواة
  2. التشغيل بأقواس الزوايا الثلاثية
  3. استخدام printf داخل النواة
  4. شرح cudaDeviceSynchronize
← العودة إلى CUDA Academy