0Pricing
CUDA Academy · Lesson

Hints via cudaMemAdvise

Guiding the driver's placement choices.

Hints via cudaMemAdvise is a free CUDA Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Advise, Do Not Command

Prefetch moves data now; cudaMemAdvise instead tells the driver how you plan to use a region so it can place pages smartly over time.

The Call Shape

You pass the pointer, byte count, an advice flag, and a device id. The driver folds that hint into its future migration decisions.

cudaMemAdvise(data, bytes, advice, device);

ReadMostly for Sharing

Use cudaMemAdviseSetReadMostly for data many devices read but rarely write. The driver can keep read-only copies on each side to avoid migration.

cudaMemAdvise(data, bytes,
  cudaMemAdviseSetReadMostly, dev);

PreferredLocation Pins a Home

With cudaMemAdviseSetPreferredLocation you nominate a home device for the pages. They resist drifting away even when another side touches them.

cudaMemAdvise(data, bytes,
  cudaMemAdviseSetPreferredLocation, dev);

AccessedBy Skips Migration

cudaMemAdviseSetAccessedBy says a device will reach this region, so the driver maps it there. Access goes over the bus instead of moving pages.

cudaMemAdvise(data, bytes,
  cudaMemAdviseSetAccessedBy, dev);

Hints Stop Ping-Pong

When two devices fight over the same pages, the right advice ends the bounce. You stabilize placement so data stops migrating back and forth.

Advice Is Persistent

Unlike a one-shot prefetch, advice persists on the region until you change it. It shapes every migration choice for the life of the buffer.

Each Advice Has an Unset

Every Set flag has a matching Unset form to revoke the hint. Clear advice when an access pattern changes so it does not mislead the driver.

cudaMemAdvise(data, bytes,
  cudaMemAdviseUnsetReadMostly, dev);

Advise Plus Prefetch

The two tools pair well. Set PreferredLocation to define the home, then prefetch to fill it, and migrations settle into a steady pattern.

Just a Hint, After All

Remember the name: advice is a suggestion, not a guarantee. The driver may override it, so always profile to confirm the placement helped.

Your Unified Memory Toolkit

You now hold three levers: one managed pointer, prefetch for timing, and advise for placement. Together they make Unified Memory both easy and fast.

Quick Check

Let us confirm how cudaMemAdvise differs from prefetching.

Recap: Memory Advice

You learned cudaMemAdvise hints like ReadMostly, PreferredLocation, and AccessedBy to guide page placement. Pair it with prefetch and profile. Well done! 🎯

Frequently asked questions

Is the “Hints via cudaMemAdvise” lesson free?

Yes — the full text of “Hints via cudaMemAdvise” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.

What will I learn in “Hints via cudaMemAdvise”?

Guiding the driver's placement choices. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CUDA Academy?

No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Hints via cudaMemAdvise” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CUDA Academy lesson?

Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. One Pointer, Both Sides
  2. On-Demand Page Migration
  3. Prefetching with cudaMemPrefetchAsync
  4. Hints via cudaMemAdvise
← Back to CUDA Academy