Fail to import semaphore from Vulkan to Cuda - cuda

I'm trying to import a Vulkan semaphore for using by CUDA on the windows platform, but always get a cudaErrorInvalidValue error. I can’t figure out what causes the problem.
Considering I have already a HANDLE for the Vulkan semaphore object, the Cuda side is at DLL1 as follows:
void test_createCudaImportSemaphor(HANDLE handle)
{
cudaExternalSemaphoreHandleDesc externalSemaphoreHandleDesc;
externalSemaphoreHandleDesc.flags = 0;
externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueWin32;
externalSemaphoreHandleDesc.handle.win32.handle = handle;
cudaExternalSemaphore_t cudaExternalSemaphore;
cudaError_t err = cudaImportExternalSemaphore(&cudaExternalSemaphore, &externalSemaphoreHandleDesc);
////////////////////////////////////////////////
// err= 1 (cudaErrorInvalidValue ) why ????
////////////////////////////////////////////////
// destory
err = cudaDestroyExternalSemaphore(cudaExternalSemaphore);
}
Testing creation of vulkan semaphore and calling test_createCudaImportSemaphor for importing to cuda is in DLL2 as follows:
void test_exportVulkanSemphoreToCuda(vk::Device device)
{
// create semaphore that can be exported (windows platform)
vk::ExportSemaphoreWin32HandleInfoKHR exportSemaphoreWin32HandleInfoKHR;
WindowsSecurityAttributes cWinSecurityAttributes; // taken from cuda samples 02_graphics
exportSemaphoreWin32HandleInfoKHR.pAttributes = &cWinSecurityAttributes;
exportSemaphoreWin32HandleInfoKHR.dwAccess = DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
vk::ExportSemaphoreCreateInfo exportSemaphoreCreateInfo;
exportSemaphoreCreateInfo.pNext = &exportSemaphoreWin32HandleInfoKHR;
exportSemaphoreCreateInfo.handleTypes = vk::ExternalSemaphoreHandleTypeFlagBits::eOpaqueWin32;
vk::SemaphoreCreateInfo semaphoreCreateInfo;
semaphoreCreateInfo.pNext = &exportSemaphoreCreateInfo;
vk::UniqueSemaphore upSemaphore = device.createSemaphoreUnique(semaphoreCreateInfo);
// get semaphore windows handle
vk::SemaphoreGetWin32HandleInfoKHR semaphoreGetWin32HandleInfoKHR = {};
semaphoreGetWin32HandleInfoKHR.semaphore = upSemaphore.get();
semaphoreGetWin32HandleInfoKHR.handleType = vk::ExternalSemaphoreHandleTypeFlagBits::eOpaqueWin32;
HANDLE handle = device.getSemaphoreWin32HandleKHR(semaphoreGetWin32HandleInfoKHR);
// Now try to import sempahore to cuda
test_createCudaImportSemaphor(handle);
CloseHandle(handle);
}

As #talonmies commented, indeed, the structure cudaExternalSemaphoreHandleDesc is actually not fully initialized with the code shown. The problem is solved when initializing the structure to zero:
cudaExternalSemaphoreHandleDesc externalSemaphoreHandleDesc = {};

Related

i am very new to micro controller world. i am using pic16f877, please solve simple error in below description

i am getting error in this code ....can any body tell this solution
void interrupt ISR (void)
{
if (RCIF == 1) //*error: expected ';' after top level declarator***
{
UART_Buffer = RCREG; // Read The Received Data Buffer
PORTB = UART_Buffer; // Display The Received Data On LEDs
RCIF = 0; // Clear The Flag
}
}

how do i publish the data on mqtt of the bme680 sensor using ESP32cam

