using cufft with streams and callbacks

I successfully executed both fwd and inverse cufft and used extra kernels between them and after the latter to scale their values.

I managed to add streams to the previous stated example. The app performs as expected.

On a third version I successfully used callbacks to replace such extra-scaling kernels as well. The callbacks are used to load Complex and Store Real on the inverse fft.

Finally, I wonder if:

is it possible to combine callbacks with streams to avoid using those extra scale kernels in order to run on independent streams (not the default or NULL one)? I implemented it but I got the following error:

`cuFFT error 6:CUFFT_EXEC_FAILED at cuda-fft.cu

when calling this line code at the inverse fft, which has the callbacks :

CHECK_CUFFT_ERRORS( cufftExecC2R( bwd, (cufftComplex*)out_d, (cufftReal*)d[0] ) );

The original version, using scaling-kernels between them and after the latter to scale their values. Summarised following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// creating both the fwd & inverse 3D plan
if ((cufftPlan3d(&fwd, dim[0], dim[1], dim[2], CUFFT_R2C))!= CUFFT_SUCCESS) {printf("cufft forward_plan errorn"); exit(-1);}
if ((cufftPlan3d(&bwd, dim[0], dim[1], dim[2], CUFFT_C2R))!= CUFFT_SUCCESS) {printf("cufft inverse_plan errorn"); exit(-1);}
...
// performing the ffts using such plans
if ((cufftExecR2C(fwd, (cufftReal*)d[1], (cufftComplex*)out_d))!=CUFFT_SUCCESS) {printf("cufft execR2C-3D forward errorn"); exit(-1);}
scaling-kernel_1<<<,>>>
if ((cufftExecC2R(bwd, (cufftComplex*)out_d, (cufftReal*)d[0]))!=CUFFT_SUCCESS) {printf("cufft execC2R-3D inverse errorn"); exit(-1);}
scaling-kernel_2<<<,>>>
</code>
<code>// creating both the fwd & inverse 3D plan if ((cufftPlan3d(&fwd, dim[0], dim[1], dim[2], CUFFT_R2C))!= CUFFT_SUCCESS) {printf("cufft forward_plan errorn"); exit(-1);} if ((cufftPlan3d(&bwd, dim[0], dim[1], dim[2], CUFFT_C2R))!= CUFFT_SUCCESS) {printf("cufft inverse_plan errorn"); exit(-1);} ... // performing the ffts using such plans if ((cufftExecR2C(fwd, (cufftReal*)d[1], (cufftComplex*)out_d))!=CUFFT_SUCCESS) {printf("cufft execR2C-3D forward errorn"); exit(-1);} scaling-kernel_1<<<,>>> if ((cufftExecC2R(bwd, (cufftComplex*)out_d, (cufftReal*)d[0]))!=CUFFT_SUCCESS) {printf("cufft execC2R-3D inverse errorn"); exit(-1);} scaling-kernel_2<<<,>>> </code>
// creating both the fwd & inverse 3D plan
if ((cufftPlan3d(&fwd, dim[0], dim[1], dim[2], CUFFT_R2C))!= CUFFT_SUCCESS) {printf("cufft forward_plan errorn"); exit(-1);}                                                                                                                                                                          
                                                                                                                                                                                        
if ((cufftPlan3d(&bwd, dim[0], dim[1], dim[2], CUFFT_C2R))!= CUFFT_SUCCESS) {printf("cufft inverse_plan errorn"); exit(-1);}        

...
// performing the ffts using such plans
if ((cufftExecR2C(fwd, (cufftReal*)d[1], (cufftComplex*)out_d))!=CUFFT_SUCCESS) {printf("cufft execR2C-3D forward errorn"); exit(-1);}

scaling-kernel_1<<<,>>>

if ((cufftExecC2R(bwd, (cufftComplex*)out_d, (cufftReal*)d[0]))!=CUFFT_SUCCESS) {printf("cufft execC2R-3D inverse errorn"); exit(-1);}

scaling-kernel_2<<<,>>>
                                                                                                                                                                  

2nd version using streams

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>GPUerrchk(cudaStreamCreateWithFlags (&stream_fwd, cudaStreamNonBlocking));
// creating both the fwd & inverse 3D plan
if ((cufftPlan3d(&fwd, dim[0], dim[1], dim[2], CUFFT_R2C))!= CUFFT_SUCCESS) {printf("cufft forward_plan errorn"); exit(-1);}
if ((cufftSetStream(fwd, stream_fwd))!= CUFFT_SUCCESS) {printf("cufft cufftSetStream_fwd errorn"); exit(-1);}
GPUerrchk(cudaStreamCreateWithFlags (&stream_bwd, cudaStreamNonBlocking));
if ((cufftPlan3d(&bwd, dim[0], dim[1], dim[2], CUFFT_C2R))!= CUFFT_SUCCESS) {printf("cufft inverse_plan errorn"); exit(-1);}
if ((cufftSetStream(bwd, stream_bwd))!= CUFFT_SUCCESS) {printf("cufft cufftSetStream_bwd errorn"); exit(-1);}
...
// performing the ffts using such plans
if ((cufftExecR2C(fwd, (cufftReal*)d[1], (cufftComplex*)out_d))!=CUFFT_SUCCESS) {printf("cufft execR2C-3D forward errorn"); exit(-1);}
scaling-kernel_1<<<,,,stream_fwd>>>
if ((cufftExecC2R(bwd, (cufftComplex*)out_d, (cufftReal*)d[0]))!=CUFFT_SUCCESS) {printf("cufft execC2R-3D inverse errorn"); exit(-1);}
scaling-kernel_2<<<,,,stream_bwd>>>
</code>
<code>GPUerrchk(cudaStreamCreateWithFlags (&stream_fwd, cudaStreamNonBlocking)); // creating both the fwd & inverse 3D plan if ((cufftPlan3d(&fwd, dim[0], dim[1], dim[2], CUFFT_R2C))!= CUFFT_SUCCESS) {printf("cufft forward_plan errorn"); exit(-1);} if ((cufftSetStream(fwd, stream_fwd))!= CUFFT_SUCCESS) {printf("cufft cufftSetStream_fwd errorn"); exit(-1);} GPUerrchk(cudaStreamCreateWithFlags (&stream_bwd, cudaStreamNonBlocking)); if ((cufftPlan3d(&bwd, dim[0], dim[1], dim[2], CUFFT_C2R))!= CUFFT_SUCCESS) {printf("cufft inverse_plan errorn"); exit(-1);} if ((cufftSetStream(bwd, stream_bwd))!= CUFFT_SUCCESS) {printf("cufft cufftSetStream_bwd errorn"); exit(-1);} ... // performing the ffts using such plans if ((cufftExecR2C(fwd, (cufftReal*)d[1], (cufftComplex*)out_d))!=CUFFT_SUCCESS) {printf("cufft execR2C-3D forward errorn"); exit(-1);} scaling-kernel_1<<<,,,stream_fwd>>> if ((cufftExecC2R(bwd, (cufftComplex*)out_d, (cufftReal*)d[0]))!=CUFFT_SUCCESS) {printf("cufft execC2R-3D inverse errorn"); exit(-1);} scaling-kernel_2<<<,,,stream_bwd>>> </code>
GPUerrchk(cudaStreamCreateWithFlags (&stream_fwd, cudaStreamNonBlocking));
// creating both the fwd & inverse 3D plan
if ((cufftPlan3d(&fwd, dim[0], dim[1], dim[2], CUFFT_R2C))!= CUFFT_SUCCESS) {printf("cufft forward_plan errorn"); exit(-1);}        
if ((cufftSetStream(fwd, stream_fwd))!= CUFFT_SUCCESS) {printf("cufft cufftSetStream_fwd errorn"); exit(-1);}                                                                      
                                                                                                                                                                                        
GPUerrchk(cudaStreamCreateWithFlags (&stream_bwd, cudaStreamNonBlocking));                                                                                                                                                                                                                                                                                                                                                         
if ((cufftPlan3d(&bwd, dim[0], dim[1], dim[2], CUFFT_C2R))!= CUFFT_SUCCESS) {printf("cufft inverse_plan errorn"); exit(-1);}  
if ((cufftSetStream(bwd, stream_bwd))!= CUFFT_SUCCESS) {printf("cufft cufftSetStream_bwd errorn"); exit(-1);}  

...
// performing the ffts using such plans
if ((cufftExecR2C(fwd, (cufftReal*)d[1], (cufftComplex*)out_d))!=CUFFT_SUCCESS) {printf("cufft execR2C-3D forward errorn"); exit(-1);}

scaling-kernel_1<<<,,,stream_fwd>>>

if ((cufftExecC2R(bwd, (cufftComplex*)out_d, (cufftReal*)d[0]))!=CUFFT_SUCCESS) {printf("cufft execC2R-3D inverse errorn"); exit(-1);}

scaling-kernel_2<<<,,,stream_bwd>>>

3rd version: I successfully used callbacks to replace such extra-scaling kernels as well. The callbacks are used to load Complex and Store Real on the inverse fft:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>...
cufftCallbackLoadC h_LoadCCallbackPtr;;
checkCudaErrors( cudaMemcpyFromSymbol(&h_LoadCCallbackPtr, d_LoadCCallbackPtr, sizeof(h_LoadCCallbackPtr)) );
checkCudaErrors( cufftXtSetCallback(bwd, (void **)&h_LoadCCallbackPtr, CUFFT_CB_LD_COMPLEX, (void **)&d_params_bwdL) );
cufftCallbackStoreR h_storeRCallbackPtr;
checkCudaErrors( cudaMemcpyFromSymbol(&h_storeRCallbackPtr, d_storeRCallbackPtr, sizeof(h_storeRCallbackPtr)) );
checkCudaErrors( cufftXtSetCallback(bwd, (void **)&h_storeRCallbackPtr, CUFFT_CB_ST_REAL, (void **)&d_params_bwdS) );
</code>
<code>... cufftCallbackLoadC h_LoadCCallbackPtr;; checkCudaErrors( cudaMemcpyFromSymbol(&h_LoadCCallbackPtr, d_LoadCCallbackPtr, sizeof(h_LoadCCallbackPtr)) ); checkCudaErrors( cufftXtSetCallback(bwd, (void **)&h_LoadCCallbackPtr, CUFFT_CB_LD_COMPLEX, (void **)&d_params_bwdL) ); cufftCallbackStoreR h_storeRCallbackPtr; checkCudaErrors( cudaMemcpyFromSymbol(&h_storeRCallbackPtr, d_storeRCallbackPtr, sizeof(h_storeRCallbackPtr)) ); checkCudaErrors( cufftXtSetCallback(bwd, (void **)&h_storeRCallbackPtr, CUFFT_CB_ST_REAL, (void **)&d_params_bwdS) ); </code>
...
cufftCallbackLoadC h_LoadCCallbackPtr;;                                                                                                                                        
checkCudaErrors( cudaMemcpyFromSymbol(&h_LoadCCallbackPtr, d_LoadCCallbackPtr, sizeof(h_LoadCCallbackPtr)) );                                                                  
checkCudaErrors( cufftXtSetCallback(bwd, (void **)&h_LoadCCallbackPtr, CUFFT_CB_LD_COMPLEX, (void **)&d_params_bwdL) );                                                        
                                                                                                                                                                                    
cufftCallbackStoreR h_storeRCallbackPtr;                                                                                                                                       
checkCudaErrors( cudaMemcpyFromSymbol(&h_storeRCallbackPtr, d_storeRCallbackPtr, sizeof(h_storeRCallbackPtr)) );                                                               
checkCudaErrors( cufftXtSetCallback(bwd, (void **)&h_storeRCallbackPtr, CUFFT_CB_ST_REAL, (void **)&d_params_bwdS) );  

So, finally, again, I wonder if:

is it possible to combine callbacks with streams to avoid using those extra scale kernels in order to run on independent streams (not the default or NULL one)?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật