本文整理汇总了C++中CHKERR函数的典型用法代码示例。如果您正苦于以下问题:C++ CHKERR函数的具体用法?C++ CHKERR怎么用?C++ CHKERR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CHKERR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_chunk_setup
void test_chunk_setup(cl_context context, cl_command_queue queue, size_t size, size_t offset, int isGPU)
{
if(size == 0)
return;
cl_mem* d_a = isGPU ? &dg_a : &dc_a;
cl_mem* d_b = isGPU ? &dg_b : &dc_b;
cl_mem_flags a_flags = CL_MEM_READ_WRITE;
cl_mem_flags b_flags = CL_MEM_READ_WRITE;
void* a_mem = NULL;
void* b_mem = NULL;
if(!isGPU)
{
a_flags |= CL_MEM_USE_HOST_PTR;
a_mem = h_a;
}
int err;
*d_a = clCreateBuffer(context, a_flags, sizeof(*h_a) * size, a_mem, &err);
CHKERR(err, "Failed to create chunk buffers!");
*d_b = clCreateBuffer(context, b_flags, sizeof(*h_b) * size, b_mem, &err);
CHKERR(err, "Failed to create chunk buffers!");
err = clEnqueueWriteBuffer(queue, *d_a, CL_FALSE, 0, sizeof(*h_a) * size, h_a + offset, 0, NULL, NULL);
CHKERR(err, "Failed to write chunk buffer A!");
}
示例2: CCMIOReadOptstr
ErrorCode ReadCCMIO::get_str_option(const char *opt_str, EntityHandle seth, Tag &tag,
CCMIOID node, const char *other_tag_name)
{
int len;
CCMIOError error = kCCMIONoErr;
std::vector<char> opt_string;
if (kCCMIONoErr != CCMIOReadOptstr(NULL, node, opt_str, &len, NULL))
return MB_SUCCESS;
opt_string.resize(len);
CCMIOReadOptstr(&error, node, opt_str, &len, &opt_string[0]);
ErrorCode rval = MB_SUCCESS;
if (!tag) {
rval = mbImpl->tag_get_handle( other_tag_name ? other_tag_name : opt_str,
NAME_TAG_SIZE, MB_TYPE_OPAQUE, tag,
MB_TAG_SPARSE|MB_TAG_CREAT );
CHKERR(rval, NULL);
}
if (opt_string.size() > NAME_TAG_SIZE) opt_string[NAME_TAG_SIZE-1] = '\0';
else (opt_string.resize(NAME_TAG_SIZE, '\0'));
rval = mbImpl->tag_set_data(tag, &seth, 1, &opt_string[0]);
CHKERR(rval, NULL);
return MB_SUCCESS;
}
示例3: create_kernel
cl_kernel create_kernel(const char* filename, const char* kernel, const cl_context context, const cl_device_id device)
{
cl_kernel kernel_compute;
// Create a command queue
cl_program program = createProgramFromSource(filename, context);
// Build the program executable
//int err = clBuildProgram(program, 1, &device, "-cl-opt-disable", NULL, NULL);
int err = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
if (err == CL_BUILD_PROGRAM_FAILURE)
{
char *log;
size_t logLen;
err = clGetProgramBuildInfo(program, device_id_gpu, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLen);
log = (char *) malloc(sizeof(char)*logLen);
err = clGetProgramBuildInfo(program, device_id_gpu, CL_PROGRAM_BUILD_LOG, logLen, (void *) log, NULL);
fprintf(stdout, "CL Error %d: Failed to build program! Log:\n%s", err, log);
free(log);
exit(1);
}
CHKERR(err, "Failed to build program!");
// Create the compute kernel in the program we wish to run
kernel_compute = clCreateKernel(program, kernel, &err);
CHKERR(err, "Failed to create a compute kernel!");
return kernel_compute;
}
示例4: Meta_SDcard_OP
void Meta_SDcard_OP(SDCARD_REQ *req, char *peer_buf, unsigned short peer_len)
{
SDCARD_CNF cnf;
int bufsz = 512;
char fname[512];
char buf[512];
unsigned char cid[16];
unsigned char csd[16];
memset(&cnf, 0, sizeof(SDCARD_CNF));
cnf.header.id = FT_SDCARD_CNF_ID;
cnf.header.token = req->header.token;
cnf.status = META_SUCCESS;
sprintf(fname, "%s/cid", path);
CHKERR(meta_sdcard_read_info(fname, buf, bufsz));
memcpy(cid,buf,16*sizeof(unsigned char));
sprintf(fname, "%s/csd", path);
CHKERR(meta_sdcard_read_info(fname, buf, bufsz));
memcpy(csd,buf,16*sizeof(unsigned char));
meta_sdcard_send_resp(&cnf);
return;
error:
cnf.status = META_FAILED;
meta_sdcard_send_resp(&cnf);
return;
}
示例5: Sm_list_clear
int Sm_list_clear(const char *fileName, int lineNbr, PsmPartition partition,
PsmAddress list, SmListDeleteFn deleteFn, void *arg)
{
CHKERR(partition);
CHKERR(list);
return wipeList(fileName, lineNbr, partition, list, deleteFn, arg, 0);
}
示例6: op_func_group
herr_t op_func_group (hid_t loc_id, const char* objname, const H5L_info_t* /*info*/, void* /*ppar*/) {
//struct param glopar;
struct param* ppar;
ppar = &glopar;
int err;
hid_t h5fi;
hid_t h5fo;
hid_t gid;
H5G_stat_t statbuf;
err = H5Gget_objinfo (loc_id, objname, 0, &statbuf); CHKERR(err);
/* if object is group, open containers, create group, iterate over datasets, close */
if (statbuf.type == H5G_GROUP) {
h5fi = H5Fopen(((struct param *)ppar)->conti, H5F_ACC_RDONLY, H5P_DEFAULT); CHKRTN(h5fi < 0, FILEERR);
h5fo = H5Fopen(((struct param *)ppar)->conto, H5F_ACC_RDWR, H5P_DEFAULT); CHKRTN(h5fo < 0, FILEERR);
gid = H5Gcreate(h5fo, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHKRTN(gid < 0, ERR);
strncpy(((struct param *)ppar)->grupi, objname, sizeof(((struct param *)ppar)->grupi) - 1);
strncpy(((struct param *)ppar)->grupo, objname, sizeof(((struct param *)ppar)->grupo) - 1);
err = H5Literate_by_name (h5fi, objname, H5_INDEX_NAME, H5_ITER_NATIVE, NULL, op_func_dset, (void *) ppar, NULL); CHKERR(err);
err = H5Fclose(h5fo); CHKERR(err);
err = H5Fclose(h5fi); CHKERR(err);
}
return EXIT_SUCCESS;
}
示例7: test_chunk_kernel
void test_chunk_kernel(cl_context context, cl_command_queue queue, cl_device_id device, cl_kernel kernel, size_t size, size_t offset, int isGPU)
{
if(size == 0)
return;
cl_mem* d_a = isGPU ? &dg_a : &dc_a;
cl_mem* d_b = isGPU ? &dg_b : &dc_b;
size_t chunk = isGPU ? 2 : size;
cl_event* event = isGPU ? &event_gpu : &event_cpu;
size_t local_size;
clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &local_size, NULL);
if(!isGPU)
local_size = 1;
int err = clSetKernelArg(kernel, 0, sizeof(cl_mem), d_a);
err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), d_b);
err |= clSetKernelArg(kernel, 2, sizeof(size_t), &size);
err |= clSetKernelArg(kernel, 3, sizeof(size_t), &chunk);
if(isGPU)
err |= clSetKernelArg(kernel, 4, sizeof(reduce_t) * local_size * 2, NULL);
CHKERR(err, "Errors setting kernel arguments");
size_t groups = size / local_size / chunk + (size % (local_size*chunk) == 0 ? 0 : 1);
size_t global_size = groups * local_size;
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global_size, &local_size, 0, NULL, event);
CHKERR(err, "Failed to run kernel!");
if(groups != 1)
{
cl_mem temp = *d_a;
*d_a = *d_b;
*d_b = temp;
test_chunk_kernel(context, queue, device, kernel, groups, offset, isGPU);
}
}
示例8: ocdBuildProgramFromFile
cl_program ocdBuildProgramFromFile(cl_context context,cl_device_id device_id,const char* kernel_file_name)
{
cl_int err;
cl_program program;
size_t kernelLength;
char* kernelSource;
FILE* kernel_fp;
size_t items_read;
#ifdef USE_AFPGA
const char* kernel_file_mode = "rb";
#else //CPU or GPU
const char* kernel_file_mode = "r";
#endif
kernel_fp = fopen(kernel_file_name, kernel_file_mode);
check(kernel_fp != NULL,"common_ocl.ocdBuildProgramFromFile() - Cannot open kernel file!");
fseek(kernel_fp, 0, SEEK_END);
kernelLength = (size_t) ftell(kernel_fp);
kernelSource = malloc(sizeof(char)*kernelLength);
check(kernelSource != NULL,"common_ocl.ocdBuildProgramFromFile() - Heap Overflow! Cannot allocate space for kernelSource.");
rewind(kernel_fp);
items_read = fread((void *) kernelSource, kernelLength, 1, kernel_fp);
check(items_read == 1,"common_ocl.ocdBuildProgramFromFile() - Error reading from kernelFile");
fclose(kernel_fp);
/* Create the compute program from the source buffer */
#ifdef USE_AFPGA //use Altera FPGA
program = clCreateProgramWithBinary(context,1,&device_id,&kernelLength,(const unsigned char**)&kernelSource,NULL,&err);
#else //CPU or GPU
program = clCreateProgramWithSource(context, 1, (const char **) &kernelSource, &kernelLength, &err);
#endif
CHKERR(err, "common_ocl.ocdBuildProgramFromFile() - Failed to create a compute program!");
/* Build the program executable */
#ifdef USE_AFPGA //use Altera FPGA
err = clBuildProgram(program,1,&device_id,"-DOPENCL -I.",NULL,NULL);
#else
err = clBuildProgram(program, 0, NULL, "-DOPENCL -I.", NULL, NULL);
#endif
if (err == CL_BUILD_PROGRAM_FAILURE)
{
char *buildLog;
size_t logLen;
err = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLen);
buildLog = (char *) malloc(sizeof(char)*logLen);
check(buildLog != NULL,"common_ocl.ocdBuildProgramFromFile() - Heap Overflow! Cannot allocate space for buildLog.");
err = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, logLen, (void *) buildLog, NULL);
fprintf(stderr, "CL Error %d: Failed to build program! Log:\n%s", err, buildLog);
free(buildLog);
exit(1);
}
CHKERR(err,"common_ocl.ocdBuildProgramFromFile() - Failed to build program!");
free(kernelSource); /* Free kernel source */
return program;
}
示例9: map_vecs_Sprimme
TEMPLATE_PLEASE
int map_vecs_Sprimme(HSCALAR *V, int m, int nV, int ldV, HSCALAR *W, int n0,
int n, int ldW, int *p, primme_context ctx) {
int i; /* Loop variable */
/* Compute the norm of the columns V(n0:n-1) */
HREAL *Vnorms = NULL;
CHKERR(Num_malloc_RHprimme(nV, &Vnorms, ctx));
for (i = 0; i < nV; i++) {
Vnorms[i] = sqrt(REAL_PART(
Num_dot_SHprimme(m, &V[ldV * i], 1, &V[ldV * i], 1, ctx)));
}
/* Compute V'*W[n0:n-1] */
HSCALAR *ip = NULL;
CHKERR(Num_malloc_SHprimme(nV * (n - n0), &ip, ctx));
Num_zero_matrix_SHprimme(ip, nV, n - n0, nV, ctx);
CHKERR(Num_gemm_SHprimme("C", "N", nV, n - n0, m, 1.0, V, ldV, &W[ldW * n0],
ldW, 0.0, ip, nV, ctx));
for (i = n0; i < n; i++) {
/* Find the j that maximizes ABS(V[j]'*W[i]/Vnorms[j]) and is not */
/* in p(0:i-1) */
int j, jmax=-1;
HREAL ipmax = -1;
for (j = 0; j < nV; j++) {
HREAL ipij = ABS(ip[nV * (i - n0) + j]);
if (ipij > ipmax * Vnorms[j]) {
/* Check that j is not in p(0:i-1) */
int k;
for (k = 0; k < i && p[k] != j; k++)
;
if (k < i) continue;
/* Update ipmax and jmax */
ipmax = fabs(ipij / Vnorms[j]);
jmax = j;
}
}
if (jmax < 0) {
jmax = i;
}
/* Assign the map */
p[i] = jmax;
}
CHKERR(Num_free_RHprimme(Vnorms, ctx));
CHKERR(Num_free_SHprimme(ip, ctx));
return 0;
}
示例10: sm_list_prev
PsmAddress sm_list_prev(PsmPartition partition, PsmAddress elt)
{
SmListElt *eltBuffer;
CHKERR(partition);
CHKERR(elt);
eltBuffer = (SmListElt *) psp(partition, elt);
CHKERR(eltBuffer);
return eltBuffer->prev;
}
示例11: ltpei_parse_extension
int ltpei_parse_extension(char **cursor, int *bytesRemaining, Lyst exts,
unsigned int *extensionOffset)
{
char *initialCursor;
LtpExtensionInbound *extField;
unsigned int valueLength;
CHKERR(cursor);
CHKERR(*cursor);
CHKERR(bytesRemaining);
CHKERR(exts);
if ((*bytesRemaining) < 1)
{
return 0; /* Corrupt. */
}
extField = MTAKE(sizeof(LtpExtensionInbound));
if (extField == NULL)
{
return -1; /* Give up. */
}
initialCursor = *cursor;
extField->offset = *extensionOffset;
extField->tag = **cursor;
(*cursor)++;
(*bytesRemaining)--;
extractSmallSdnv(&valueLength, cursor, bytesRemaining);
if (valueLength == 0 || *bytesRemaining < valueLength)
{
return 0; /* Corrupt. */
}
extField->length = valueLength;
extField->value = MTAKE(valueLength);
if (extField->value == 0)
{
MRELEASE(extField);
return -1; /* Give up. */
}
memcpy(extField->value, *cursor, valueLength);
(*cursor) += valueLength;
(*bytesRemaining) -= valueLength;
if (lyst_insert_last(exts, extField) == NULL)
{
MRELEASE(extField->value);
MRELEASE(extField);
return -1; /* Give up. */
}
*extensionOffset += ((*cursor) - initialCursor);
return 1;
}
示例12: dtn2_updateRule
int dtn2_updateRule(char *nodeNm, char *demux, FwdDirective *directive)
{
Sdr sdr = getIonsdr();
char nodeName[SDRSTRING_BUFSZ];
Object elt;
OBJ_POINTER(Dtn2Plan, plan);
Object ruleAddr;
Dtn2Rule ruleBuf;
CHKERR(nodeNm && demux && directive);
if (*demux == '\0')
{
writeMemo("[?] Zero-length DTN2 rule demux.");
return 0;
}
if (filterNodeName(nodeName, nodeNm) < 0)
{
return 0;
}
CHKERR(sdr_begin_xn(sdr));
elt = locatePlan(nodeName, NULL);
if (elt == 0)
{
sdr_exit_xn(sdr);
writeMemoNote("[?] No plan defined for this node", nodeNm);
return 0;
}
GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt));
dtn2_findRule(nodeName, demux, plan, &ruleAddr, &elt);
if (elt == 0)
{
sdr_exit_xn(sdr);
writeMemoNote("[?] Unknown rule", demux);
return 0;
}
/* All parameters validated, okay to update the rule. */
sdr_stage(sdr, (char *) &ruleBuf, ruleAddr, sizeof(Dtn2Rule));
dtn2_destroyDirective(&ruleBuf.directive);
memcpy((char *) &ruleBuf.directive, (char *) directive,
sizeof(FwdDirective));
sdr_write(sdr, ruleAddr, (char *) &ruleBuf, sizeof(Dtn2Rule));
if (sdr_end_xn(sdr) < 0)
{
putErrmsg("Can't update rule.", NULL);
return -1;
}
return 1;
}
示例13: CCMIOSIZEC
ErrorCode ReadCCMIO::read_all_faces(CCMIOID topologyID, TupleList &vert_map,
TupleList &face_map
#ifndef TUPLE_LIST
,SenseList &sense_map
#endif
, Range *new_faces)
{
CCMIOSize_t index = CCMIOSIZEC(0);
CCMIOID faceID;
ErrorCode rval;
// get total # internal/bdy faces, size the face map accordingly
int nint_faces = 0, nbdy_faces = 0;
CCMIOSize_t nf;
CCMIOError error = kCCMIONoErr;
while (kCCMIONoErr == CCMIONextEntity(NULL, topologyID, kCCMIOBoundaryFaces, &index,
&faceID))
{
CCMIOEntitySize(&error, faceID, &nf, NULL);
nbdy_faces = nbdy_faces + nf;
}
CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID);
CCMIOEntitySize(&error, faceID, &nf, NULL);
nint_faces = nint_faces + nf;
#ifdef TUPLE_LIST
face_map.resize(2*nint_faces + nbdy_faces);
#endif
// get multiple blocks of bdy faces
index = CCMIOSIZEC(0);
while (kCCMIONoErr == CCMIONextEntity(NULL, topologyID, kCCMIOBoundaryFaces, &index,
&faceID))
{
rval = read_faces(faceID, kCCMIOBoundaryFaces, vert_map, face_map
#ifndef TUPLE_LIST
, sense_map
#endif
, new_faces);
CHKERR(rval, "Trouble reading boundary faces.");
}
// now get internal faces
CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID);
rval = read_faces(faceID, kCCMIOInternalFaces, vert_map,face_map
#ifndef TUPLE_LIST
, sense_map
#endif
, new_faces);
CHKERR(rval, "Trouble reading internal faces.");
return rval;
}
示例14: dtn2_removeRule
int dtn2_removeRule(char *nodeNm, char *demux)
{
Sdr sdr = getIonsdr();
char nodeName[SDRSTRING_BUFSZ];
Object elt;
OBJ_POINTER(Dtn2Plan, plan);
Object ruleAddr;
OBJ_POINTER(Dtn2Rule, rule);
CHKERR(nodeNm && demux);
if (*demux == '\0')
{
writeMemo("[?] Zero-length DTN2 rule demux.");
return 0;
}
if (filterNodeName(nodeName, nodeNm) < 0)
{
return 0;
}
CHKERR(sdr_begin_xn(sdr));
elt = locatePlan(nodeName, NULL);
if (elt == 0)
{
sdr_exit_xn(sdr);
writeMemoNote("[?] No plan defined for this node", nodeNm);
return 0;
}
GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt));
dtn2_findRule(nodeName, demux, plan, &ruleAddr, &elt);
if (elt == 0)
{
sdr_exit_xn(sdr);
writeMemoNote("[?] Unknown rule", demux);
return 0;
}
/* All parameters validated, okay to remove the rule. */
GET_OBJ_POINTER(sdr, Dtn2Rule, rule, ruleAddr);
dtn2_destroyDirective(&(rule->directive));
sdr_free(sdr, ruleAddr);
sdr_list_delete(sdr, elt, NULL, NULL);
if (sdr_end_xn(sdr) < 0)
{
putErrmsg("Can't remove rule.", NULL);
return -1;
}
return 1;
}
示例15: ltpei_add_xmit_trailer_extension
int ltpei_add_xmit_trailer_extension(LtpXmitSeg *segment, char tag,
int valueLength, char *value)
{
Sdr sdr = getIonsdr();
Sdnv sdnv;
LtpExtensionOutbound extension;
Object addr;
CHKERR(segment);
CHKERR(ionLocked());
encodeSdnv(&sdnv, valueLength);
if (segment->pdu.trailerExtensions == 0)
{
if ((segment->pdu.trailerExtensions = sdr_list_create(sdr))
== 0)
{
return -1; /* No space in SDR heap. */
}
}
extension.tag = tag;
extension.length = valueLength;
if (valueLength == 0)
{
extension.value = 0;
}
else
{
CHKERR(value);
extension.value = sdr_insert(sdr, value, valueLength);
if (extension.value == 0)
{
return -1; /* No space in SDR heap. */
}
}
if ((addr = sdr_insert(sdr, (char *) &extension,
sizeof(LtpExtensionOutbound))) == 0)
{
return -1; /* No space in SDR heap. */
}
if (sdr_list_insert_last(sdr, segment->pdu.trailerExtensions, addr)
== 0)
{
return -1; /* No space in SDR heap. */
}
segment->pdu.trailerExtensionsCount++;
segment->pdu.trailerLength += (1 + sdnv.length + valueLength);
return 0;
}