分类 未分类 下的文章

每一个 host thread 绑定一个 device

__host__​cudaError_t cudaSetDevice ( int device ) 绑定线程的 device

memory 相关

managed memory

在 host 和 device 上使用相同指针(virtual memory)访问。基于 page fault 机制

2025-02-10T08:23:13.png

使用 cudaMallocManaged 分配

当 GPU 访问 managed memory 出现 page fault 时,发生以下事件:

  1. Allocate new pages on the GPU;
  2. Unmap old pages on the CPU;
  3. Copy data from the CPU to the GPU;
  4. Map new pages on the GPU;
  5. Free old CPU pages.

使用 __host__​cudaError_t cudaMemPrefetchAsync ( const void* devPtr, size_t count, int dstDevice, cudaStream_t stream = 0 ) 将 managed memory prefetch 到 CPU 或 GPU

pinned host memory

分配的 host memory 默认是 pageable 的

GPU 无法直接访问 pageable 的 host memory,因此在拷贝 pageable host memory 时会先拷贝到 pinned memory,再拷贝到 device

可以使用 cudaMallocHost 直接分配 pinned host memory

2025-02-10T08:40:15.png

AMD Instinct 系列 GPU 对标 NVIDIA 科学计算 GPU
AMD Radeon 系列 GPU 对标 NVIDIA 桌面游戏卡

AMD Instinct™ MI325X

release date : 10/10/2024,目前最新
架构:CDNA3
内存:256GB HBM3E, 带宽:6TB/s
peak FP32 : 163.4 TFLOPs
peak FP64 : 81.7 TFLOPs

AMD Instinct™ MI250X

Frontier 中使用
release date : 11/08/2021
架构:CDNA2
内存:128GB HBM2e,带宽:3.2TB/s
peak FP32 : 47.9 TFLOPs
peak FP64 : 47.9 TFLOPs

AMD Instinct™ MI60

ORISE 中使用
release date : 11/18/2018
架构:Vega20
内存:32GB HBM2,带宽:1.2TB/s
peak FP32 : 14.7 TFLOPs
peak FP64 : 7.4 TFLOPs
peak FP16 : 29.5 TFLOPs

与之对比:

NVIDIA A100 GPU

release date : 5/14/2020
内存:80GB HBM2e,带宽:1935GB/s
peak FP32 : 19.5 TFLOPs
peak FP64 : 9.7 TFLOPs

ASSERT_* : fatal 错误,退出当前程序
EXPECT_* : nonfatal 错误,发生时不退出当前程序

test fixture

对于多个测试使用相同数据设置
继承 testing::Test, 以 protected: 开始。
使用 默认构造函数 或 SetUp() override 函数 为测试初始化
使用 析构函数 或 TearDown() 结束
在 fixture 中使用 TEST_F() 而非 TEST() 定义测试

不同 test 之间不会复用 fixture


::testing::StaticAssertTypeEq<T1, T2>(); assert 两个类型相同,不同时发生编译错误

あぁ! 夏を今もう一回
いまが最高!

时间追溯到几个月前,之前就一直想去一次ASL现场,没去上23年的觉得还是有点可惜的,所以就在想今年跑一趟。公布阵容的时候发现 day3 的阵容很想看:闹闹,TRUE老师,minori,ReoNa ,爱喵,asaka,还有南球和 fripside。所以拜托马哥帮忙搞票。后来又追加了北宇治和B小町,阵容就更加无敌了。

- 阅读剩余部分 -

Kokkos 是 C++ library

hierarchy :
device, host-parallel, host-serial

同步:
Kokkos::fence()

两个问题:

  1. memory space : device / host
  2. memory layout : LayoutLeft / LayoutRight

DualView : 维护在 device memory 上的 Kokkos::View 和其在 host memory 上的 Kokkos::View mirror,同时维护在两个不同 memory space 的 data

  • template argument:DataType, Layout, Device
  • using view_type = Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device>

原子操作相关

scatter-add :两个粒子共享邻居,当两个粒子同时更新邻居时可能造成 race
使用 data replication V.S. 使用 atomic operation 解决 race 问题
ScatterView : 在编译时透明地选择处理原子操作方法,对于 CPU 使用 data replication,对于 GPU 使用 atomic operation

`Kokkos::Experimental::contribute(View &dest, Kokkos::Experimental::ScatterView
const &src) 将 ScatterView 的 reduction 结果放回到 dest,可能在 Kokkos::parallel_reduce()` 后调用

检查 Kokkos 属性

判断 layout :

  if (std::is_same<typename decltype(fpair->f)::traits::array_layout, Kokkos::LayoutLeft>::value) {
    printf("array fpair->f is LayoutLeft\n");
  }
  if (std::is_same<typename decltype(fpair->f)::traits::array_layout, Kokkos::LayoutRight>::value) {
    printf("array fpair->f is LayoutRight\n");
  }

获取 stride :

  int strides[2];
  (fpair->x).stride(strides);
  printf("array fpair->x stride : (%d, %d)\n", strides[0], strides[1]);

Access traits

RandomAccess : Kokkos::MemoryTraits<Kokkos::RandomAccess> ,当在 Cuda execution space 中执行时, 如果对于在 CudaSpaceCudaUVMSpace 中的 const View,Kokkos 会使用 texture fetch 访问

Unmanaged View : Kokkos::MemoryTraits<Kokkos::Unmanaged>, 对于一个 raw pointer, Kokkos 不进行 reference counting 和 deallocation