c - 在 CUDA C 中使用 open() 时出错

标签 c cuda system-calls

我尝试在 CUDA C 中打开一个文件

fd = open("stats.txt", O_CREAT)

open() 应该在主机端运行,编译通过但存在链接错误。

In function `open':
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:45: undefined reference to `__open_too_many_args'
collect2: ld returned 1 exit status

令我惊讶的是,在 Google 上搜索并没有显示任何接近的内容。有没有人有任何提示如何解决这个问题?非常感谢!


是的,我实际上使用了 0644,抱歉打错了。我将程序简化如下,但仍然出现链接错误。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <cuda.h>
#include <sys/types.h>
#include <fcntl.h>
int main(int argc, char ** argv) {
  int fd;
  if((fd = open("stats.txt",O_CREAT|O_RDWR, 0644)) == -1) { printf("Can't open stats.txt.\n"); }
  else printf("stats.txt opened.\n");
  return 0;
}

nvcc  -c -arch sm_20 --keep --compiler-options -fno-strict-aliasing  -I/usr/local/cuda/include/ -I../NVIDIA_GPU_Computing_SDK/C/common/inc/ -I../../libcuda -L../NVIDIA_GPU_Computing_SDK/C/lib -lcutil -DUNIX -O3 try.cu -o try

try.cu(13): warning: variable "fd" was set but never used

try.cu(13): warning: variable "fd" was set but never used

g++  -g -c try.cu.cpp -o try.cu_o

g++  -Wall -O3 try.cu_o -o try -L../libcuda -lcuda -L/home/NVIDIA_GPU_Computing_SDK/C/lib -static -static-libgcc   -L/usr/lib64 -lcutil_x86_64 -lm -lc

try.cu_o: In function `open':
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:45: undefined reference to `__open_too_many_args'

由于一些依赖,我必须使用旧的 nvcc

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Wed_Nov__3_16:16:57_PDT_2010
Cuda compilation tools, release 3.2, V0.2.1221

g++ 是 4.6.3。谢谢。

最佳答案

open() 函数有两种变体。

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);

如果指定 O_CREAT 标志,则必须还指定mode 参数(文件权限位)。

所以你的代码应该是例如

fd = open("stats.txt", O_CREAT, 0644)

__open_too_many_args 的链接器错误只是一种使最近的 glibc header 完成的编译/链接失败的方法,通过使用 gcc 特定的技巧来捕获将 O_CREAT 传递给的情况open(),但未能提供 3.mode 参数。

关于c - 在 CUDA C 中使用 open() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25706291/

相关文章:

c - 图片 18F45K42 : How to combine 4 bytes to Int?

c - 如何读取/写入 unsigned char 的特定位

c - Linux :/proc/<PID>/exe return path to executable '/bin/bash' for process located at '/home/<USER>/new/v'

c - C 中管道、greps、wc 的堆栈崩溃问题

cuda - fmad=false 提供良好的性能

linux - 如何在 Linux 中跟踪系统调用?

c - 回文程序无法运行

c - SSL_CONNECT 因 SSL_ERROR_SYSCALL 错误而失败

c - CUDA矩阵乘法的性能

c++ - 我应该如何以及何时在 cuda API 中使用倾斜指针?