Error- a __global__ function call must be configured - parallel-processing

I am writing a code for Big Integer Addition, Subtraction, Multiplication and Division. But while compiling the code, I am getting this error, along with another error error: a __global__ function must have a void return type.
The code is 700 lines long and there are errors are multiple lines. Hence for convenience, I am attaching a link of my Google Colab notebook. Please check it here
And here is the error I am getting
/content/src/omp_cuda80.cu(94): error: a __global__ function must have a void return type
/content/src/omp_cuda80.cu(139): warning: missing return statement at end of non-void function "addition"
/content/src/omp_cuda80.cu(265): warning: variable "n" was declared but never referenced
/content/src/omp_cuda80.cu(367): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(381): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(390): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(442): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(456): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(465): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(533): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(538): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(548): error: a __global__ function call must be configured
/content/src/omp_cuda80.cu(553): error: a __global__ function call must be configured
11 errors detected in the compilation of "/content/src/omp_cuda80.cu".
/bin/bash: /content/src/omp_cuda80: No such file or directory

If you define a CUDA function using __global__ you need to call it with the syntax
function<<<grid,block>>>(param1,param2,...);
You are calling them as
function(param1,param2,...);
That is why you get a __global__ function call must be configured.
GPU functions also do not return a value, they must return void. You can get the return value in a pointer, and the copy it to CPU to inspect it if needed. There are other ways also, but it goes beyond the scope of this answer.

Related

Use of bind function in boost.asio server example

In boost.asio example of asynchronous UDP server we can find next code:
void start_receive()
{
socket_.async_receive_from(
boost::asio::buffer(recv_buffer_), remote_endpoint_,
boost::bind(&udp_server::handle_receive, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
..........
void handle_receive(const boost::system::error_code& error,
std::size_t /*bytes_transferred*/)
According to specification of basic_datagram_socket::async_receive_from function, its prototype is
template<
typename MutableBufferSequence,
typename ReadToken = DEFAULT>
DEDUCED async_receive_from(
const MutableBufferSequence & buffers,
endpoint_type & sender_endpoint,
ReadToken && token = DEFAULT);
when token may be a function with prototype
void handler(
const boost::system::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes received.
);
I do not understand two things (at least)
How bind work here? It accept handle_receive pointer, udp_server object (what for?) and two placeholders. How does it turn to function that is called at the end of asynchronous call and get context varibles?
How does handle_receive function access a recv_buffer_ which is an argument of async_receive_from function but not of handle_receive?
Bind returns a bound function object. There's extensive documentation about how it works and why you'd use it:
https://www.boost.org/doc/libs/1_77_0/libs/bind/doc/html/bind.html
also see https://en.cppreference.com/w/cpp/utility/functional/bind
udp_server object (what for?)
(Non-static) member functions take an implicit this pointer argument to the class instance (object). So a 2-argument non-static member function void X::foo(int,int) consttakes 3 arguments:X const*, int, int`.
How does handle_receive function access a recv_buffer_ which is an argument of async_receive_from function but not of handle_receive?
recv_buffer_ is a data member of the same class (udp_server), so in handle_receive it is implicitly accessing it as this->recv_buffer_. This is very elementary C++, so I recommend maybe reading a good introduction or book if this is new for you.

how to resolve module marked permanent in LKM

I have written a simple jiffies code and when I try to do rmmod I get
ERROR: Removing 'jiffi_module': Device or resource busy
so I did bit of research and found by doing lsmod below symptom of "permanent" being the problem which is caused by exit_function not being found.
Module Size Used by
jiffi_module 1027 0 **[permanent]**
infact my make file do show me warning related to exit function
Warning when exit function is defined as
static void __exit
jif_exit(void)
{
remove_proc_entry("jif", NULL);
}
warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘modile_exit’
warning: parameter names (without types) in function declaration
warning: ‘jif_exit’ defined but not used
when I remove the __exit seems it atleast identifies jif_exit - so now the warning I get is
warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘modile_exit’
warning: parameter names (without types) in function declaration
Reading through below Why is this kernel module marked at permanent on 2.6.39
it talks about gcc mismatch being a problem ? Can someone please help I am not able to debug it further ? Any pointers how to load module properly such that its not permanent?
Kernel module is marked as permanent (cannot be unloaded) if there is no exit function is defined for it.
exit function accepts no arguments and return nothing and should be defined either with predefined name
void cleanup_module(void)
{
...
}
or with arbitrary name but registered with module_exit macro
void <func_name>(void)
{
...
}
module_exit(<func_name>);
static, __exit and other attributes for exit function are optional.

gcc warnings: defined but not used vs unused variable

Whenever I compile my code I observe following two warnings:
warning: '<variable>' defined but not used
warning: unused variable '<variable>'
I tried to google but I did not find any helpful thread or blog about what is the difference between these two warnings.
Example with some sample code snippet will do for me or if am duplicating some existing thread please feel free to refer.
I think the difference is kind of subtle but here is the code snippet along with the compiler output that demonstrates some differences:
#include <iostream>
static const char * hello = "Hello";
void foo() {
int i;
std::cout << "foo" << std::endl;
}
...
argenet#Martell ~ % g++ /tmp/def_not_used.cpp -Wall
/tmp/def_not_used.cpp: In function ‘void foo()’:
/tmp/def_not_used.cpp:6:9: warning: unused variable ‘i’ [-Wunused-variable]
int i;
^
/tmp/def_not_used.cpp: At global scope:
/tmp/def_not_used.cpp:3:21: warning: ‘hello’ defined but not used [-Wunused-variable]
static const char * hello = "Hello";
So here the local variable is never used, therefore the compiler may simply omit it while generating the code and it emits an "unused variable" warning.
At the same time, the static C-style literal cannot be omitted that easily as it is available for a wider scope (the whole .cpp file).
However, it is not referenced by any code in this module so the compiler warns about it like "defined but not used".

c++0x lambdas, not letting me pass as function ptr

I am currently writing a program in C++0x which I am fairly new to.
I am setting up callbacks between objects and using lambda to match the types (like boost::bind() does in ways)
If I call a function in the asio library like:
socket_.async_read_some(buffer(&(pBuf->front()), szBuffer),
[=](const boost::system::error_code &error, size_t byTrans) {
this->doneRead(callBack, pBuf, error, byTrans); });
This compiles fine, and runs as expected, 'doneRead' is called back from 'async_read_some'
so I have a similar call back in my own code:
client->asyncRead([=](string msg){this->newMsg(msg); });
This takes just a string, and asyncReads prototype is as follows
void ClientConnection::asyncRead(void(*callBack)(string))
But I get this compile error:
Server.cpp: In member function ‘void
Server::clientAccepted(std::shared_ptr,
const boost::system::error_code&)’:
Server.cpp:31:3: error: no matching
function for call to
‘ClientConnection::asyncRead(Server::clientAccepted(std::shared_ptr,
const
boost::system::error_code&)::)’
Server.cpp:31:3: note: candidate is:
ClientConnection.h:16:9: note: void
ClientConnection::asyncRead(void
(*)(std::string))
ClientConnection.h:16:9: note: no
known conversion for argument 1 from
‘Server::clientAccepted(std::shared_ptr,
const
boost::system::error_code&)::’
to ‘void (*)(std::string)’
How can this issue be resolved?
Your lambda captures this implicitly. A lambda that captures things cannot convert to a raw function pointer.
So you need to write asyncRead so it accepts the lambda function object directly, instead of letting it convert to a function pointer
template<typename CallbackType>
void ClientConnection::asyncRead(CallbackType callback);
Alternatively, if you don't want to write this as a template, you can use a polymorphic function object wrapper
void ClientConnection::asyncRead(std::function<void(string)> callBack);
I would also consider changing the callback's interface so it accepts the string by const reference (unless all the callback implementations inherently want to modify or save/move the passed string internally, which seem unlikely in your case).

V8 compilation problems

I'm trying to compile a file with the V8 the JavaScript Engine by Google. I installed scons and have compiled the V8 engine. But, here is where the problem lies, I stay in the V8 directory as they say and make a file named hello_world.cpp with the code:
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Create a new context.
Persistent<Context> context = Context::New();
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::New("'Hello' + ', World!'");
// Compile the source code.
Handle<Script> script = Script::Compile(source);
// Run the script to get the result.
Handle<Value> result = script->Run();
// Dispose the persistent context.
context.Dispose();
// Convert the result to an ASCII string and print it.
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;
}
Then I compile using gcc hello_world.cpp -o libv8.a. But, when I compile it I get a skew of errors:
hello_world.cpp:1:16: error: v8.h: No such file or directory
hello_world.cpp:3: error: ‘v8’ is not a namespace-name
hello_world.cpp:3: error: expected namespace-name before ‘;’ token
hello_world.cpp: In function ‘int main(int, char**)’:
hello_world.cpp:8: error: ‘HandleScope’ was not declared in this scope
hello_world.cpp:8: error: expected `;' before ‘handle_scope’
hello_world.cpp:11: error: ‘Persistent’ was not declared in this scope
hello_world.cpp:11: error: ‘Context’ was not declared in this scope
hello_world.cpp:11: error: ‘context’ was not declared in this scope
hello_world.cpp:11: error: ‘Context’ is not a class or namespace
hello_world.cpp:15: error: ‘Context’ is not a class or namespace
hello_world.cpp:15: error: expected `;' before ‘context_scope’
hello_world.cpp:18: error: ‘Handle’ was not declared in this scope
hello_world.cpp:18: error: ‘String’ was not declared in this scope
hello_world.cpp:18: error: ‘source’ was not declared in this scope
hello_world.cpp:18: error: ‘String’ is not a class or namespace
hello_world.cpp:21: error: ‘Script’ was not declared in this scope
hello_world.cpp:21: error: ‘script’ was not declared in this scope
hello_world.cpp:21: error: ‘Script’ is not a class or namespace
hello_world.cpp:24: error: ‘Value’ was not declared in this scope
hello_world.cpp:24: error: ‘result’ was not declared in this scope
hello_world.cpp:30: error: ‘String’ is not a class or namespace
hello_world.cpp:30: error: expected `;' before ‘ascii’
hello_world.cpp:31: error: ‘ascii’ was not declared in this scope
hello_world.cpp:31: error: ‘printf’ was not declared in this scope
I don't get why it say V8.h is not declared. I already built it and I'm in its directory and I'm guessing if I get rid of that all the other errors will go away. Any suggestions?
i just believe you in that you are really inside the toplevel source directory (and since i do not have compiled v8 i only believe that libvp8.a is created in that toplevel directory):
% g++ -Iinclude hello_world.cpp -o hello_world libv8.a
it says "v8.h" is not declared because that file is inside the "include" directory and the preprocessor is not able to find it out of thin air.
furthermore: you are compiling a .cpp file with the C compiler instead of the C++ compiler.
you are using the '-o' flag wrong because it defines the name of the linked binary and thus needs a name, you do not want the output binary be named "libvp8.a"

Resources