如何设置显卡驱动以实现深度学习推理的最佳性能

快速解决深度学习推理过程cuda或tensorRT推理速度变慢的办法,记录一下方便自己以后查看。

一、显卡性能设置:
    低延时模式——超高、最大帧速度——1000每秒帧数、电源管理模式——最高性能优先

二、管理员权限(命令提示符以管理员身份运行)终端输入nvidia-smi -q -d SUPPORTED_ClOCKS 

三、终端输入nvidia-smi -lgc 10501(根据实际大小来输入)

四、终端输入nvidia-smi -lgc 5000,10501   显存锁定在5000-10501直接波动,低版本最好直接设置最大值

五、终端输入nvidia-smi -rgc 解除锁定
 

六、程序初始化自动设置

int AmplifyGpu()
{
	STARTUPINFOW si = { sizeof(si) };  // Use STARTUPINFOW for wide character support
	PROCESS_INFORMATION pi;

	// Command 1: nvidia-smi -lgc 99999999999
	std::wstring cmd1 = L"cmd.exe /c nvidia-smi -lgc 99999999999";

	// CreateProcessW to run the first command
	if (CreateProcessW(NULL, &cmd1[0], NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
	{
		// Wait for a short time to make sure the window is created
		Sleep(1000);

		// Get the handle of the cmd window (using FindWindowW for wide strings)
		HWND hwndCmd = FindWindowW(NULL, L"Administrator: C:\\Windows\\System32\\cmd.exe");

		if (hwndCmd != NULL)
		{
			LockCmdWindow(hwndCmd);  // Lock the cmd window to prevent hiding or closing
		}

		// Wait for the process to finish
		WaitForSingleObject(pi.hProcess, INFINITE);

		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
	}
	else
	{
		std::cerr << "Failed to execute first command as Administrator!" << std::endl;
		return -1;
	}

	// Command 2: nvidia-smi -lmc 99999999999
	std::wstring cmd2 = L"cmd.exe /c nvidia-smi -lmc 99999999999";

	// CreateProcessW to run the second command
	if (CreateProcessW(NULL, &cmd2[0], NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
	{
		// Wait for a short time to make sure the window is created
		Sleep(1000);

		HWND hwndCmd = FindWindowW(NULL, L"Administrator: C:\\Windows\\System32\\cmd.exe");

		if (hwndCmd != NULL)
		{
			LockCmdWindow(hwndCmd);  // Lock the cmd window to prevent hiding or closing
		}

		// Wait for the process to finish
		WaitForSingleObject(pi.hProcess, INFINITE);

		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
	}
	else
	{
		std::cerr << "Failed to execute second command as Administrator!" << std::endl;
		return -1;
	}

	std::cout << "Commands executed successfully!" << std::endl;
	return 0;
	
	
	 Command 1: nvidia-smi -lgc 99999999999
	//LPCWSTR cmd1 = L"nvidia-smi -lgc 99999999999";

	 Command 2: nvidia-smi -lmc 99999999999
	//LPCWSTR cmd2 = L"nvidia-smi -lmc 99999999999";

	 Use ShellExecute to run the command as Administrator
	//HINSTANCE result1 = ShellExecuteW(
	//	NULL,              // No parent window
	//	L"runas",          // Run as administrator
	//	L"cmd.exe",        // Program to open (cmd)
	//	(L"/c " + std::wstring(cmd1)).c_str(), // Arguments: run command 1
	//	NULL,              // Default working directory
	//	SW_HIDE            // Hide the command window
	//);

	//if ((int)result1 <= 32)
	//{
	//	std::cerr << "Failed to execute first command as Administrator!" << std::endl;
	//	return -1;
	//}

	 Use ShellExecute to run the second command as Administrator
	//HINSTANCE result2 = ShellExecuteW(
	//	NULL,              // No parent window
	//	L"runas",          // Run as administrator
	//	L"cmd.exe",        // Program to open (cmd)
	//	(L"/c " + std::wstring(cmd2)).c_str(), // Arguments: run command 2
	//	NULL,              // Default working directory
	//	SW_HIDE            // Hide the command window
	//);

	//if ((int)result2 <= 32)
	//{
	//	std::cerr << "Failed to execute second command as Administrator!" << std::endl;
	//	return -1;
	//}

	//std::cout << "Commands executed successfully!" << std::endl;
	//return 0;
	
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值