'Concurrency': a namespace with this name does not exist - c++-amp

I am an amateur C# programmer who strayed into C++ because of a need for the C++ AMP technology for some heavy-duty number crunching. Hence, my C++ programming skills are not very well developed.
For my first attempt at an actual program, I chose code based on a Daniel Moth's April 2012 article. I cannot get it to build. I always get the error:
C2871 ‘Concurrency’: a namespace with this name does not exist.
I know that the code was first written for Visual Studio 11, but I only had VS 2008 and VS 2010 on my machine. So, I installed VS 2017 (version 15.9.4, .Net 4.7.03062). I started with an empty C++ project but had trouble with it. The best I could do, after I worked through all the things it didn’t recognize, was an error:
C3861: ‘access’ identifier not found, line 2616 in file ‘amp.h’.
So I started again, this time with an empty Windows Console Application project. Again, I had to tweak the code considerably to migrate from Visual Studio 11 to VS 2017, but ended up with code as shown below.
I tried what I could to find the source of the error. I targeted both x64 and x86, but it made no difference. I commented out line 5 and lines 21 – 27, and the code would build and execute. IntelliSense showed no problems, either with identifiers or syntax. In fact, the mouse-over info recognized the Concurrency constructs as such. I deliberately misspelled Concurrency, but IntelliSense caught that right away. I looked through the project properties with an eye toward a setting that needed to be changed to run AMP, but as I wasn’t even sure what I was looking for, I didn’t find anything.
I tried to find the name of the file in which Concurrency is defined, so that I could search my machine to see if it was there, and to add a path if it was, but was unsuccessful. I couldn’t even find the file name. I googled and pored through on-line sources and MS Docs, but no matter how I phrased my search questions, I didn’t find any answers.
The error says:
Concurrency does not exist
which to me means it can’t find it, it’s not on the machine, or some build setting is preventing it from being used. Most of the on-line articles about writing AMP code say nothing about build settings. Does it not require anything different than a serially-coded project? Is it as simple as a missing reference? If so, where do I go to find it? With my limited experience, I don’t know what else to try.
My machine is a Win 7 SP1 box. The KB2999226 bug fix has been installed. I didn’t install all of VS 2017 since I am only interested in C# and C++. Did I fail to install something I should have?
If this problem was addressed before, I couldn’t find it. So, any help would be appreciated.
1. #include <amp.h>
2. #include "pch.h"
3. #include <iostream>
4. #include <vector>
5. using namespace Concurrency;
6.
7. int main() {
8. const int M = 1024; const int N = 1024; //row, col for vector
9. std::vector<int> vA(M*N); std::vector<int> vB(M*N); //vectors to add
10. std::vector<int> vC(M*N); //vector for result
11.
12. for (int i = 0; i < M; i++) { vA[i] = i; } //populate vectors
13. for (int j = N - 1; j >= 0; j--) { vB[j] = j; }
14.
15. for (int i = 0; i < M; i++) { //serial version of
16. for (int j = 0; j < N; j++) { //matrix addition
17. vC[i*N + j] = vA[i*N + j] + vB[i*N + j]; //using vectors
18. }
19. }
20.
21. extent<2> e(M, N); //uses AMP constructs but no
22. array_view<int, 2> a(e, vA), b(e, vB); //parallel functions invoked
23. array_view<int, 2> c(e, vC);
24. index<2> idx(0, 0);
25. for (idx[0] = 0; idx[0] < e[0]; idx[0]++) {
26. for (idx[1] = 0; idx[1] < e[1]; idx[1]++) {
27. c[idx] = a[idx] + b[idx];
28. }
29. }
30. // C2871 'Concurrency': a namespace with this name does not exist. Line 5
31. // Also C2065, C3861, C2062 for all Concurrency objects Line 21 - Line 27
32. }
33.

