0Pricing
CUDA Academy · درس

مؤهّل الدالة __global__

حدّد الدالة بوصفها نواة GPU.

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

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

Two Worlds, Two Compilers

Your CUDA file holds both CPU and GPU code. A tiny keyword tells the compiler which side a function belongs to. That keyword is the function qualifier. ⚡

Meet __global__

The __global__ qualifier marks a function as a GPU kernel: code the CPU launches but the GPU actually runs across many threads.

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

Called Here, Runs There

A __global__ function is the only kind the host can call but the device executes. It is the bridge between your two worlds.

Always Returns void

A kernel must return void. It cannot hand a value back to the CPU, so results travel out through memory instead.

__global__ void addOne(int* data) {
    data[0] += 1;
}

Launching Is Asynchronous

When you launch a __global__ kernel, the CPU does not wait. The call returns instantly while the GPU works in the background. 🚀

Many Threads, One Function

One __global__ definition runs on thousands of threads at once. You write the body once; the GPU clones the work across cores.

The Launch Syntax

Calling a kernel needs special triple angle brackets that set how many threads run. Normal parentheses alone will not do.

myKernel<<<1, 256>>>();

Parameters by Value

Kernel arguments are copied to the device. Pass device pointers for arrays, since a host pointer would be meaningless on the GPU.

Not the Same as __device__

Do not confuse them: __global__ is a launchable entry point, while __device__ functions are helpers callable only from GPU code.

No Recursion at the Entry

A __global__ kernel cannot call itself directly the way host functions do. Classic recursion belongs to device helper functions instead.

Why It Matters

Mastering __global__ unlocks everything ahead: every kernel you write, launch, and tune starts with this one little keyword.

Quick Check

Let us check your grasp of the __global__ qualifier.

Recap

You learned that __global__ marks a GPU kernel: called by the host, run by the device, returns void, and launched with triple angle brackets. 🎉

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

هل درس «مؤهّل الدالة __global__» مجاني؟

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

ماذا ستتعلم في «مؤهّل الدالة __global__»؟

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

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

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

كم من الوقت يستغرق درس «مؤهّل الدالة __global__»؟

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

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

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

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

  1. مؤهّل الدالة __global__
  2. دوال __device__ و__host__
  3. مساحات عناوين منفصلة
  4. دورة حياة برنامج CUDA
← العودة إلى CUDA Academy