الترجمة باستخدام nvcc
تعرّف على كيفية فصل nvcc بين كود المضيف وكود الجهاز.
الترجمة باستخدام nvcc درس مجاني في CUDA Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في CUDA Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة CUDA Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Meet nvcc
The CUDA compiler is called nvcc. It takes your .cu file with mixed CPU and GPU code and turns it into one runnable program. 🛠️
Two Kinds of Code
A .cu file holds two worlds: host code that runs on the CPU and device code that runs on the GPU. nvcc must handle each one differently.
The Great Split
nvcc splits your source automatically. It hands the host portions to your normal C++ compiler and keeps the device portions for itself.
Compiling Device Code
For the GPU side, nvcc generates a special assembly called PTX, then turns it into machine code your specific GPU can execute.
The Host Compiler
nvcc does not compile CPU code itself. It quietly calls your system's host compiler, like g++ or clang, to handle the ordinary C++.
Your First Build Command
Compiling looks just like g++. Point nvcc at your .cu file and name the output with the -o flag.
nvcc hello.cu -o helloTargeting an Architecture
The -arch flag tells nvcc which GPU generation to build for. Matching it to your card produces faster, fully optimized device code.
nvcc -arch=sm_80 hello.cu -o helloCompute Capability
That sm number is a compute capability, a label for a GPU's feature set. sm_80 means an Ampere card; older cards use smaller numbers.
Fatbins for Many GPUs
nvcc can pack code for several architectures into one fatbinary, so the same executable runs well on different GPUs without rebuilding.
Familiar Optimization Flags
Many g++ habits carry over. nvcc accepts -O levels and -g for debugging, passing them along to the right compiler stage.
nvcc -O3 hello.cu -o helloLinking CUDA Libraries
Need a tuned library like cuBLAS? You link it just as in g++, adding the library name with an -l flag on the nvcc command.
nvcc app.cu -lcublas -o appQuick Check
Let us check how nvcc divides the work.
Recap
You learned that nvcc splits a .cu file, compiles device code to GPU machine code, and hands host code to g++. The -arch flag targets your card. 🎯
الأسئلة الشائعة
هل درس «الترجمة باستخدام nvcc» مجاني؟
نعم — نص درس «الترجمة باستخدام nvcc» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة CUDA Academy، انتقل إلى CoddyKit PRO. تتضمن دورة CUDA Academy 4 دروس في المجموع.
ماذا ستتعلم في «الترجمة باستخدام nvcc»؟
تعرّف على كيفية فصل nvcc بين كود المضيف وكود الجهاز. تتمرن على CUDA Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ CUDA Academy؟
لا تُشترط خبرة سابقة. CUDA Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «الترجمة باستخدام nvcc»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس CUDA Academy هذا؟
نعم. كل درس في CUDA Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إصدارات Driver وRuntime وToolkit
- قراءة nvidia-smi باحتراف
- الترجمة باستخدام nvcc
- مرحبًا بـ GPU: أول ملف .cu لك