0Pricing
CUDA Academy · Ders

atomicAdd ve Benzerleri

Donanımsal oku-değiştir-yaz işlemleri.

atomicAdd ve Benzerleri, 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.

One Indivisible Step

An atomic operation reads, modifies, and writes a value as a single step that no other thread can interrupt. That kills the race. ⚛️

Meet atomicAdd

atomicAdd takes a pointer and a value, adds safely, and returns the old value. Many threads can hit the same address with no lost updates.

atomicAdd(total, 1);

Fixing the Racy Counter

Swap the plain increment for atomicAdd and the count becomes correct every single time, no matter how many threads run.

__global__ void count(int* total) {
    atomicAdd(total, 1);
}

The Return Value Is Useful

atomicAdd returns the value held before your add. That old value is a unique slot you can use as an index or a ticket number.

int slot = atomicAdd(counter, 1);

A Whole Family

atomicAdd has many friends: atomicSub, atomicMax, atomicMin, atomicExch, atomicAnd, atomicOr, and atomicXor all work the same atomic way.

Swapping a Value

atomicExch stores a new value and returns the old one in one step. It is handy for claiming flags or grabbing a previous state safely.

int prev = atomicExch(flag, 1);

Atomic Max and Min

atomicMax updates the target only if your value is larger. It is perfect for finding a global maximum across all threads without races.

atomicMax(best, myValue);

Supported Types

Atomics cover int, unsigned, and on newer hardware float and double too. Always check that your type and arch support the call you want.

Atomics Have a Cost

Atomics serialize threads that target the same address. Heavy contention on one spot becomes a bottleneck, so use them only where needed.

Spread the Load

Reduce contention by having threads update different addresses, then combine results. Fewer collisions means atomics stay fast.

Atomics vs Reductions

For summing huge arrays, a tree reduction often beats a flood of atomics. Reach for atomics when updates are sparse or irregular.

Quick Check

Test your grip on atomicAdd's behavior.

Recap: atomicAdd and Friends

You met the atomic family, fixed the racy counter, and learned atomics return the old value but cost time under contention. ✅

Sıkça Sorulan Sorular

“atomicAdd ve Benzerleri” dersi ücretsiz mi?

Evet — “atomicAdd ve Benzerleri” 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.

“atomicAdd ve Benzerleri” dersinde ne öğreneceğim?

Donanımsal oku-değiştir-yaz işlemleri. 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.

“atomicAdd ve Benzerleri” 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. GPU'da Yarış Koşulları
  2. atomicAdd ve Benzerleri
  3. Histogram Oluşturma
  4. atomicCAS ile Özel Atomik İşlemler
← CUDA Academy Sayfasına Dön