How to porting a rather complicated c++ code (Geant4) into GPU ??

ronaldo1018 2015-11-03 01:40:19
i, I'm pretty new to CUDA programming and I'm having a problem trying to port a part of Geant4 code into GPU.

Geant4 is a particle simulation tool based on c++ program.

The main reasons why we think it difficult is as following:

1. Geant4 simulation uses c++ instead of c programming.

2. Geant4's program structure is a multi-level class ( In other words, it uses class calls class method to
complete the work }

3. In order to let kernel function uses the class function we need to add Tag __device__ __host__ before each function. Could anyone gives some samrt ideas to add this Tag in front of every class's member function ?

4. Geant4's each class uses many class pointer variable. Hence, we need to use CUDA Unified Memory
Mechanism to handle it ( this is a rather difficult part)

And we have use a simple c++ program to test for it




#include <iostream>
#include <cuda_runtime.h>
using namespace std;

// Derived class
class Rectangle
{
public:
Rectangle()
{

}
int getArea()
{
return (*width * *height);
}
int* width;
int* height;
};

// Base class
class Shape
{
public:
Shape()
{
}
Rectangle* rect;
};

__global__ void change_width(Shape* sha)
{
*(sha->rect->width) = 210;
*(sha->rect->height) = 10;
return;
}

int main(void)
{
Shape* sha;
cudaMallocManaged(&sha,sizeof(Shape));
cudaMallocManaged(&sha->rect, sizeof(Rectangle));
cudaMallocManaged(&sha->rect->width,sizeof(int));
cudaMallocManaged(&sha->rect->height,sizeof(int));
*(sha->rect->width) = 20;
*(sha->rect->height) = 10;
change_width<<<1,1,0>>>(sha);
cudaDeviceSynchronize();

// Print the area of the object.
cout << "Total area: " << sha->rect->getArea() << endl;

return 0;
}





In this code, we can port a 2-level class structure into GPU. And it works.
But you know , Geant4 is a rather big project. I am afraid that our simple idea could not fulfill the job.

Could anyone with good experience in porting c++ code to GPU give some good advice to me??
I really don't have idea how to handle for such a big program.
Thanks for all your help.

Sincerely,
KEVIN
...全文
189 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
Android NDK Beginner's Guide, 9781849691529 (1849691525), Packt Publishing, 2012 The short history of computing machines has witnessed some major events, which forever transformed our usage of technology. From the first massive main frames to the democratization of personal computers, and then the interconnection of networks. Mobility is the next revolution. Like the primitive soup, all the ingredients are now gathered: an ubiquitous network, new social, professional and industrial usages, a powerful technology. A new period of innovation is blooming right now in front of our eyes. We can fear it or embrace it, but it is here, for good! Android NDK is all about injecting high performance into your apps. Exploit the maximum power of these mobile devices using high-performance and portable code. This book will show you how to create C/C++ enabled applications and integrate them with Java. You will learn how to access native API and port libraries used in some of the most successful Android applications. Using this practical step-by-step tutorial, highlighted with comments and tricks, discover how to run C/C++ code embedded in a Java application or in a standalone application. You will create a real native application starting from project creation through to full implementation of native API and the porting of existing third-party libraries. You will discover OpenGL ES and OpenSL ES, which are becoming the new standard in mobility. You will also understand how to access keyboard and input peripherals and how to read accelerometer or orientation sensors. Finally, you will dive into more advanced topics such as debugging and ARM assembler instructions. By the end of the book, you should know the key elements to enable you to start exploiting the power and portability of native code.

581

社区成员

发帖
与我相关
我的任务
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
  • CUDA编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