CUDA、MySQL 和 CMake

发布于 2024-10-19 12:43:00 字数 778 浏览 1 评论 0原文

我正在尝试创建一个 CUDA 程序(我是新来的),该程序首先从远程 MySQL 数据库获取信息。在 CUDA 调用之前,我在程序内使用 MySQL 网站上的 Connector/C 库。

当使用 gcc (没有任何 CUDA 代码)时,我可以用 MySQL 编译我的程序,但不能使用 nvcc (CUDA 编译器)。一位熟悉 CUDA 的同行向我提到,他必须编译一些他正在使用 nvcc 做的 libjpg 东西,以避免“错误的架构”和链接问题。他建议我用nvcc编译Connector/C库。但是,Connector/C 库使用 CMake 而不是常规 Makefile。

因此,作为 CMake 的新手,我研究了一些东西并找到了听起来很像我需要的工具链文件(在此处找到)。但是,我在编译过程中遇到了问题,其中不包括 Connector/C 中使用的所有默认包含和库。具体来说

-- Looking for include files HAVE_ALLOCA_H
-- Looking for include files HAVE_ALLOCA_H - not found.

-- Looking for strstr
-- Looking for strstr - not found

这些只是几个示例,还有更多文件未找到。 我是否正确地处理这个问题?有没有我没有考虑的更明显的解决方法?如果我尝试使用 CUDA 编译 MySQL Connector/C 是正确的,是否有任何建议可以正确包含 Connector/C 所需的文件和库?

感谢您的帮助。

I'm trying to create a CUDA program (which I'm new at) that involves first grabbing information from a remote MySQL database. I'm using the Connector/C library from the MySQL website inside the program, before the CUDA calls.

I'm able to compile my program with MySQL when using gcc (without any CUDA code), but not with nvcc (the CUDA compiler). A peer who is familiar with CUDA mentioned to me that he had to compile some libjpg stuff he was doing with nvcc to avoid 'wrong architecture' and linking problems. He suggested that I compile the Connector/C library with nvcc. However, the Connector/C library uses CMake instead of a regular Makefile.

So, being new to CMake, I researched some stuff and found the toolchain file which sounded a lot like what I needed (found here). However, I am running into problems during the compile where all of the default includes and libraries used in Connector/C are not included. Specifically

-- Looking for include files HAVE_ALLOCA_H
-- Looking for include files HAVE_ALLOCA_H - not found.

and

-- Looking for strstr
-- Looking for strstr - not found

Those are just a couple examples, there are many more files that are not found.
Am I approaching this problem correctly? Is there a more obvious workaround that I am just not considering? If I am right in trying to compile MySQL Connector/C with CUDA, are there any suggestions for properly including the files and libraries required for Connector/C?

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2024-10-26 12:43:00

如果您可以将 CUDA 内核与 mysql 调用分开并将它们放在单独的文件中,则可以使用 Makefile。

我将所有 cuda 内核等保留在 .cu 文件中,然后我有一个定义:

#
# CUDA Compilation Rules
#

define cuda-compile-rule
  $1: $(call generated-source,$2) \
    $(call source-dir-to-build-dir, $(subst .cu,.cubin, $2)) \
    $(call source-dir-to-build-dir, $(subst .cu,.ptx, $2))
    $(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(INCFLAGS) $(DEFINES) -o $@ -c $<

  $(call source-dir-to-build-dir, $(subst .cu,.cubin, $2)): $(call generated-source,$2)
    $(NVCC) -cubin -Xptxas -v $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(INCFLAGS) $(DEFINES) $(SMVERSIONFLAGS) -o $@ $<

  $(call source-dir-to-build-dir, $(subst .cu,.ptx, $2)): $(call generated-source,$2)
    $(NVCC) -ptx $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(INCFLAGS) $(DEFINES) $(SMVERSIONFLAGS) -o $@ $<
endef

为了便于使用,我还包含了三个函数:

generated-source = $(filter %.cpp, $1) $(filter %.c, $1) $(filter %.f, $1) $(filter %.F, $1) $(filter %.cu, $1)
source-dir-to-build-dir = $(addprefix $(BUILDDIR)/, $1)
source-to-object = $(call source-dir-to-build-dir, \
           $(subst .f,.o,$(filter %.f,$1)) \
           $(subst .F,.o,$(filter %.F,$1)) \
           $(subst .c,.o,$(filter %.c,$1)) \
           $(subst .cpp,.o,$(filter %.cpp,$1)) \
           $(if $(filter 1,$(USE_CUDA)),$(subst .cu,.cu.o,$(filter %.cu,$1))))

然后您需要做的就是构建源文件列表并调用

$(foreach f,$(filter %.cu, $listOfFiles),$(call cuda-compile-rule,$(call source-to-object,$f),$f))

:在函数source-to-object中有一个变量,我用它来有条件地禁用CUDA编译USE_CUDA

If you can separate out the CUDA kernels from your mysql calls and place them in separate files, you can use your Makefile.

I keep all of the cuda kernels and such in .cu files and then I have a definition:

#
# CUDA Compilation Rules
#

define cuda-compile-rule
  $1: $(call generated-source,$2) \
    $(call source-dir-to-build-dir, $(subst .cu,.cubin, $2)) \
    $(call source-dir-to-build-dir, $(subst .cu,.ptx, $2))
    $(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(INCFLAGS) $(DEFINES) -o $@ -c $<

  $(call source-dir-to-build-dir, $(subst .cu,.cubin, $2)): $(call generated-source,$2)
    $(NVCC) -cubin -Xptxas -v $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(INCFLAGS) $(DEFINES) $(SMVERSIONFLAGS) -o $@ $<

  $(call source-dir-to-build-dir, $(subst .cu,.ptx, $2)): $(call generated-source,$2)
    $(NVCC) -ptx $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(INCFLAGS) $(DEFINES) $(SMVERSIONFLAGS) -o $@ $<
endef

I've also included three functions for ease of use:

generated-source = $(filter %.cpp, $1) $(filter %.c, $1) $(filter %.f, $1) $(filter %.F, $1) $(filter %.cu, $1)
source-dir-to-build-dir = $(addprefix $(BUILDDIR)/, $1)
source-to-object = $(call source-dir-to-build-dir, \
           $(subst .f,.o,$(filter %.f,$1)) \
           $(subst .F,.o,$(filter %.F,$1)) \
           $(subst .c,.o,$(filter %.c,$1)) \
           $(subst .cpp,.o,$(filter %.cpp,$1)) \
           $(if $(filter 1,$(USE_CUDA)),$(subst .cu,.cu.o,$(filter %.cu,$1))))

Then all you need to do is build up a list of source files and call:

$(foreach f,$(filter %.cu, $listOfFiles),$(call cuda-compile-rule,$(call source-to-object,$f),$f))

Note that in the function source-to-object there is a variable which I use to conditionally disable CUDA compilation USE_CUDA.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文