.CODE在汇编程序中在段的第一行设置断点不会停止程序的执行.
那么Visual Studio的调试器会使它无法在汇编程序的第一行创建断点?这是调试器的一些奇怪之处,打破多字节指令的情况,还是我只是在做一些愚蠢的事情?
我有以下汇编程序在Visual Studio中编译和运行:
; Tell MASM to use the Intel 80386 instruction set.
.386
; Flat memory model, and Win 32 calling convention
.MODEL FLAT, STDCALL
; Treat labels as case-sensitive (required for windows.inc)
OPTION CaseMap:None
include windows.inc
include masm32.inc
include user32.inc
include kernel32.inc
include macros.asm
includelib masm32.lib
includelib user32.lib
includelib kernel32.lib
.DATA
BadText db "Error...", 0
GoodText db "Excellent!", 0
.CODE
main PROC
;int 3 ; <-- If uncommented, this will not break. …Run Code Online (Sandbox Code Playgroud) 我的类GraphicsManager已经出错了.
GraphicsManager.cpp:
#include "C:\Users\Chris Uzzolina\Desktop\obj\include\GraphicsManager.h"
#include <SDL.h>
#include <string>
GraphicsManager::GraphicsManager(int SCREEN_WIDTH, int SCREEN_HEIGHT, int SCREEN_BPP, std::string caption, SDL_Surface *screen)
{
}
GraphicsManager::~GraphicsManager()
{
//dtor
}
bool init(int SCREEN_WIDTH, int SCREEN_HEIGHT, int SCREEN_BPP, std::string caption, SDL_Surface *scr)
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
scr = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( scr == NULL )
{ …Run Code Online (Sandbox Code Playgroud) 我将以下代码作为重组数据的一部分,以便以后在CUDA内核中使用:
thrust::device_ptr<int> dev_ptr = thrust::device_pointer_cast(dev_particle_cell_indices);
int total = 0;
for(int i = 0; i < num_cells; i++) {
particle_offsets[i] = total;
// int num = 0;
int num = thrust::count(dev_ptr, dev_ptr + num_particles, i);
particle_counts[i] = num;
total += num;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我设置num为0(取消注释第5行,并注释掉第6行),应用程序将以超过30 fps的速度运行,这是我的目标.但是,当我设置num等于thrust::count呼叫时,帧率降至约1-2 fps.为什么会这样?
我的理解是,推力应该是高度优化的算法的集合,利用GPU的强大功能,所以我很惊讶它会对我的程序的性能产生这样的影响.这是我第一次使用推力,所以我可能没有意识到一些重要的细节.
是否有关于thrust::count在循环中使用导致它运行如此缓慢的事情?如何优化我的使用?
在我目前的测试案例中,给出一些数字num_particles大约是2000,num_cells大概是1500.
请考虑以下代码:
const char *s = "a b c d !";
const char *p = s;
top:for(; *p; p++) {
switch(*p) {
case 0x20:
case '\n':
goto top;
default:
putchar(*p);
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么它进入无限循环,而不是停止时*p是NULL?我想到了以下几点:当*p是0x20或\n再次回到循环的开始,因为它测试的条件和计算表达式p++.所以,我没有看到它无限循环的原因,或者我真的没有得到C语言中的goto语句和labels工作方式.