Skip to content

Commit 792395d

Browse files
committed
add hw
1 parent 711e01e commit 792395d

9 files changed

+1830
-10
lines changed

CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
cmake_minimum_required(VERSION 3.12)
2-
project(hellocmake LANGUAGES CXX)
32

43
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CUDA_STANDARD 17)
55
if (NOT CMAKE_BUILD_TYPE)
66
set(CMAKE_BUILD_TYPE Release)
77
endif()
8+
# 如果需要指定显卡版本号的话:
9+
# set(CMAKE_CUDA_ARCHITECTURES 52)
810

9-
add_executable(main main.cpp)
11+
project(hellocmake LANGUAGES CXX CUDA)
12+
13+
add_executable(main main.cu)
14+
target_include_directories(main PUBLIC include)

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
## 作业要求
2626

27-
修改 main.cpp,改良其中的矩阵系列函数,回答注释中的问题,并通过 `main()` 函数中的基本测试。
27+
修改 main.cpp,改良其中的各个核函数,回答注释中的问题,并通过 `main()` 函数中的基本测试。
2828
测试的结果和你的优化思路,请填到 ANSWER.md。
2929

3030
温馨提示:如果用了 IDE,记得统一开启 Release 模式来比较性能。
3131

3232
## 关于内卷
3333

34-
如果你把矩阵转置改成了基于 `_mm_shuffle_ps` 的,或是用了莫顿序存储矩阵
34+
如果你把 `filter_positive` 改成了基于 BLS 优化的 `exclusive_scan` 的,或是用了 `thrust``vector` 和模板函数
3535
只要是在 **满足作业要求的基础** 上,这是件好事!
3636
老师会酌情加分,视为“独特的创新点”,但最多不超过 20 分。

include/CudaAllocator.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <cstddef>
4+
#include <utility>
5+
#include <cuda_runtime.h>
6+
#include "helper_cuda.h"
7+
8+
template <class T>
9+
struct CudaAllocator {
10+
using value_type = T;
11+
12+
T *allocate(size_t size) {
13+
T *ptr = nullptr;
14+
checkCudaErrors(cudaMallocManaged(&ptr, size * sizeof(T)));
15+
return ptr;
16+
}
17+
18+
void deallocate(T *ptr, size_t size = 0) {
19+
checkCudaErrors(cudaFree(ptr));
20+
}
21+
22+
template <class ...Args>
23+
void construct(T *p, Args &&...args) {
24+
if constexpr (!(sizeof...(Args) == 0 && std::is_pod_v<T>))
25+
::new((void *)p) T(std::forward<Args>(args)...);
26+
}
27+
28+
constexpr bool operator==(CudaAllocator<T> const &other) const {
29+
return this == &other;
30+
}
31+
};

0 commit comments

Comments
 (0)