自2016年11月起,可以编译引用Eigen3.3的CUDA代码 - 请参阅此答案
这个答案不是我正在寻找的,现在可能已经"过时",因为现在可能有一种更简单的方法,因为以下是在文档中写的
从Eigen 3.3开始,现在可以在CUDA内核中使用Eigen的对象和算法.但是,仅支持一部分功能,以确保在CUDA内核中不会触发动态分配.
另见这里.不幸的是,我无法找到任何这样的例子.
现在是否可以编写如下的内核,它应该只计算一堆点积?
__global__ void cu_dot(Eigen::Vector3d *v1, Eigen::Vector3d *v2, double *out, size_t N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if(idx < N)
{
out[idx] = v1[idx].dot(v2[idx]);
}
return;
}
Run Code Online (Sandbox Code Playgroud)
我可以编译它,但它似乎不起作用.当我尝试将数据复制到主机时,我明白了illegal memory access.请注意,我最初将Vector3d存储为`std :: vector然后分别使用
cudaMalloc((void **)&p_device_v1, sizeof(Eigen::Vector3d)*n);
cudaMemcpy(p_v1_device, v1.data(), sizeof(Eigen::Vector3d)*n, cudaMemcpyHostToDevice);
Run Code Online (Sandbox Code Playgroud)
我在https://github.com/GPMueller/eigen-cuda上使用CMake 建立了一个MWE项目
我已经尝试过但是失败了,以获得最低限度的工作示例.因为我不需要将我的大量代码暴露给python,所以我不需要f2py来包装它的大部分内容.此外,由于传递可分配数组和使用派生类型,我特别希望f2py只包装我创建的接口模块(在下面的示例'main.f90'中).但是我有问题要把我单独编译的其他模块链接到我的主模块.
请注意,所有源文件都在一个目录中.
我创建了一个我想要编译的fortran模块(libtest.f90):
module testmod
implicit none
contains
subroutine testsub(arr)
real, allocatable, intent(in) :: arr(:,:)
print *, 'testsub executed'
end subroutine testsub
end module testmod
Run Code Online (Sandbox Code Playgroud)
和一个我想用f2py(main.f90)包装的fortran模块:
module mainmod
use testmod
implicit none
contains
subroutine mainsub
real, allocatable :: arr(:,:)
call testsub(arr)
end subroutine main sub
end module mainmod
Run Code Online (Sandbox Code Playgroud)
gfortran -c -fPIC libtest.f90
Run Code Online (Sandbox Code Playgroud)
它生成'libtest.o'和'testmod.mod',以及
f2py -c --fcompiler=gfortran -L. -I. -llibtest -m Main main.f90
Run Code Online (Sandbox Code Playgroud)
这给了我' ld:找不到-llibtest的库 '.
我不明白为什么会这样,因为它似乎适用于其他人(F2PY找不到模块) …
在 Python 脚本中,我试图确定已安装的 Clang 支持的最高 C++ 标准。
一个问题是我不能依赖 的输出clang --version始终相同 - 最好的例子是 OSX 上的 AppleClang。尝试使用、 、 ....cpp等测试标志编译 hello world 文件似乎不是最可靠的方法,并且需要创建临时文件。-std=c++11-std=c++14
是否有任何命令可以运行来测试某种方言是否可用,而无需实际编译任何内容?
以下MWE描述了我想要使用的内容(请注意,我没有设计这个,我只是尝试使用某些代码,我通常不会使用全局变量).
PROGRAM MAIN
IMPLICIT NONE
integer :: N
real(8), allocatable :: a(:,:)
N=3
allocate(a(N,3))
a=initialize_array()
CONTAINS
function initialize_array() result(a)
IMPLICIT NONE
real(8) :: a(N,3)
a=1
end function initialize_array
END PROGRAM MAIN
Run Code Online (Sandbox Code Playgroud)
gfortran给出了一个错误,它Error: Variable 'n' cannot appear in the expression at (1)指向real(8) :: a(N,3)函数内部.在一个子程序中它会起作用,那么问题可能在这里呢?
为什么ifort(v.15.0.3)编译这个,而gfortran(v.4.8.4)没有?
我想创建键盘绑定,至少在不同的键盘布局上工作类似。我的问题是shift修饰符将键转换为不同的键,如文档中所述:http : //doc.qt.io/qt-5/qkeysequence.html#keyboard-layout-issues
无论键盘布局如何,有没有办法找出原始键?
例如,.当shift+.被按下时找出被按下。
另请参阅此(当前未回答)问题:使用 qkeyevent 在 qt 中获取 shift+numeric keys
以下函数应该将 C 字符串转换为 Fortran 字符串,并且在 Release 版本中可以正常工作,但在 Debug 中不能:
! Helper function to generate a Fortran string from a C char pointer
function get_string(c_pointer) result(f_string)
use, intrinsic :: iso_c_binding
implicit none
type(c_ptr), intent(in) :: c_pointer
character(len=:), allocatable :: f_string
integer(c_size_t) :: l_str
character(len=:), pointer :: f_ptr
interface
function c_strlen(str_ptr) bind ( C, name = "strlen" ) result(len)
use, intrinsic :: iso_c_binding
type(c_ptr), value :: str_ptr
integer(kind=c_size_t) :: len
end function c_strlen
end interface
l_str = c_strlen(c_pointer)
call c_f_pointer(c_pointer, f_ptr)
f_string …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的代码示例,当-O2在gcc 8.2.0下进行优化时会崩溃
#include <vector>
#include <functional>
#include <iostream>
template<typename T, typename Container>
class Lambda_Expression
{
using Lambda = std::function<T()>;
const Lambda & _lambda;
public:
Lambda_Expression(const Lambda & l) : _lambda(l) {}
T operator[](const std::size_t i)
{
std::cerr << "inside expression [] " << i << std::endl;
return _lambda();
}
};
auto lambda = []() -> double
{
return 1.0;
};
int main()
{
int N = 10;
std::vector<double> res(N, 0.0);
double x = lambda();
std::cerr << "before for …Run Code Online (Sandbox Code Playgroud)