cusolverDnCreate之后,如果不调用 cusolverSetStream,那么,cusolver的这个handle是否可以被正常使用来调用cusolver的Math API 呢?
1,不设置时会Get到 NULL stream
测试源码
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <cusolverDn.h>
int main()
{
cusolverDnHandle_t handle;
cublasHandle_t cublasHandle;
cudaStream_t stream;
cusolverDnCreate(&handle);
cublasCreate(&cublasHandle);
//cudaStreamCreate(&stream);
//LL::cusolverDnSetStream(handle, stream);
//LL::cublasSetStream(cublasHandle, stream);
cudaStream_t blas_stream;
cublasGetStream(cublasHandle, &blas_stream);
printf("blas_stream = %p\n", blas_stream);
cudaStream_t solver_stream;
cusolverDnGetStream(handle, &solver_stream);
printf("solver_stream = %p\n", solver_stream);
return 0;
}
编译命令:
$ g++ hello.cpp -I /usr/local/cuda/include -L /usr/local/cuda/lib64 -lcudart -lcublas -l cusolver
运行效果:
结论:
Get到的stream都是NULL指针,即,cublas和cusolver都会使用默认stream;
2,cusolver在不设置stream时能正常工作
测试源代码:
https://github.com/NVIDIA/cuda-samples/blob/v11.4/Samples/cuSolverDn_LinearSolver/cuSolverDn_LinearSolver.cpp
将上述示例中的SetStream的两行注释掉,依然可以正常工作:
没有注释掉Set效果图:
没注释掉Set的运行结果:
注释掉了Set效果图:
注释掉Set的效果图:
不注释时,stream指针非0,
注释掉时,stream指针为0;
但计算结果和运行时间结果完全一致;