With,
#include "amp.h"
#include "pch.h"
#include <iostream>
using namespace concurrency;
I get,
C2871 'concurrency': a namespace with this name does not exist
However, with,
#include "pch.h"
#include <iostream>
#include "amp.h"
using namespace concurrency;
there is no error.
I suggest moving #include "amp.h" as shown.
I also used both concurrency and Concurrency. There was no difference.
For the error C3861: ‘access’ identifier not found, line 2616 in file ‘amp.h’.
From the menu, select Project, then select Properties.
In the Property Pages window, under C/C++, select All Options, then select Conformance mode.
Change Yes (/permissive-) to No. Select OK.
Build the project and run.
By default, the /permissive- option is set in new projects created by Visual Studio 2017 version 15.5 and later versions. It is not set by default in earlier versions. When the option is set, the compiler generates diagnostic errors or warnings when non-standard language constructs are detected in your code, including some common bugs in pre-C++11 code.
More information may be found here.
This suggests, to me, that "amp.h" is not conforming to the changes made to C++ 15.5. Thus it worked with C++ in VS 2015 14.0 (Update 3), then failed with C++ in VS 2017 15.9.5.

Related

How to see the Auto Reference section on Plugin Inspector?

In the latest Unity manual
https://docs.unity3d.com/2019.1/Documentation/Manual/PluginInspector.html
they assert that the Plugin Inspector
now features an "Auto Reference" concept:
So using the latest Unity (and even trying .2 etc),
However no matter what I do I cannot make this appear. Every single Unity project I have tried, even Unity examples, does not have the feature.
How it looks for me ..
What is going on?
how to access the Auto Reference ?
tl;dr- "Auto reference" only works for managed plugins. that is a .dll file that was written in, and compiled from C#. Unmanaged plugins (dll's written in a language that is not C#, are unmanaged and can't be auto referenced)
edit: I just noticed there were more hidden comments, one of which was Aybe mentioning it working for managed DLL's.
edit2: if you want the project to test it out i can upload it.
I wanted to check if there was a difference between managed and unmanaged DLL's when inspecting in the editor (testing in Unity 2019, but I assume the same goes for 2018).
I made the following two DLL's. One in C# (managed) and one in CPP (unmanaged). I added some simply functionality to it to make sure it wouldn't be caused by having an empty dll.
Managed C# plugin
using System;
namespace TestDLLManaged
{
public class TestDLLManaged
{
public static float Multiply(int a, float b)
{
return a * b;
}
}
}
Compiled it into a DLL targeting .Net 3.5 framework (unity 2018 and later versions support 4.x, but wanted to play it on the safe side) and placed the .dll file in the /Assets/ folder (Apparantly the Assets/Plugin folder is intended to be used with native/unmanaged plugins, and not managed).
Unmanaged/native C++ plugin
//header filer
#pragma once
#define TESTDLLMULTIPLY_API __declspec(dllexport)
extern "C"
{
TESTDLLMULTIPLY_API float MultiplyNumbers(int a, float b);
}
//body
#include "TestDLLMultiply.h"
extern "C"
{
float MultiplyNumbers(int a, float b)
{
return a * b;
}
}
Also compiled this into a dll, and placed it in the /Assets/Plugin folder.
I call both DLL's inside DLLImportTest.cs and perform a simple calculation to make sure both DLL's are actually imported, and functioning like so
using static TestDLLManaged.TestDLLManaged;
public class DLLImportTest : MonoBehaviour
{
const float pi = 3.1415926535f;
[DllImport("TestDLL", EntryPoint = "MultiplyNumbers")]
public static extern float UnmanagedMultiply(int a, float b);
// Use this for initialization
void Start()
{
UnityEngine.Debug.LogFormat("validating unmanaged, expeceted result = 100: {0}", UnmanagedMultiply(10, 10f));
UnityEngine.Debug.LogFormat("validating managed, expeceted result = 100: {0}", Multiply(10, 10f));
}
}
When inspecting the DLL's in the editor it seems that the Managed (C#) plugin does have the option to auto reference and the Unmanaged/native (cpp) dll indeed doens't have the functionality. Now I don't actually know why this is the case, as it is nowhere to be found in the documentation. Maybe it's a bug, maybe there is another reason behind it. I may make a forum post about it later asking for more clarification.
As a little extra I decided to run a benchmark the two function, and to my surprise found that the managed C# plugin was actually faster than the cpp one.
private void BenchMark()
{
Stopwatch watch1 = new Stopwatch();
watch1.Start();
for (int i = 0; i < 10000000; i++)
{
UnmanagedMultiply(1574, pi);
}
watch1.Stop();
UnityEngine.Debug.LogFormat("Unmanaged multiply took {0} milliseconds", watch1.Elapsed);
Stopwatch watch2 = new Stopwatch();
watch2.Start();
for (int i = 0; i < 10000000; i++)
{
Multiply(1574, pi);
}
watch2.Stop();
UnityEngine.Debug.LogFormat("Managed multiply took {0} milliseconds", watch2.Elapsed);
}
Results:
Unmanaged multiply took 00:00:00.1078501 milliseconds
Managed multiply took 00:00:00.0848208 milliseconds
For anyone wishing to view the differences/experiment with it themselves, i've made a git-hub repo here containing the project i used above.
This question has been nicely resolved by #remy_rm
Compiled c# dlls ("managed plugins") do have the auto-reference feature
Actual native plugins ("unmanaged plugins") do NOT have the auto-reference feature
In fact this does apply identically on both PC and Mac:
Unity (sometimes) refers to:
c# compiled as a dll as "managed plugins"; and they (sometimes) refer to
native plugins (say, an actual static library for iPhone which is compiled C) as "unmanaged plugins".
(Whereas, all other Unity-related writing on the www generally refers to compiled c# as "dlls" and native plugins as "plugins".)
The auto-reference system is only for compiled c# .. "managed plugins".
A huge thanks to #remy_rm for spending hours resolving this issue.
Unity are trying and trying to improve their comic documentation - not quite there yet :)

