Exemple #1
0
void RosterDBManager::updateSubjectGroup(Group *g)
{
    QSqlQuery gquery(db);

    gquery.prepare("update roster set subject_timestamp=:subject_timestamp, "
                   "subject_owner=:subject_owner, "
                   "subject_owner_name=:subject_owner_name where jid=:jid");

    gquery.bindValue(":jid",g->jid);
    gquery.bindValue(":subject_timestamp",g->subjectTimestamp);
    gquery.bindValue(":subject_owner",g->subjectOwner);
    gquery.bindValue(":subject_owner_name",g->subjectOwnerName);

    gquery.exec();
}
Exemple #2
0
void RosterDBManager::updateContact(Contact *c)
{
    QSqlQuery query(db);

    query.exec("BEGIN TRANSACTION");

    query.prepare("select jid from roster "
                  "where jid = :jid");
    query.bindValue(":jid",c->jid);

    query.exec();

    if (query.next() && query.value(0).toString() == c->jid)
    {
        // Update contact
        query.prepare("update roster set name=:name, type=:type, alias=:alias,"
                      "phone=:phone, status=:status, blocked=:blocked, "
                      "status_timestamp=:status_timestamp, last_seen=:last_seen,"
                      "from_abook=:from_abook where jid=:jid");
    }
    else
    {
        // New contact

        query.prepare("insert into roster "
                      "(jid, name, alias, type, phone, status, status_timestamp, "
                      "last_seen, from_abook, blocked) "
                      "values "
                      "(:jid, :name, :alias, :type, :phone, :status, :status_timestamp, "
                      ":last_seen, :from_abook, :blocked)");
    }

    query.bindValue(":jid",c->jid);
    query.bindValue(":name",c->name);
    query.bindValue(":type",c->type);
    query.bindValue(":alias",c->alias);
    query.bindValue(":from_abook",c->fromAddressBook);
    query.bindValue(":phone", (c->phone.isEmpty())
                    ? QString("+" + c->jid.left(c->jid.indexOf("@")))
                    : c->phone);
    query.bindValue(":status",c->status);
    query.bindValue(":status_timestamp",c->statusTimestamp);
    query.bindValue(":last_seen",c->lastSeen);
    query.bindValue(":blocked",c->blocked);

    /*
    QByteArray bytes;
    QBuffer buffer(&bytes);
    buffer.open(QIODevice::WriteOnly);
    c->photo.save(&buffer, "PNG");

    query.bindValue(":photo",bytes);
    */

    query.exec();

    if (c->type == Contact::TypeGroup)
    {
        QSqlQuery gquery(db);
        Group *g = (Group *)c;
        gquery.prepare("update roster set creation_timestamp=:creation_timestamp, "
                       "author=:author, subject_timestamp=:subject_timestamp, "
                       "subject_owner=:subject_owner, "
                       "subject_owner_name=:subject_owner_name where jid=:jid");

        gquery.bindValue(":jid",g->jid);
        gquery.bindValue(":creation_timestamp",g->creationTimestamp);
        gquery.bindValue(":author",g->author);
        gquery.bindValue(":subject_timestamp",g->subjectTimestamp);
        gquery.bindValue(":subject_owner",g->subjectOwner);
        gquery.bindValue(":subject_owner_name",g->subjectOwnerName);

        gquery.exec();
    }
    query.exec("END TRANSACTION");

}
Exemple #3
0
int gdev_test_matrixadd(uint32_t *a, uint32_t *b, uint32_t *c, int n)
{
	int i, j, idx;
	uint32_t id;
	uint32_t mp_count;
	uint32_t code_size, a_size, b_size, c_size;
	uint32_t param_buf[PARAM_SIZE];
	uint64_t a_addr, b_addr, c_addr;
	uint64_t result[3];

	Ghandle handle;
	struct gdev_kernel k;

	/* initialize A[] & B[] */
	for (i = 0; i < n; i++) {
		for(j = 0; j < n; j++) {
			idx = i * n + j;
			a[idx] = i;
			b[idx] = j;
		}
	}

	if (!(handle = gopen(0))) {
		return -1;
	}
	
	a_size = n * n * sizeof(uint32_t);
	b_size = n * n * sizeof(uint32_t);
	c_size = n * n * sizeof(uint32_t);

	if (!(a_addr = gmalloc(handle, a_size)))
		return -1;
	if (!(b_addr = gmalloc(handle, b_size)))
		return -1;
	if (!(c_addr = gmalloc(handle, c_size)))
		return -1;

	code_size = sizeof(kcode);
	if (code_size & 0xff)
		k.code_size = (code_size + 0x100) & ~0xff;
	if (!(k.code_addr = gmalloc(handle, k.code_size)))
		return -1;
	k.code_pc = 0;

	k.cmem[0].size = PARAM_SIZE;
	if (k.cmem[0].size == 0 || k.cmem[0].size & 0xff)
		k.cmem[0].size = (k.cmem[0].size + 0x100) & ~0xff;
	if (!(k.cmem[0].addr = gmalloc(handle, k.cmem[0].size)))
		return -1;
	k.cmem[0].offset = 0;
	for (i = 1; i < GDEV_NVIDIA_CONST_SEGMENT_MAX_COUNT; i++) {
		k.cmem[i].addr = 0;
		k.cmem[i].size = 0;
		k.cmem[i].offset = 0;
	}
	k.cmem_count = GDEV_NVIDIA_CONST_SEGMENT_MAX_COUNT;
	k.param_size = PARAM_SIZE;
	k.param_buf = c0;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 0] = a_addr;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 1] = a_addr >> 32;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 2] = b_addr;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 3] = b_addr >> 32;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 4] = c_addr;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 5] = c_addr >> 32;
	k.param_buf[NVCC_PARAM_OFFSET/4 + 6] = n;

	k.lmem_size = LOCAL_SIZE;
	if (k.lmem_size & 0xf)
		k.lmem_size = (k.lmem_size + 0x10) & ~0xf;
	k.lmem_size_neg = 0; /* just random */
	if (k.lmem_size_neg & 0xf)
		k.lmem_size_neg = (k.lmem_size_neg + 0x10) & ~0xf;
	k.lmem_base = 0x01000000;
	k.smem_size = SHARED_SIZE;
	if (k.smem_size & 0x7f)
		k.smem_size = (k.smem_size + 0x80) & (~0x7f);
	k.smem_base = 0x0;
	
	k.warp_stack_size = (STACK_DEPTH + 0x1000) & (~0xfff);
	
	/* FIXME: per-thread warp size may differ from 32. */
	k.warp_lmem_size = 32 * (k.lmem_size + k.lmem_size_neg) + k.warp_stack_size; 
	
	/* FIXME: the number of active warps may differ from 48. */
	gquery(handle, GDEV_NVIDIA_QUERY_MP_COUNT, (uint64_t *)&mp_count);
	k.lmem_size_total = 48 * mp_count * k.warp_lmem_size;
	k.lmem_size_total = __round_up_pow2(k.lmem_size_total);
	if (!(k.lmem_addr = gmalloc(handle, k.lmem_size_total)))
		return -1;

	k.reg_count = REG_COUNT;
	k.bar_count = BARRIER_COUNT;
	k.grid_id = 1;
	
	k.block_x = n < 16 ? n : 16;
	k.block_y = n < 16 ? n : 16;
	k.block_z = 1;
	k.grid_x = n / k.block_x;
	if (n % k.block_x != 0)
		k.grid_x++;
	k.grid_y = n / k.block_y;
	if (n % k.block_y != 0)
		k.grid_y++;
	k.grid_z = 1;
	
	gmemcpy_to_device(handle, k.code_addr, kcode, k.code_size);
	gmemcpy_to_device(handle, a_addr, a, a_size);
	gmemcpy_to_device(handle, b_addr, b, b_size);
	
	glaunch(handle, &k, &id);
	gsync(handle, id, NULL);
	
	gmemcpy_from_device(handle, c, c_addr, c_size);

	gfree(handle, a_addr);
	gfree(handle, b_addr);
	gfree(handle, c_addr);
	gfree(handle, k.code_addr);
	gfree(handle, k.cmem[0].addr);
	gfree(handle, k.lmem_addr);
	
	gclose(handle);

	i = j = idx = 0;
	while (i < n) {
		while (j < n) {
			idx = i * n + j;
			if (c[idx] != a[idx] + b[idx]) {
				printf("c[%d] = %d\n", idx, c[idx]);
				printf("a[%d]+b[%d] = %d\n", idx, idx, a[idx]+b[idx]);
				return -1;
			}
			j++;
		}
		i++;
	}

	return 0;
}