I am using windows 10 and working on getting the gas readings from BME680 using esp32cam. I tried to add this:
#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
//#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <Arduino_JSON.h>
//uint64_t mac;
//uint32_t high;
//uint32_t low;
// Replace the next variables with your SSID/Password combination
const char* ssid = "";
const char* password = "";
// Add your MQTT Broker IP address, example:
//const char* mqtt_server = "";
const char* mqtt_server = "";
const char* mqtt_port = "";
const char* mqtt_user = "";
const char* mqtt_password = "";
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
//uncomment the following lines if you're using SPI
#include <SPI.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15
//Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
float temperature = 0;
float humidity = 0;
float pressure = 0;
float gas = 0;
//Device ID
//uint64_t chip_id;
//chip_id=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
// LED Pin
const int ledPin = 4;
void setup() {
Serial.begin(115200);
// default settings
// (you can also pass in a Wire library object like &Wire2)
//status = bme.begin();
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
WiFi.begin();
}
setup_wifi();
client.setServer(mqtt_server,...);
client.setCallback(callback);
pinMode(ledPin, OUTPUT);
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* message, unsigned int length) {
Serial.print("Message arrived on topic: ");
Serial.print(topic);
Serial.print(". Message: ");
String messageTemp;
for (int i = 0; i < length; i++) {
Serial.print((char)message[i]);
messageTemp += (char)message[i];
}
Serial.println();
// Feel free to add more if statements to control more GPIOs with MQTT
// If a message is received on the topic esp32/output, you check if the message is either "on" or "off".
// Changes the output state according to the message
if (String(topic) == "esp32/output") {
Serial.print("Changing output to ");
if(messageTemp == "on"){
Serial.println("on");
digitalWrite(ledPin, HIGH);
}
else if(messageTemp == "off"){
Serial.println("off");
digitalWrite(ledPin, LOW);
}
}
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP32Client", mqtt_user, mqtt_password)) {
Serial.println("connected");
// Subscribe
client.subscribe("esp32/output");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(20000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
long now = millis();
if (now - lastMsg > 5000) {
lastMsg = now;
// Temperature in Celsius
temperature = bme.readTemperature();
// Uncomment the next line to set temperature in Fahrenheit
// (and comment the previous temperature line)
//temperature = 1.8 * bme.readTemperature() + 32; // Temperature in Fahrenheit
// Convert the value to a char array
char tempString[8];
dtostrf(temperature, 1, 2, tempString);
//Serial.print("Temperature: ");
//Serial.println(tempString);
//client.publish("esp32/temperature", tempString);
humidity = bme.readHumidity();
// Convert the value to a char array
char humString[8];
dtostrf(humidity, 1, 2, humString);
//Serial.print("Humidity: ");
//Serial.println(humString);
//client.publish("esp32/humidity", humString);
pressure = bme.readPressure();
//Convert the value to a char array
char preString[16];
dtostrf(pressure, 1, 2, preString);
//Serial.print("Pressure: ");
//Serial.println(preString);
//client.publish("esp32/pressure", preString);
gas = bme.readGas();
//Serial.print(bme.gas_resistance / 1000.0);
char gasString[8];
dtostrf(gas, 1, 2, gasString);
//Serial.println(" KOhms");
char macValue[13]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEfuseMac();
sprintf(macValue, "%012x", mac);
//Serial.print("ChipID: ");
//Serial.println(chipId);
//client.publish("esp32/chipid", chipId);
JSONVar data;
data["temperature"] = temperature;
data["humidity"] = humidity;
data["pressure"] = pressure;
data["macValue"] = macValue;
data["gas"] = gas;
//Serial.print("data.keys() = ");
//Serial.println(data.keys());
//Serial.print("Data = ");
//Serial.println(data);
String jsonString = JSON.stringify(data);
//Serial.print("JSON.stringify(data) = ");
//Serial.println(jsonString);
client.publish("esp32/data", jsonString.c_str());
}
}
everything got compiled perfectly. But when i tried to upload the code, this error came up:
Arduino: 1.8.9 (Windows 10), Board: "ESP32 Wrover Module, Huge APP
(3MB No OTA), QIO, 80MHz, 115200, Verbose"
Sketch uses 789282 bytes (25%) of program storage space. Maximum
is 3145728 bytes.
Global variables use 40652 bytes (12%) of dynamic memory, leaving
287028 bytes for local variables. Maximum is 327680 bytes.
esptool.py v2.6
Serial port COM7
Connecting.....
Chip is .....(revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse,
Coding Scheme None
MAC: .....
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Warning: Could not auto-detect Flash size (FlashID=0xffffff,
SizeID=0xff), defaulting to 4MB
Compressed 8192 bytes to 47...
A fatal error occurred: Timed out waiting for packet content
A fatal error occurred: Timed out waiting for packet content
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I don't know why is this thing coming up because previously everything was working fine when I tried to incorporate BME280 and publish the available data on MQTT. Now, I have switched to bme680.
EDIT:
I tried to disconnect BME from ESP32, then uploaded the code, then connected BME back. The error did not show up, but still, the data is not being shown this time, rather something like this, continually:
rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun 8 2016 00:22:57
It looks to me that ESP32-CAM is not in the bootloader mode when you try to upload the code.
Did you connect IO0 and GND pins and push the reset button?
You should see the message that ESP32 is ready for upload in the terminal window.
Sorry for the late reply ... :)

dlopen load library correct,but run the program,the result is incorrect

I use dlopen, dlsym load library function. When I run the program, I met this problem:
use dlopen load function, call the function correct but the result is incorrect
don't use dlopen and call the function directly,the result is correct
How can I find the problem?
Example:
void *dl_handle = NULL;
char *error = NULL;
/* Open the shared object */
dl_handle = dlopen(pLibraryName, RTLD_LAZY );
if (!dl_handle)
{
return -1
}
char* error = NULL;
pFunc = dlsym( dlHandle, "mysql_rollback");
error = dlerror();
if (error != NULL)\
{
return -1
}

Setting System.Console.WindowHeight throws an System.NotSupportedException under Mono

I get an Unhandled Exception: System.NotSupportedException: Operation is not supported. The Exception is raised under Mono using Ubuntu 11.10.
Reading the property works. The docs could suggest that the Method does not pose issues.
Any ideas on how to best handle or fix this situation?
My current solution is rather awkward, and does not solve the issue of setting the Window Size through the System.Console-API:
const int defaultConsoleWindowWidth = 80;
const int defaultConsoleWindowHeight = 25;
if (pid != PlatformID.Unix && pid != (PlatformID)128) {
System.Console.WindowHeight = lastConsoleWindowHeight;
System.Console.WindowWidth = defaultConsoleWindowWidth;
}else{
//assume *NIX system
try {
var p = new Process();
p.StartInfo = new ProcessStartInfo(#"stty cols " + defaultConsoleWindowWidth + " rows " + lastConsoleWindowHeight, "-n")
{
UseShellExecute = false
};
p.Start();
p.WaitForExit();
}
catch (Exception e) { /*...*/}
}
My Mono version:
lo#lo-VirtualBox:~/Desktop$ mono --version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
From the master branch on mono on Github Console.cs:
[MonoLimitation ("Only works on windows")]
public static int WindowHeight {
get { return ConsoleDriver.WindowHeight; }
set { ConsoleDriver.WindowHeight = value; }
}
Notice the MonoLimitation attribute

How to Call an Application with Parameters in NPAPI for Mac

I try to create a simple NPAPI which passes an URL to Safari.
plugin_invoke method is below:
bool plugin_invoke(NPObject *obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
// Make sure the method called is "open".
NPUTF8 *name = npnfuncs->utf8fromidentifier(methodName);
if(strcmp(name, plugin_method_name_open) == 0) {
npnfuncs->memfree(name);
BOOLEAN_TO_NPVARIANT(false, *result);
// Meke sure the arugment has at least one String parameter.
if(argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
// Build CFURL object from the arugment.
NPString str = NPVARIANT_TO_STRING(args[0]);
CFURLRef url = CFURLCreateWithBytes(NULL, (const UInt8 *)str.UTF8Characters, str.UTF8Length, kCFStringEncodingUTF8, NULL);
if(url) {
// Open URL with the default application by Launch Service.
//OSStatus res = LSOpenCFURLRef(url, NULL);
//CFRelease(url);
OSStatus resultt = eventNotHandledErr;
//FSRef appRef;
FSRef appRef = {0};
Boolean isDir =true;
resultt = FSPathMakeRef((UInt8 *) "/Applications/Safari.app", &appRef,
&isDir);
LSApplicationParameters appParams = {0, kLSLaunchDefaults};
appParams.application = &appRef;
appParams.version = 0;
appParams.flags = kLSLaunchDefaults;
resultt = LSOpenApplication(&appParams, NULL);
BOOLEAN_TO_NPVARIANT(resultt == noErr, *result);
}
}
return true;
}
npnfuncs->memfree(name);
return false;
}
Currently it just invokes Safari but URL can not be passed.
How can I pass an example URL to the Safari in NPAPI? I read LSOpenFromURLSpec might work but I could not create the code.
Read the documentation for Launch Services, especially LSOpenURLsWithRole.
FYI, nothing about your question is NPAPI-specific, it's just about launching a Mac application from another process. In general you'll get more answers if you don't post general questions as NPAPI questions, since way more people know the answers to general Mac questions than to NPAPI-specific questions.