Object module_cuda_init() { if (cuda_module != NULL) return cuda_module; CudaError = alloc_Exception("CudaError", ErrorObject); gc_root(CudaError); ClassData c = alloc_class("Module<cuda>", 13); add_Method(c, "over()map", &cuda_over_map); add_Method(c, "floatArray", &cuda_floatArray); add_Method(c, "deviceName", &cuda_deviceName); add_Method(c, "computeCapability", &cuda_computeCapability); add_Method(c, "cores", &cuda_cores); add_Method(c, "using()do()blockWidth()blockHeight()gridWidth()gridHeight", &cuda_using_do_blockWidth_blockHeight_gridWidth_gridHeight); add_Method(c, "using()do", &cuda_using_do); add_Method(c, "using()times()do", &cuda_using_times_do); add_Method(c, "do", &cuda_do_infer); add_Method(c, "do()blockWidth()blockHeight()gridWidth()gridHeight", &cuda_do_dimensions_infer); add_Method(c, "bindir", &cuda_bindir); add_Method(c, "includedir", &cuda_includedir); Object o = alloc_newobj(0, c); cuda_module = o; gc_root(o); return o; }
// Create and return a grace object which contains the above functions Object module_math_init() { if (math_module != NULL) return math_module; srand(time(NULL)); ClassData c = alloc_class("Module<math>", 13); add_Method(c, "asString", &math_asString); add_Method(c, "asDebugString", &math_asDebugString); add_Method(c, "sin", &math_sin); add_Method(c, "cos", &math_cos); add_Method(c, "tan", &math_tan); add_Method(c, "asin", &math_asin); add_Method(c, "acos", &math_acos); add_Method(c, "atan", &math_atan); add_Method(c, "random", &math_random); add_Method(c, "pi", &math_pi); add_Method(c, "π", &math_pi); add_Method(c, "sqrt", &math_sqrt); add_Method(c, "abs", &math_abs); Object o = alloc_newobj(0, c); math_module = o; gc_root(math_module); return o; }
void add_class(struct RP_class *root, ea_t adr, size_t namelen) { if ( root->total == root->alloced ) root->children = (struct RP_class **)qrealloc(root->children, sizeof(struct RP_class *) * (root->alloced += RP_INCREMENT)); root->children[root->total++] = alloc_class(adr, namelen, root); if ( namelen > max_size ) max_size = namelen; }
/** * sysfs_open_class: opens specific class and all its devices on system * returns sysfs_class structure with success or NULL with error. */ struct sysfs_class *sysfs_open_class(const char *name) { struct sysfs_class *cls = NULL; char *c, classpath[SYSFS_PATH_MAX]; if (!name) { errno = EINVAL; return NULL; } memset(classpath, 0, SYSFS_PATH_MAX); if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0) { dprintf("Sysfs not supported on this system\n"); return NULL; } safestrcat(classpath, "/"); if (strcmp(name, SYSFS_BLOCK_NAME) == 0) { safestrcat(classpath, SYSFS_BLOCK_NAME); if (!sysfs_path_is_dir(classpath)) goto done; c = strrchr(classpath, '/'); *(c+1) = '\0'; } safestrcat(classpath, SYSFS_CLASS_NAME); safestrcat(classpath, "/"); safestrcat(classpath, name); done: if (sysfs_path_is_dir(classpath)) { dprintf("Class %s not found on the system\n", name); return NULL; } cls = alloc_class(); if (cls == NULL) { dprintf("calloc failed\n"); return NULL; } safestrcpy(cls->name, name); safestrcpy(cls->path, classpath); if ((sysfs_remove_trailing_slash(cls->path)) != 0) { dprintf("Invalid path to class device %s\n", cls->path); sysfs_close_class(cls); return NULL; } return cls; }
Object module_repl_init() { if (repl_module != NULL) return repl_module; ClassData c = alloc_class("Module<repl>", 12); add_Method(c, "asString", &Object_asString); add_Method(c, "registerVisitor", &repl_registerVisitor); add_Method(c, "createobject", &repl_createobject); add_Method(c, "addmethod", &repl_addmethod); Object o = alloc_newobj(0, c); repl_module = o; gc_root(repl_module); if (module_ast == NULL) module_ast = module_ast_init(); if (module_interactive == NULL) module_interactive = module_interactive_init(); return o; }
Object alloc_CudaFloatArray(int n) { if (!CudaFloatArray) { CudaFloatArray = alloc_class("CudaFloatArray", 4); add_Method(CudaFloatArray, "at", &cuda_FloatArray_at); add_Method(CudaFloatArray, "at()put", &cuda_FloatArray_at_put); add_Method(CudaFloatArray, "[]", &cuda_FloatArray_at); add_Method(CudaFloatArray, "[]:=", &cuda_FloatArray_at_put); } Object o = alloc_obj(sizeof(struct CudaFloatArray) - sizeof(struct Object) + sizeof(float) * n, CudaFloatArray); struct CudaFloatArray *a = (struct CudaFloatArray *)o; a->size = n; for (int i = 0; i < n; i++) { a->data[i] = 0.0f; } return o; }
static bool internal_build_rt_tree(ea_t adr) { /* check what we have */ ea_t root = find_root(adr & ~4, true); /* RT struct must be aligned on 4 bytes */ if ( NULL == root ) return false; if ( NULL != CObject ) classes_deinit(); /* make root class */ CObject = alloc_class(root, ROOT_LEN, NULL); make_RTStruct(root, ROOT_LEN); back_trace_rt(CObject); misc_buffer1 = (char *)qalloc(6 + max_size); /* 'vtbl_' + one for leading zero */ misc_buffer2 = (char *)qalloc(1 + max_size); sort_and_name_all(CObject); /* next fill linear array and sort it too */ rt_database = (struct RP_class **)qalloc(total_classes * sizeof(struct RP_class *)); filler_index = 0; fill_rt_database(CObject); qsort(rt_database, total_classes, sizeof(struct RP_class *), rt_compare_names); return true; }