- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编译修改后的 mlpack knn_example.cpp Xeon Phi Knights Corner 的示例。它使用 mlpack 库以及 Armadillo c++ 库。它似乎编译成功但是当我运行 pymic 代码时,它抛出以下错误:
`pymic.offload_error.OffloadError: Could not load library 'knn.so' on device 0`.
修改后的c++代码为:
extern "C" {
#include <Python.h>
#include <numpy/arrayobject.h>
}
#include <mlpack/core.hpp>
#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
#include <pymic_kernel.h>
using namespace mlpack;
using namespace mlpack::neighbor; // NeighborSearch and NearestNeighborSort
using namespace mlpack::metric; // ManhattanDistance
PYMIC_KERNEL
void calc_knn(double *arr, double *distarr)
{
// Armadillo is a C++ linear algebra library; mlpack uses its matrix data type.
arma::mat data(arr, 17, 4);
/*
* Load the data from a file. mlpack does not provide an example dataset,
* so I've included a tiny one.
*
* 'data' is a helper class in mlpack that facilitates saving and loading
* matrices and models.
*
* Pass the filename, matrix to hold the data, and set fatal = true to have
* it throw an exception if there is an issue.
*
* 'Load' excepts comma-separated and tab-separated text files, and will
* infer the format.
*/
//data::Load("data.csv", data, true);
/*
* Create a NeighborSearch model. The parameters of the model are specified
* with templates:
* - Sorting method: "NearestNeighborSort" - This class sorts by increasing
* distance.
* - Distance metric: "ManhattanDistance" - The L1 distance, sum of absolute
* distances.
*
* Pass the reference dataset (the vectors to be searched through) to the
* constructor.
*/
NeighborSearch<NearestNeighborSort, ManhattanDistance> nn(data);
/*
* Create the matrices to hold the results of the search.
* neighbors [k x n] - Indeces of the nearest neighbor(s).
* One column per data query vector and one row per
* 'k' neighbors.
* distances [k x n] - Calculated distance values.
* One column per data query vector and one row per
* 'k' neighbors.
*/
arma::Mat<size_t> neighbors;
arma::mat distances(distarr, 17, 17);
/*
* Find the nearest neighbors.
*
* If no query vectors are provided (as is the case here), then the
* reference vectors are searched against themselves.
*
* Specify the number of neighbors to find, k = 1, and provide matrices
* to hold the result indeces and distances.
*/
nn.Search(1, neighbors, distances);
// Print out each neighbor and its distance.
for (size_t i = 0; i < neighbors.n_elem; ++i)
{
std::cout << "Nearest neighbor of point " << i << " is point "
<< neighbors[i] << " and the distance is " << distances[i] << ".\n";
}
}
编译参数如下:
icpc -std=c++11 -I/home/userxx/Downloads/pyMIC/include -I/usr/include/python2.7 -I/usr/lib64/python2.7/site-packages/numpy/core/include -I/usr/include -fPIC -qopenmp -g -shared -mmic -o knn.so knn.cpp
然后使用 knn.py 中的 python 代码运行它:
import pymic as mic
import numpy as np
from collections import namedtuple
Point = namedtuple("Point", "x y val distance")
# load the library with the kernel function (on the target)
device = mic.devices[0]
library = device.load_library(("knn.so",))
stream = device.get_default_stream()
#na = np.arange(1, 33)
#a = stream.bind(na)
n = 17; # Number of data points
arr = np.array([[1, 12, 0, 0],
[2, 5, 0, 0],
[5, 3, 1, 0],
[3, 2, 1, 0],
[3, 6, 0, 0],
[1.5, 9, 1, 0],
[7, 2, 1, 0],
[6, 1, 1, 0],
[3.8, 3, 1, 0],
[3, 10, 0, 0],
[5.6, 4, 1, 0],
[4,2,1, 0],
[3.5, 8, 0, 0],
[2, 11, 0, 0],
[2, 5, 1, 0],
[2, 9, 0, 0],
[1, 7, 0, 0]])
distances = np.zeros((n,n))
distances_off = stream.bind(distances)
print "input:"
print "--------------------------------------"
print arr
print
stream.invoke(library.calc_knn, arr, distances_off)
stream.sync()
print "output:"
print "--------------------------------------"
distance_off.update_host()
stream.sync()
#np.asarray(p_off)
print "The distances are: "
print distance_off
OFFLOAD_REPORT=3 的输出如下:
[root@localhost knn_mlpack_example]# python2.7 knn.py
PYMIC: debug level set to 7
PYMIC: tracing is disabled
PYMIC: found 1 device(s)
PYMIC: created stream 0x169f6f0 for device 0
PYMIC: searching for liboffload_array.so in
PYMIC: looking for liboffload_array.so in /usr/lib64/python2.7/site-packages/pymic
PYMIC: loading '/usr/lib64/python2.7/site-packages/pymic/liboffload_array.so' on device 0
[Offload] [HOST] [State] Initialize logical card 0 = physical card 0
[Offload] [MIC 0] [File] src/pymicimpl_misc.cc
[Offload] [MIC 0] [Line] 186
[Offload] [MIC 0] [Tag] Tag 0
[Offload] [HOST] [Tag 0] [State] Start target
[Offload] [HOST] [Tag 0] [State] Setup target entry: __offload_entry_pymicimpl_misc_cc_186target_lo_cb16b0e23fb7bc6a3c1ad05f43fef8d0icc06321843140yPzMH
[Offload] [HOST] [Tag 0] [Signal] signal : none
[Offload] [HOST] [Tag 0] [Signal] waits : none
[Offload] [HOST] [Tag 0] [State] Gather copyin data: base=0x16af790 length=80289
[Offload] [HOST] [Tag 0] [State] Create target buffer: size=82225 offset=1936
[Offload] [HOST] [Tag 0] [State] Host->target pointer data 80289
[Offload] [HOST] [Tag 0] [State] Host->target copyin data 24
[Offload] [HOST] [Tag 0] [State] Execute task on target
[Offload] [HOST] [Tag 0] [State] Target->host pointer data 320
[Offload] [MIC 0] [Tag 0] [State] Start target entry: __offload_entry_pymicimpl_misc_cc_186target_lo_cb16b0e23fb7bc6a3c1ad05f43fef8d0icc06321843140yPzMH
[Offload] [MIC 0] [Tag 0] [Var] __offload_stack_ptr__ZN5pymic19target_load_libraryEiRKSsRSsRm.176 NOCOPY
[Offload] [MIC 0] [Tag 0] [Var] size_in IN
[Offload] [MIC 0] [Tag 0] [Var] data IN
[Offload] [MIC 0] [Tag 0] [Var] bufsz IN
[Offload] [MIC 0] [Tag 0] [Var] __offload_stack_ptr__ZN5pymic19target_load_libraryEiRKSsRSsRm.176 OUT
[Offload] [MIC 0] [Tag 0] [Var] __offload_stack_ptr__ZN5pymic19target_load_libraryEiRKSsRSsRm.176 OUT
[Offload] [MIC 0] [Tag 0] [Var] handle_device_ptr OUT
[Offload] [MIC 0] [Tag 0] [Var] tempname_cstr_sz INOUT
[Offload] [MIC 0] [Tag 0] [State] Target->host copyout data 16
[Offload] [HOST] [Tag 0] [CPU Time] 0.835535(seconds)
[Offload] [MIC 0] [Tag 0] [CPU->MIC Data] 80313 (bytes)
[Offload] [MIC 0] [Tag 0] [MIC Time] 0.001485(seconds)
[Offload] [MIC 0] [Tag 0] [MIC->CPU Data] 336 (bytes)
PYMIC: successfully loaded '/usr/lib64/python2.7/site-packages/pymic/liboffload_array.so' on device 0 with handle 0x7f168c0011c0
PYMIC: starting initialization of the offload infrastructure
PYMIC: loading supporting pyMIC libraries on all devices
PYMIC: searching for knn.so in
PYMIC: looking for knn.so in /usr/lib64/python2.7/site-packages/pymic
PYMIC: looking for knn.so in
PYMIC: loading 'knn.so' on device 0
[Offload] [MIC 0] [File] src/pymicimpl_misc.cc
[Offload] [MIC 0] [Line] 186
[Offload] [MIC 0] [Tag] Tag 1
[Offload] [HOST] [Tag 1] [State] Start target
[Offload] [HOST] [Tag 1] [State] Setup target entry: __offload_entry_pymicimpl_misc_cc_186target_lo_cb16b0e23fb7bc6a3c1ad05f43fef8d0icc06321843140yPzMH
[Offload] [HOST] [Tag 1] [Signal] signal : none
[Offload] [HOST] [Tag 1] [Signal] waits : none
[Offload] [HOST] [Tag 1] [State] Gather copyin data: base=0x16dc310 length=3100981
[Offload] [HOST] [Tag 1] [State] Create target buffer: size=3101765 offset=784
[Offload] [HOST] [Tag 1] [State] Host->target pointer data 3100981
[Offload] [HOST] [Tag 1] [State] Host->target copyin data 32
[Offload] [HOST] [Tag 1] [State] Execute task on target
[Offload] [HOST] [Tag 1] [State] Target->host pointer data 320
[Offload] [MIC 0] [Tag 1] [State] Start target entry: __offload_entry_pymicimpl_misc_cc_186target_lo_cb16b0e23fb7bc6a3c1ad05f43fef8d0icc06321843140yPzMH
[Offload] [MIC 0] [Tag 1] [Var] __offload_stack_ptr__ZN5pymic19target_load_libraryEiRKSsRSsRm.176 NOCOPY
[Offload] [MIC 0] [Tag 1] [Var] size_in IN
[Offload] [MIC 0] [Tag 1] [Var] data IN
[Offload] [MIC 0] [Tag 1] [Var] bufsz IN
[Offload] [MIC 0] [Tag 1] [Var] __offload_stack_ptr__ZN5pymic19target_load_libraryEiRKSsRSsRm.176 OUT
[Offload] [MIC 0] [Tag 1] [Var] __offload_stack_ptr__ZN5pymic19target_load_libraryEiRKSsRSsRm.176 OUT
[Offload] [MIC 0] [Tag 1] [Var] handle_device_ptr OUT
[Offload] [MIC 0] [Tag 1] [Var] tempname_cstr_sz INOUT
[Offload] [MIC 0] [Tag 1] [State] Target->host copyout data 16
[Offload] [HOST] [Tag 1] [CPU Time] 0.020388(seconds)
[Offload] [MIC 0] [Tag 1] [CPU->MIC Data] 3101013 (bytes)
[Offload] [MIC 0] [Tag 1] [MIC Time] 0.014470(seconds)
[Offload] [MIC 0] [Tag 1] [MIC->CPU Data] 336 (bytes)
caught!
Traceback (most recent call last):
File "knn.py", line 9, in <module>
library = device.load_library(("knn.so",))
File "/usr/lib64/python2.7/site-packages/pymic/_tracing.py", line 128, in wrapper
return func(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/pymic/offload_device.py", line 168, in load_library
return OffloadLibrary(libraries[0], device=self)
File "/usr/lib64/python2.7/site-packages/pymic/offload_library.py", line 125, in __init__
filename)
File "src/pymic_libxstream.pyx", line 238, in pymic.pymic_libxstream.pymic_library_load
File "src/pymic_libxstream.pyx", line 231, in pymic.pymic_libxstream._c_pymic_library_load
pymic.offload_error.OffloadError: Could not load library 'knn.so' on device 0
[Offload] [MIC 0] [File] src/pymicimpl_misc.cc
[Offload] [MIC 0] [Line] 258
[Offload] [MIC 0] [Tag] Tag 2
[Offload] [HOST] [Tag 2] [State] Start target
[Offload] [HOST] [Tag 2] [State] Setup target entry: __offload_entry_pymicimpl_misc_cc_258target_un_0cc318b72500803c42a213bcdc3aa259icc06321843140yPzMH
[Offload] [HOST] [Tag 2] [Signal] signal : none
[Offload] [HOST] [Tag 2] [Signal] waits : none
[Offload] [HOST] [Tag 2] [State] Gather copyin data: base=0x1667c78 length=22
[Offload] [HOST] [Tag 2] [State] Create target buffer: size=3214 offset=3192
[Offload] [HOST] [Tag 2] [State] Host->target pointer data 22
[Offload] [HOST] [Tag 2] [State] Host->target copyin data 24
[Offload] [HOST] [Tag 2] [State] Execute task on target
[Offload] [HOST] [Tag 2] [State] Target->host pointer data 256
[Offload] [MIC 0] [Tag 2] [State] Start target entry: __offload_entry_pymicimpl_misc_cc_258target_un_0cc318b72500803c42a213bcdc3aa259icc06321843140yPzMH
[Offload] [MIC 0] [Tag 2] [Var] __offload_stack_ptr__ZN5pymic21target_unload_libraryEiRKSsm.30 NOCOPY
[Offload] [MIC 0] [Tag 2] [Var] handle IN
[Offload] [MIC 0] [Tag 2] [Var] bufsz IN
[Offload] [MIC 0] [Tag 2] [Var] tempname_cstr IN
[Offload] [MIC 0] [Tag 2] [Var] __offload_stack_ptr__ZN5pymic21target_unload_libraryEiRKSsm.30 OUT
[Offload] [MIC 0] [Tag 2] [Var] errorcode OUT
[Offload] [MIC 0] [Tag 2] [State] Target->host copyout data 4
[Offload] [HOST] [Tag 2] [CPU Time] 0.001950(seconds)
[Offload] [MIC 0] [Tag 2] [CPU->MIC Data] 46 (bytes)
[Offload] [MIC 0] [Tag 2] [MIC Time] 0.000585(seconds)
[Offload] [MIC 0] [Tag 2] [MIC->CPU Data] 260 (bytes)
offload error: cannot unload library from the device 0 (error code 14)
如果有人能让我走上正确的道路,我将不胜感激。
最佳答案
pymic Github 站点上有一个 Unresolved 问题,用于调查 pymic 是否存在错误或环境设置是否存在问题。请看https://github.com/intel/pyMIC/issues/22 .一旦问题得到解决和关闭,我会在这里发布。
关于c++ - 如何在 pyMIC 中为 Xeon Phi 编译 knn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53740709/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!