Skip to content

Commit 3a335eb

Browse files
committed
Tutorials/CUDA C++: Fix module 01-02 builds with CUDA 13.
CUDA 13 removed cudaDeviceProp::memoryClockRate, which every module 01-02 ach.h uses in max_bandwidth(), so every exercise in those modules fails to compile in the current tutorial image (CUDA 13.1) and on Google Colab. Query the clock with cudaDeviceGetAttribute(cudaDevAttrMemoryClockRate) instead. Module 02 additionally fails because `cuda::std::mdspan temp_in(ptr, h, w)` deduces dextents<size_t, 2>, while ach::compute() takes dextents<int, 2>. size_t -> int is potentially narrowing, so the standard makes that conversion explicit, which CUDA 13's libcu++ enforces. Take cuda::std::dims<2> (dextents<size_t, 2>) instead, so the existing call sites, including the notebook cells, compile unchanged. Tested in ghcr.io/nvidia/cuda-cpp-tutorial:latest (CUDA 13.1) on an RTX PRO 6000: all module 01-03 Sources/Solutions files and notebook %%writefile cells build (exercise starters excepted), and every solution runs successfully.
1 parent d640cf4 commit 3a335eb

15 files changed

Lines changed: 51 additions & 21 deletions

File tree

  • tutorials/cuda-cpp/notebooks

‎tutorials/cuda-cpp/notebooks/01.02-Execution-Spaces/Solutions/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ static double max_bandwidth() {
3333
cudaDeviceProp prop;
3434
cudaGetDeviceProperties(&prop, 0);
3535

36+
int mem_clock_khz = 0;
37+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
3638
const std::size_t mem_freq =
37-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
39+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
3840
const int bus_width = prop.memoryBusWidth;
3941
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4042
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.02-Execution-Spaces/Sources/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ static double max_bandwidth() {
3333
cudaDeviceProp prop;
3434
cudaGetDeviceProperties(&prop, 0);
3535

36+
int mem_clock_khz = 0;
37+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
3638
const std::size_t mem_freq =
37-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
39+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
3840
const int bus_width = prop.memoryBusWidth;
3941
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4042
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.03-Extending-Algorithms/Solutions/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ static double max_bandwidth() {
3737
cudaDeviceProp prop;
3838
cudaGetDeviceProperties(&prop, 0);
3939

40+
int mem_clock_khz = 0;
41+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4042
const std::size_t mem_freq =
41-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
43+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4244
const int bus_width = prop.memoryBusWidth;
4345
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4446
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.03-Extending-Algorithms/Sources/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ static double max_bandwidth() {
3737
cudaDeviceProp prop;
3838
cudaGetDeviceProperties(&prop, 0);
3939

40+
int mem_clock_khz = 0;
41+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4042
const std::size_t mem_freq =
41-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
43+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4244
const int bus_width = prop.memoryBusWidth;
4345
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4446
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.04-Vocabulary-Types/Sources/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ static double max_bandwidth() {
3939
cudaDeviceProp prop;
4040
cudaGetDeviceProperties(&prop, 0);
4141

42+
int mem_clock_khz = 0;
43+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4244
const std::size_t mem_freq =
43-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
45+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4446
const int bus_width = prop.memoryBusWidth;
4547
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4648
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.05-Serial-vs-Parallel/Solutions/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ static double max_bandwidth() {
4141
cudaDeviceProp prop;
4242
cudaGetDeviceProperties(&prop, 0);
4343

44+
int mem_clock_khz = 0;
45+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4446
const std::size_t mem_freq =
45-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
47+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4648
const int bus_width = prop.memoryBusWidth;
4749
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4850
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.05-Serial-vs-Parallel/Sources/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ static double max_bandwidth() {
4141
cudaDeviceProp prop;
4242
cudaGetDeviceProperties(&prop, 0);
4343

44+
int mem_clock_khz = 0;
45+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4446
const std::size_t mem_freq =
45-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
47+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4648
const int bus_width = prop.memoryBusWidth;
4749
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4850
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.06-Memory-Spaces/Solutions/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ static double max_bandwidth() {
4242
cudaDeviceProp prop;
4343
cudaGetDeviceProperties(&prop, 0);
4444

45+
int mem_clock_khz = 0;
46+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4547
const std::size_t mem_freq =
46-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
48+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4749
const int bus_width = prop.memoryBusWidth;
4850
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4951
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/01.06-Memory-Spaces/Sources/ach.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ static double max_bandwidth() {
4242
cudaDeviceProp prop;
4343
cudaGetDeviceProperties(&prop, 0);
4444

45+
int mem_clock_khz = 0;
46+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4547
const std::size_t mem_freq =
46-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
48+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
4749
const int bus_width = prop.memoryBusWidth;
4850
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
4951
return static_cast<double>(bytes_per_second) / 1024 / 1024 /

‎tutorials/cuda-cpp/notebooks/02.02-Asynchrony/Solutions/ach.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ static double max_bandwidth() {
4646
cudaDeviceProp prop;
4747
cudaGetDeviceProperties(&prop, 0);
4848

49+
int mem_clock_khz = 0;
50+
cudaDeviceGetAttribute(&mem_clock_khz, cudaDevAttrMemoryClockRate, 0);
4951
const std::size_t mem_freq =
50-
static_cast<std::size_t>(prop.memoryClockRate) * 1000; // kHz -> Hz
52+
static_cast<std::size_t>(mem_clock_khz) * 1000; // kHz -> Hz
5153
const int bus_width = prop.memoryBusWidth;
5254
const std::size_t bytes_per_second = 2 * mem_freq * bus_width / CHAR_BIT;
5355
return static_cast<double>(bytes_per_second) / 1024 / 1024 /
@@ -67,7 +69,7 @@ void store(int step, int height, int width, ContainerT &data)
6769
file.write(reinterpret_cast<const char *>(thrust::raw_pointer_cast(data.data())), height * width * sizeof(float));
6870
}
6971

70-
__host__ __device__ float compute(int cell_id, cuda::std::mdspan<const float, cuda::std::dextents<int, 2>> temp) {
72+
__host__ __device__ float compute(int cell_id, cuda::std::mdspan<const float, cuda::std::dims<2>> temp) {
7173
int height = temp.extent(0);
7274
int width = temp.extent(1);
7375

0 commit comments

Comments
 (0)