Eclipse Nsight CDT plugin pressing F3 to Open Declaration goes to the wrong line

Nsight Eclipse Edition
Version: 5.5.0
CDT version: 8.1.2.nvidia-qualifier
Quick reference upon mouse over pops up the wrong declaration. Usually it's a function, which is located at the same header file, as the one I'm looking for, but it has no relation to it so far. For example:
For cudaMemcpy() it shows me this function from "cuda_runtime_api.h":
extern __host__ cudaError_t CUDARTAPI cudaPointerGetAttributes(struct cudaPointerAttributes *attributes, void *ptr);
For cudaMalloc() it gives me the description of:
extern __host__ cudaError_t CUDARTAPI cudaMemcpy2DToArray(struct cudaArray *dst, size_t wOffset, size_t hOffset, const void *src, size_t spitch, size_t width, size_t height, enum cudaMemcpyKind kind);
Why is indexing behaving this way? I'm getting tired of it after a couple of days working, but still couldn't find any obvious solution for this issue.
I will log this issue in our issue tracker. Sorry for the inconvenience. There is no workaround available.
Note that for performance reasons, Nsight does not index those files on your system. Instead, it comes prepackaged with compiled index files - apparently some headers might be different from the versions Nsight index was built from.

8051 include file setting in eclipse

