コード例 #1
0
ファイル: context_test.go プロジェクト: xfong/gocl
func TestContext(t *testing.T) {
	/* Host/device data structures */
	var platform [1]cl.CL_platform_id
	var device [1]cl.CL_device_id
	var context cl.CL_context
	var err cl.CL_int

	var paramValueSize cl.CL_size_t
	var ref_count interface{}
	user_data := []byte("Hello, I am callback")

	/* Access the first installed platform */
	err = cl.CLGetPlatformIDs(1, platform[:], nil)
	if err != cl.CL_SUCCESS {
		t.Errorf("Couldn't find any platforms")
	}

	/* Access the first available device */
	err = cl.CLGetDeviceIDs(platform[0], cl.CL_DEVICE_TYPE_GPU, 1, device[:], nil)
	if err == cl.CL_DEVICE_NOT_FOUND {
		err = cl.CLGetDeviceIDs(platform[0], cl.CL_DEVICE_TYPE_CPU, 1, device[:], nil)
	}
	if err != cl.CL_SUCCESS {
		t.Errorf("Couldn't find any devices")
	}

	/* Create the context */
	context = cl.CLCreateContext(nil, 1, device[:], my_contex_notify, unsafe.Pointer(&user_data), &err)
	if err != cl.CL_SUCCESS {
		t.Errorf("Couldn't create a context")
	}

	/* Determine the reference count */
	err = cl.CLGetContextInfo(context, cl.CL_CONTEXT_REFERENCE_COUNT,
		0, nil, &paramValueSize)

	if err != cl.CL_SUCCESS {
		t.Errorf("Failed to find context %s.\n", "CL_CONTEXT_REFERENCE_COUNT")
	}

	err = cl.CLGetContextInfo(context, cl.CL_CONTEXT_REFERENCE_COUNT,
		paramValueSize, &ref_count, nil)
	if err != cl.CL_SUCCESS {
		t.Errorf("Couldn't read the reference count.")
	}
	t.Logf("Initial reference count: %d\n", ref_count.(cl.CL_uint))

	/* Update and display the reference count */
	cl.CLRetainContext(context)
	cl.CLGetContextInfo(context, cl.CL_CONTEXT_REFERENCE_COUNT,
		paramValueSize, &ref_count, nil)
	t.Logf("Reference count: %d\n", ref_count.(cl.CL_uint))

	cl.CLReleaseContext(context)
	cl.CLGetContextInfo(context, cl.CL_CONTEXT_REFERENCE_COUNT,
		paramValueSize, &ref_count, nil)
	t.Logf("Reference count: %d\n", ref_count.(cl.CL_uint))

	cl.CLReleaseContext(context)
}
コード例 #2
0
ファイル: context.go プロジェクト: xfong/gocl
func (this *context) GetInfo(param_name cl.CL_context_info) (interface{}, error) {
	/* param data */
	var param_value interface{}
	var param_size cl.CL_size_t
	var errCode cl.CL_int

	/* Find size of param data */
	if errCode = cl.CLGetContextInfo(this.context_id, param_name, 0, nil, &param_size); errCode != cl.CL_SUCCESS {
		return nil, fmt.Errorf("GetInfo failure with errcode_ret %d: %s", errCode, cl.ERROR_CODES_STRINGS[-errCode])
	}

	/* Access param data */
	if errCode = cl.CLGetContextInfo(this.context_id, param_name, param_size, &param_value, nil); errCode != cl.CL_SUCCESS {
		return nil, fmt.Errorf("GetInfo failure with errcode_ret %d: %s", errCode, cl.ERROR_CODES_STRINGS[-errCode])
	}

	return param_value, nil
}