小编Pas*_*cal的帖子

Cuda和OpenGL Interop

我一直在阅读CUDA文档,在我看来,需要与glGL接口的每个缓冲区都需要在glBuffer中创建.

根据nvidia编程指南,必须这样做:

GLuint positionsVBO;
struct cudaGraphicsResource* positionsVBO_CUDA;

int main() {

    // Explicitly set device
    cudaGLSetGLDevice(0);
    // Initialize OpenGL and GLUT
    ...
    glutDisplayFunc(display);
    // Create buffer object and register it with CUDA
    glGenBuffers(1, positionsVBO);
    glBindBuffer(GL_ARRAY_BUFFER, &vbo);
    unsigned int size = width * height * 4 * sizeof(float);
    glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    cudaGraphicsGLRegisterBuffer(&positionsVBO_CUDA, positionsVBO, cudaGraphicsMapFlagsWriteDiscard);

    // Launch rendering loop
    glutMainLoop();
}
void display() {
    // Map buffer object for writing from CUDA
    float4* positions;
    cudaGraphicsMapResources(1, &positionsVBO_CUDA, 0);
    size_t num_bytes;
    cudaGraphicsResourceGetMappedPointer((void**)&positions, …
Run Code Online (Sandbox Code Playgroud)

opengl cuda

18
推荐指数
1
解决办法
1万
查看次数

Xcode 4.5和带有Clang的OpenMP(Apple LLVM)仅使用一个核心

我们在C++ 11项目中使用Xcode 4.5,我们使用OpenMP来加速计算:

#pragma omp parallel for
for (uint x=1; x<grid.width()-1; ++x) {
    for (uint y=1; y<grid.height()-1; ++y) {
         // code
    }
}
Run Code Online (Sandbox Code Playgroud)

虽然活动监视器显示程序正在使用多个线程,但我们发现只使用了一个核心:

运行我的代码的Activity Monitor的屏幕截图

我们还使用GCC 4.7在Ubuntu上运行相同的代码,我们观察到所有核心上的争用.是否已在Apple LLVM中删除了OpenMP支持?有没有替代OpenMP?由于我们使用C++ 11功能,因此无法切换到GCC.

c++ xcode openmp clang

6
推荐指数
1
解决办法
4010
查看次数

使用带有Apple核心库(如Foundation.h)的OSX上的gcc-4.7编译Objective C文件

我在某种程度上无法使用包含任何OSX核心库的GCC 4.7编译Objective C文件,例如:

#import <Foundation/Foundation.h>
Run Code Online (Sandbox Code Playgroud)

产生的错误总是会导致奇怪的GCC输出:

gcc -c -pipe -O2 -arch x86_64 -mmacosx-version-min=10.8 -Wall -W  -I/usr/local/Cellar/qt/4.8.4/mkspecs/macx-g++ -I../TerrainFluid -I../TerrainFluid/external -I../TerrainFluid -I. ../TerrainFluid/external/osx_bundle.mm -o osx_bundle.o

In file included from 

/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:123:0,
                 from ../TerrainFluid/external/osx_bundle.mm:24:
/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:69:24: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:69:24: error: expected ')' before '^' token
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:159:0,
                 from ../TerrainFluid/external/osx_bundle.mm:24:
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:36:15: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:36:15: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:37:39: error: expected type-specifier before 'NSUserScriptTaskCompletionHandler'
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:53:15: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:53:15: error: …
Run Code Online (Sandbox Code Playgroud)

macos gcc objective-c

5
推荐指数
1
解决办法
933
查看次数

链接OSX Homebrew Gfortran与libc ++

我有一个带有大型C++组件的项目,我能够使用OSX上的clang成功编译(Apple LLVM版本6.1.0(clang-602.0.49)(基于LLVM 3.6.0svn).由于OSX不提供Fortran编译器我通过Homebrew安装了gfortran.

编译工作正常,但我无法将编译的Fortran代码与之前编译的C++代码链接:我收到以下错误:

$ make fortran
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
      DataFieldInfo::FromJSON(JSONNode const&) in [...]
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      std::__1::vector<char, std::__1::allocator<char> >::allocate(unsigned long) in [...]
      void std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::__push_back_slow_path<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in [...]
      void std::__1::vector<JSONNode, std::__1::allocator<JSONNode> >::__push_back_slow_path<JSONNode const>(JSONNode const&) in [...]
[...]
Run Code Online (Sandbox Code Playgroud)

这告诉我,我在Fortran和C++部分之间存在链接问题.

如何将Fortran部分与libc ++链接?Homebrew提供的gfortran可以实现吗?解决这个问题的最佳方法是什么?我应该尝试使用clang ++进行链接吗?

macos fortran libc++

5
推荐指数
1
解决办法
590
查看次数

CUDA __syncthreads()和递归

我想使用__syncthreads()来进行递归

__device__ void foo(int k) {
  if (some_condition) {
    for (int i=0;i<8;i++) { 
       foo(i+k); // foo might take longer with some inputs
       __syncthreads();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

__syncthreads()现在如何应用?我知道它只适用于一个区块.据我所知,这适用于所有本地线程,与递归深度无关?但是如果我想确保这个__syncthreads()到某个递归深度呢?这甚至可能吗?我可以检查递归深度,但我相信这也行不通.

有可能的替代方案吗?

我已经看到CUDA Device> = 2.0有3个syncthread扩展

int __syncthreads_count(int predicate);
int __syncthreads_and(int predicate);
int __syncthreads_or(int predicate);
Run Code Online (Sandbox Code Playgroud)

但我不认为他们会帮助他们,因为他们看起来像一个原子计数器.

recursion cuda

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

cuda ×2

macos ×2

c++ ×1

clang ×1

fortran ×1

gcc ×1

libc++ ×1

objective-c ×1

opengl ×1

openmp ×1

recursion ×1

xcode ×1