简体   繁体   English

R内部构件:从SEXP对象中提取函数指针

[英]R internals: extracting a function pointer from an SEXP object

Is there a way to extract a C-style function pointer from an SEXP object? 有没有办法从SEXP对象中提取C样式的函数指针?

The Writing R Extensions zero-finding example is almost what I want. 我几乎要编写Writing R Extensions零查找示例 The body of f.check is passed from R to C and then called with eval . f.check的主体从R传递到C,然后使用eval进行调用。 Since I'm working inside CUDA, I can't call eval on an SEXP object in this way or use the Function type in Rcpp directly. 由于我在CUDA中工作,因此无法以这种方式在SEXP对象上调用eval或直接在Rcpp使用Function类型。 I have to unpack the raw function pointer inside the SEXP and pass it to a CUDA kernel. 我必须在SEXP中解压缩原始函数指针,并将其传递给CUDA内核。

GPUs can only run kernels consisting of code specifically designed for the architecture. GPU只能运行由专门为该体系结构设计的代码组成的内核。 I know very little about CUDA, but I think the principles are the same as OpenCL, which is pretty much C with an API for dealing with GPU memory and parallel architecture. 我对CUDA知之甚少,但我认为其原理与OpenCL相同,后者几乎是C语言,带有用于处理GPU内存和并行体系结构的API。 You can't just run R or C++ code in the GPU. 您不能只在GPU中运行R或C ++代码。 All the pointer is going to give you is a number stuck in the GPU. 所有指针将为您提供一个卡在GPU中的数字。 You can't call functions in main memory from the GPU. 您无法从GPU调用主内存中的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM