What should I set the flags field of CUDA_BATCH_MEM_OP_NODE_PARAMS? - cuda

The CUDA graph API exposes a function call for adding a "batch memory operations" node to a graph:
CUresult cuGraphAddBatchMemOpNode (
CUgraphNode* phGraphNode,
CUgraph hGraph,
const CUgraphNode* dependencies,
size_t numDependencies,
const CUDA_BATCH_MEM_OP_NODE_PARAMS* nodeParams
);
but the documentation for this API call does not explain what the flags field of ... is used for, and what one should set the flags to. So what value should I be passing?

A related API function is cuStreamBatchMemOp
CUresult cuStreamBatchMemOp (
CUstream stream,
unsigned int count,
CUstreamBatchMemOpParams* paramArray,
unsigned int flags
);
it essentially takes the fields of CUDA_BATCH_MEM_OP_NODE_PARAMS as its separate parameters. Its documentation says that flags is "reserved for future expansion; must be 0".

Related

How to use Critcl ByteArray?

I want to try out Critcl to enhance memory performance using a Z-order curve for a 2d-grid. What I need from Critcl is allocation, setter, getter and some size info. Reading about the Critcl ByteArray and examples does not make me confident on how to do it.
How do I create and return a ByteArray (i.e. Z-order curve)?
Any caveats I should know about when using ByteArray?
According to the documentation, you should be using the bytes type instead (when you get a pointer to a structure that has a len field with the number of bytes in it, and an s field that is the pointer to the actual read only block of bytes. (As a char * and not an unsigned char * for reasons I don't know. And why it isn't const is another mystery to me; there are cases where that's indeed true, but you need to look at the o field to figure that out.)
To return a byte array, you use the object (or object0) result type, and make the object with, for example, Tcl_NewByteArrayObj(), or Tcl_NewObj() and Tcl_SetByteArrayLength().
Here's an example (just the command definition) that does trivial byte reversing (since I don't understand Z-order curves at all):
critcl::cproc example {bytes dataPtr} object0 {
Tcl_Obj *result = Tcl_NewObj();
unsigned char *targetBytes = Tcl_SetByteArrayLength(result, dataPtr->len);
for (int i = 0, j = dataPtr->len - 1; j >= 0; i++, j--) {
targetBytes[i] = (unsigned byte) dataPtr->s[j];
}
return result;
}
Naturally, you'll want to read the Critcl usage guide when getting this to work, and if you're going to produce errors (by returning NULL), remember to set an error message in the interpreter. You can get access to that by using Tcl_Interp* interp as your first pseudo-argument to the command you create with critcl::cproc (it's documented, but easily missed).

Uppaal template parameters

I am using UPPAAL 4.1.19 and I am following the train tutorial, given in this. In Train template, I put the parameters int[0,N] e, const int id and in the system declaration I declare Train1=Train(el, 1); and the system returns me "Incompatible argument" error for e1. I don't understand why it is actually incompatible? I have declared N as a constant equal to 5 in the global declarations, as well as el, but still it doesn't seem to work. Any idea?
Try int[0,N] &e, const int id, similarly as here (page 6): https://www.it.uu.se/research/group/darts/uppaal/small_tutorial.pdf.

Is there any way to declare a function that can take both an int and a double as it's argument in MQL4?

I have these two functions:
void CheckOneConditionInt( int &SettingsEditValueInt );
void CheckOneConditionDbl( double &SettingsEditValueDbl );
They do the same stuff, but one is used with int values and another is used with double values. Is there any way to make it one function that can take int/double as an argument? For example:
void CheckOneCondition( void &SettingsEditValue );
PS: The example does not work of course.
Have you heard about method overloading? It is used in MQL4.5.
So, if you pass int value then Function( int value ) is called, if real - then Function( double value ) is called. If the algorithm applied to both types is same - maybe you can just skip Function( int value ), or add a wrapper inside the integer function, something like:
Function( int &value ){
double tmp = value/1.0;
Function( tmp );
value = ( int ) Normalize( tmp, 0 );
}
Yes and No.
While the New-MQL4.56789 extensions have introduced classes ( inside which there are means for multiple calling interfaces ( where one could being suited for double and another for int ), which could mean YES ),the MQL4 is in its initial design principles a compiled language with strong typing,which means NO.
Design decision rules
A sound and clear desing can answer the dilemma. There is no principal reason to have ambiguous, dual-typed calling interface in MQL4 problem domain.
Except for some theoretical experimentation, there is always a deterministic certainty, of what type the value to be passed to a function is, thus an amorphous dual-(multi)-typed calling interface is moreless an academical subject in MQL4 context of use.
Epilogue
If one indeed seeks for such an extremely artificial geekiness to achieve such non-deterministic agnosticism, let's first define a clear MQL4-domain use-case, for which such uncertaintiness of parameter type is both necessary and un-avoidable by other, available, means.
The problem is solved by using templates:
template<typename T>
void CheckOneCondition( T &SettingsEditValue );
I can then call it passing double or int parameter.

C MySQL Types Error

I'm trying to store results taken from a MySQL query into an array of structs. I can't seem to get the types to work though, and I've found the MySQL documentation difficult to sort through.
My struct is:
struct login_session
{
char* user[10];
time_t time;
int length;
};
And the loop where I'm trying to get the data is:
while ( (row = mysql_fetch_row(res)) != NULL ) {
strcpy(records[cnt].user, &row[0]);
cnt++;
}
No matter what I try though I constantly get the error:
test.c:45: warning: passing argument 1 of ‘strcpy’ from incompatible pointer type
/usr/include/string.h:128: note: expected ‘char * __restrict__’ but argument is of type ‘char **’
test.c:45: warning: passing argument 2 of ‘strcpy’ from incompatible pointer type
/usr/include/string.h:128: note: expected ‘const char * __restrict__’ but argument is of type ‘MYSQL_ROW’
Any pointers?
Multiple problems, all related to pointers and arrays, I recommend you do some reading.
First, char * user[10] is defining an array of 10 char * values, not an array of char, which is was I suspect you want. The warning even says as much, strcpy() expects a char *, the user field on its own is seen as a char **.
Second, you're one & away from what you want in the second argument.
Copied from mysql.h header:
typedef char **MYSQL_ROW; /* return data as array of strings */
A MYSQL_ROW is an array of char arrays. Using [] does a dereference, so you dereference down to a char * which is what strcpy() takes, but then you take the address of it using &.
Your code should look more like this:
struct login_session
{
char user[10];
time_t time;
int length;
};
while ( (row = mysql_fetch_row(res)) != NULL ) {
strcpy(records[cnt].user, row[0]);
cnt++;
}
I don't know what guarantees you have about the data coming from mysql, but if you can't be absolutely sure that the rows are <= 10 characters long and null ('\0') terminated, you should use strncpy() to avoid any possibility of overflowing the user array.

tcllib Tcl_CreateObjTrace usage example

Does anyone have an example of how to use Tcl_CreateObjTrace? This is the procedure to add Tcl calls tracing to the C code using TclLib.
My main problem is this: I'm trying to develop a tracer for my Tcl code. However, I'd like to trace only my own procedures. The following code works:
static int
tcl_tracer( ClientData clientData,
Tcl_Interp* interp,
int level,
CONST char* command,
Tcl_Command commandToken,
int objc, Tcl_Obj *CONST objv[])
{
int param_length = 0;
CONST char *param_str = NULL;
int i;
/**
* The first three parameters represent the procedure
*/
if (objc < 2) {
printf("Invalid number of parameters for the tracer: %d\n", objc);
return TCL_OK;
}
param_str = Tcl_GetStringFromObj(objv[0], &param_length);
printf("%d:%s ", 0, param_str);
param_str = Tcl_GetStringFromObj(objv[1], &param_length);
printf("%d:%s ", 1, param_str);
param_str = Tcl_GetStringFromObj(objv[2], &param_length);
printf("%d:%s ", 2, param_str);
printf("\n");
return TCL_OK;
}
However, it traces all procedures. It traces 'puts', 'set', etc.
Is there any way to avoid that? There is a parameter to specify the level of tracing. But I don't know beforehand how many levels deep my code may run.
Much appreciated.
-Ilya.
As that page mentions, setting the flags parameter of the Tcl_CreateObjTrace call to TCL_ALLOW_INLINE_COMPILATION will disable the most intrusive level of tracing (in particular, many common core commands are bytecode compiled as normal with that flag set).
That said, it is substantially easier to hook into this mechanism from the Tcl level through trace add execution; setting an enter trace on each command you're interested in (sorry, you'll have to list them) should do the trick. (This works because the trace internals can turn off a lot of the cost in a way your code can't. This is fairly tricky, and one of the reasons I hate dealing with the trace command implementation.)