Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FFT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuto Makino
FFT
Commits
b284c161
Commit
b284c161
authored
1 year ago
by
Yuto Makino
Browse files
Options
Downloads
Patches
Plain Diff
新規ファイルをアップロード
parent
988acfd8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CUDA課題/streamdivergencefft.cu
+75
-0
75 additions, 0 deletions
CUDA課題/streamdivergencefft.cu
with
75 additions
and
0 deletions
CUDA課題/streamdivergencefft.cu
0 → 100644
+
75
−
0
View file @
b284c161
#include
<stdio.h>
#include
<math.h>
#include
<cufft.h>
#define NX 512
#define NY 512
#define BLOCK_SIZE 4
// 複素数の構造体定義
struct
Complex
{
float
real
;
float
imag
;
};
__global__
void
InputHost
(
Complex
*
input
)
{
int
i
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
int
j
=
blockIdx
.
y
*
blockDim
.
y
+
threadIdx
.
y
;
if
(
i
<
NX
&&
j
<
NY
)
{
input
[
i
*
NY
+
j
].
real
=
sinf
(
i
+
j
);
input
[
i
*
NY
+
j
].
imag
=
cosf
(
i
+
j
);
}
}
int
main
()
{
const
int
size
=
NX
*
NY
;
const
int
complexSize
=
size
*
sizeof
(
Complex
);
cufftHandle
plan
;
// ホスト上の出力データ
Complex
hostOutput
[
size
];
// デバイス上の入力データと出力データ
Complex
*
deviceInput
;
Complex
*
deviceOutput
;
// デバイスメモリを確保
cudaMalloc
((
void
**
)
&
deviceInput
,
complexSize
);
cudaMalloc
((
void
**
)
&
deviceOutput
,
complexSize
);
// ストリームの生成
cudaStream_t
stream
;
cudaStreamCreate
(
&
stream
);
// グリッドとブロックの次元を設定
dim3
blockDim
(
BLOCK_SIZE
,
BLOCK_SIZE
);
dim3
gridDim
((
NX
+
blockDim
.
x
-
1
)
/
blockDim
.
x
,
(
NY
+
blockDim
.
y
-
1
)
/
blockDim
.
y
);
// カーネルを実行して入力データ初期化
InputHost
<<<
gridDim
,
blockDim
,
0
,
stream
>>>
(
deviceInput
);
// 2次元FFTのプランを作成
cufftPlan2d
(
&
plan
,
NX
,
NY
,
CUFFT_C2C
);
// FFTを実行
cufftExecC2C
(
plan
,
(
cufftComplex
*
)
deviceInput
,
(
cufftComplex
*
)
deviceOutput
,
CUFFT_FORWARD
);
// 出力データ転送
cudaMemcpyAsync
(
hostOutput
,
deviceOutput
,
complexSize
,
cudaMemcpyDeviceToHost
,
stream
);
// 結果の出力
for
(
int
i
=
0
;
i
<
NX
;
i
++
)
{
for
(
int
j
=
0
;
j
<
NY
;
j
++
)
{
int
idx
=
i
*
NY
+
j
;
printf
(
"Output: %f + %fI
\n
"
,
hostOutput
[
idx
].
real
,
hostOutput
[
idx
].
imag
);
}
}
cudaStreamDestroy
(
stream
);
cufftDestroy
(
plan
);
cudaFree
(
deviceInput
);
cudaFree
(
deviceOutput
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment