0Pricing
CUDA Academy · Ders

__device__ ve __host__ İşlevleri

Her işlev türünün nerede çalışabileceğini öğrenin.

__device__ ve __host__ İşlevleri, CoddyKit'te ücretsiz bir CUDA Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, CUDA Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. CUDA Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Beyond the Kernel

Kernels are entry points, but most code lives in helpers. CUDA gives two more qualifiers to say where a plain function may run. Let us meet them.

The __device__ Qualifier

A __device__ function runs on the GPU and is callable only from other GPU code, like a kernel or another device function.

__device__ int square(int x) {
    return x * x;
}

Helpers for Kernels

Think of __device__ functions as your GPU toolbox. They keep kernels tidy by holding logic the device threads reuse.

The __host__ Qualifier

The __host__ qualifier means ordinary CPU code. It is the default, so plain C++ functions are already host functions.

__host__ void setup() {
    // runs on the CPU
}

Default Is Host

Leave off all qualifiers and your function is host-only by default. That is why normal C++ still compiles inside a .cu file.

Both at Once

Combine the two and a function compiles for both sides. nvcc builds one version for the CPU and one for the GPU.

__host__ __device__ int dbl(int x) {
    return x + x;
}

Why Dual-Compile?

Marking a helper __host__ __device__ lets the same math run in CPU reference code and inside kernels, with zero duplication. ✨

Calling Rules

Host code may not call a __device__ function, and device code may not call a host-only one. The compiler enforces the boundary.

No __global__ from Device

A __device__ function is not launchable. Only __global__ kernels accept the triple-angle-bracket launch from the host.

Inlining for Speed

The compiler often inlines small __device__ functions, so wrapping logic in helpers usually costs nothing at runtime.

Pick the Right Tag

Choose by where it runs: __device__ for GPU helpers, __host__ for CPU code, and both when the logic is shared.

Quick Check

Time to test the device and host qualifiers.

Recap

You learned __device__ runs on the GPU, __host__ runs on the CPU, the default is host, and combining both shares one function across worlds. 🎯

Sıkça Sorulan Sorular

“__device__ ve __host__ İşlevleri” dersi ücretsiz mi?

Evet — “__device__ ve __host__ İşlevleri” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve CUDA Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. CUDA Academy kursu toplamda 4 dersten oluşur.

“__device__ ve __host__ İşlevleri” dersinde ne öğreneceğim?

Her işlev türünün nerede çalışabileceğini öğrenin. CUDA Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

CUDA Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te CUDA Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“__device__ ve __host__ İşlevleri” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu CUDA Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her CUDA Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. __global__ İşlev Belirteci
  2. __device__ ve __host__ İşlevleri
  3. Ayrı Adres Alanları
  4. Bir CUDA Programının Yaşam Döngüsü
← CUDA Academy Sayfasına Dön