I am running Eclispe IDE Kepler C/C++Developers, because I would like to programming a 8051 based microcontroller. I start Eclipse, File>New>C Project. Select MCS51 family (SDCC) under Project type and SDCC Tool Chain under Toolchains. Click next, leave Release and Debug selected, click Finish. The project is created. I want to try a simple code:
#include <8051.h>
void delay()
{
int i,j;
for (i = 0;i<=100;i++)
for (j = 0;j<=100;j++);
}
void main()
{
while (1)
{
P1_0 =0; // led glow
delay();
P1_0 = 1; // led off
delay();
}
}
When I build it there was a question mark before #inlude<8051.h> , and when I double click on it, I had got a messsage: No Inludes Found, "No include files were found that matched that name."
So, as I think Eclipse did not find the 8051 header file. I tried to find an example how to solve this problem, but I failed. The question is how to set the right path for 8051.h? If anyone of you can offer me a right solution I would be greatful.
Inside the folder where the toolchain is installed, you should have a folder called "include". Check if 8051.h is in the "root" folder, inside /include. If not, look for it. You must add the path to the include. Let's say the file is in /arch/8051.h, your include becomes:
#include <arch/8051.h>
void delay()
{
//stuff

Send data from Visual C++ via socket on the same machine

I am currently in a project involving data visualization of a signal captured from a device which has a Visual C++ API. I currently can log each datasample to file, but I'd like to do some sort of plot to screen.
I have had a previous successful experience with a similar job using socket between C++ and Python, but the code was lost. I have the Python socket "receiver" to reuse, but don't have the Visual C++ "sender" to reverse engineer or otherwise copy/paste.
My current Python code, which was working very fine, is:
import SocketServer
class SocketHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
## do something with 'data' here!
server = SocketServer.UDPServer(("192.168.1.23", 8888), SocketHandler)
server.serve_forever()
And the part of the Visual C++ that currently logs to file and I want to send to the socket is:
#include <fstream>
//(...lots of code...)
short int * dataBuff;
unsigned int dataNum;
int isAcqRunning;
int startFromTrg, stopFromTrg;
unsigned int firstSample, lastSample;
int errcode;
int i;
std::ofstream out("./out.txt");
// device->transferData is called inside a loop
// to get data from aquisition hardware's buffer
errcode = device->transferData(&dataBuff, &dataNum, &isAcqRunning,
&startFromTrg, &stopFromTrg,
&firstSample, &lastSample);
if(errcode == 0)
{
printf("\n Acquired samples: %d", dataNum);
for (i=firstSample; i<lastSample; i++)
out<<dataBuff[i]<<'\n'; /////// I'd like to send dataBuff[i] via socket!!
}
//(...lots of more code...)
Possibly useful additional information:
I'm using VisualStudio 2010 in Windows7;
This is the first time I touch C++ code in my life, I use Python almost exclusively;
I haven't have success trying to follow C++ examples from books and sites because, as it appears, C++ and VISUAL C++ are NOT the same thing and can behave very differently :o(
I thank very much for any help, and for reading this.
(EDIT: if there is a better way to do that without any additional complexity overhead for a noob, I would be glad to try. I like the socket stuff because it is language-transparent and solved a previous problem with very good speed)

Error C2679 when attempting to use std::wcout << wstring-var; vc++ 2008 express

I'm getting a rather odd error message when attempting to wcout a wstring in vc++ 2008 express:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring' (or there is no acceptable conversion)
If I understand this correctly it's reporting that wcout does not accept a wstring? I ask someone to compile this code under linux and it runs fine. I also tried the same code on another computer with vc++ 2008 express and still fails. A known issue with std in vc++ 2008?
#include <iostream>
int main()
{
std::wstring unicode_test = L"Unicode var";
std::wcout << L"Unicode non-var" << std::endl;
std::wcout << unicode_test << std::endl; //<-- This line fails!
}
I'm using vc++ 2008 express sp1 with all the updates up to KB948127. I'm aware that console will need codepage changes but this isn't even compiling. Thanks.
You need to #include <string>. I'm not sure what the standard says, but I'm quite sure that <iostream> is not required to export all of <string>, if any.
[edit]At least cplusplus.com does not even list string as the types declared in <iostream>. No, it's not the standard, I know...[/edit]
For those with this problem, you may need to enable multi-byte printing in the console. See the answer here: https://stackoverflow.com/a/41584090/1599699
And my comment:
I was having trouble printing a wstring that I instantiated with a greater length than the data I was supplying due to sizeof(wchar_t) == sizeof(char) * 2, and then printing anything after that wasn't succeeding.