static bool allocateTuiMemoryPool(struct tui_mempool *pool, size_t size)
{
	bool ret = false;
	void *tuiMemPool = NULL;

	pr_info("%s %s:%d\n", __func__, __FILE__, __LINE__);
	if (!size) {
		pr_debug("TUI frame buffer: nothing to allocate.");
		return true;
	}

	tuiMemPool = kmalloc(size, GFP_KERNEL);
	if (!tuiMemPool) {
		pr_debug("ERROR Could not allocate TUI memory pool");
	} else if (ksize(tuiMemPool) < size) {
		pr_err("TUI mem pool size too small: req'd=%d alloc'd=%d", size,
		       ksize(tuiMemPool));
		kfree(tuiMemPool);
	} else {
		pool->va = tuiMemPool;
		pool->pa = virt_to_phys(tuiMemPool);
		pool->size = ksize(tuiMemPool);
		ret = true;
	}
	return ret;
}
示例#2
0
static int proc_write(struct file *filp, const char __user *buff,
                      unsigned long len, void *data)
{
    unsigned int page_no = 0, clen = 0;

    if (copy_from_user(&buffer, buff, len))
        return -EFAULT;
    sscanf(buffer, "%u %u", &page_no, &clen);

    if (table[page_no]) {
        used_size -= (unsigned long)ksize(table[page_no]);
        kfree(table[page_no]);
    }
    if (!(table[page_no] = kmalloc(clen, GFP_KERNEL))) {
        printk(KERN_INFO "Error allocating mem for page: %u\n", page_no);
    } else {
        used_size += (unsigned long)ksize(table[page_no]);
    }

    count++;
    sprintf(buffer, "%lu %lu %lu\n", count, used_size, used_size >> 10);

    relay_write(relay, buffer, strlen(buffer));

    return len;
}
示例#3
0
static int stat_open(struct inode *inode, struct file *file)
{
	unsigned size = 1024 + 128 * num_possible_cpus();
	char *buf;
	struct seq_file *m;
	int res;

	
	size += 2 * nr_irqs;

	
	if (size > KMALLOC_MAX_SIZE)
		size = KMALLOC_MAX_SIZE;
	buf = kmalloc(size, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	res = single_open(file, show_stat, NULL);
	if (!res) {
		m = file->private_data;
		m->buf = buf;
		m->size = ksize(buf);
	} else
		kfree(buf);
	return res;
}
示例#4
0
 void SobelTest::testManual1()
 {
     m_operator->setParameter(Sobel::PARAMETER_DATA_FLOW, runtime::Enum(Sobel::MANUAL));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src(new cvsupport::Image("lenna.jpg", cvsupport::Image::GRAYSCALE));
     runtime::DataContainer dst(new cvsupport::Image(1000000));
     runtime::Enum ddepth(1);
     runtime::UInt32 dx(2);
     runtime::UInt32 dy(0);
     runtime::UInt32 ksize(3);
     runtime::Float64 scale(1);
     runtime::Float64 delta(0);
     
     m_operator->setInputData(Sobel::INPUT_SRC, src);
     m_operator->setInputData(Sobel::INPUT_DST, dst);
     m_operator->setParameter(Sobel::PARAMETER_DDEPTH, ddepth);
     m_operator->setParameter(Sobel::PARAMETER_DX, dx);
     m_operator->setParameter(Sobel::PARAMETER_DY, dy);
     m_operator->setParameter(Sobel::PARAMETER_KSIZE, ksize);
     m_operator->setParameter(Sobel::PARAMETER_SCALE, scale);
     m_operator->setParameter(Sobel::PARAMETER_DELTA, delta);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Sobel::OUTPUT_DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("SobelTest_testManual1_dst.png", dstAccess.get<runtime::Image>());
 }
示例#5
0
static int my_init (void) {
	proc_mydev = proc_mkdir(MYDEV,0);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
  proc_hello = proc_create("hello", 0777, proc_mydev, &proc_fops);
#else
  proc_hello = create_proc_entry(HELLO,0,proc_mydev);
  proc_hello->read_proc = read_hello;
  proc_hello->write_proc = write_hello;
#endif

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,29)
  proc_hello->owner = THIS_MODULE;
#endif

	hello_data=(struct proc_hello_data *)
		kmalloc(sizeof(*hello_data),GFP_KERNEL);

	hello_data->proc_hello_value=(char *)
		kmalloc(PROC_HELLO_BUFLEN,GFP_KERNEL);

	hello_data->proc_hello_flag=0;

    // module init message
    printk(KERN_ALERT "2470:10.5a: main initialized!\n");
    printk(KERN_ALERT "2470:10.5a: memory allocated(hello_data) = %d!\n", ksize(hello_data));
    printk(KERN_ALERT "2470:10.5a: memory allocated(hello_data->proc_hello_value) = %d!\n", ksize(hello_data->proc_hello_value));

	return 0;
}
示例#6
0
static int stat_open(struct inode *inode, struct file *file)
{
	unsigned size = 1024 + 128 * num_possible_cpus();
	char *buf;
	struct seq_file *m;
	int res;

	/* minimum size to display an interrupt count : 2 bytes */
	size += 2 * nr_irqs;

	/* don't ask for more than the kmalloc() max size */
	if (size > KMALLOC_MAX_SIZE)
		size = KMALLOC_MAX_SIZE;
	buf = kmalloc(size, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	res = single_open(file, show_stat, NULL);
	if (!res) {
		m = file->private_data;
		m->buf = buf;
		m->size = ksize(buf);
	} else
		kfree(buf);
	return res;
}
示例#7
0
/*
 * Reallocates an existing block of memory, with
 * a new size
 */
void *realloc(void *ptr, size_t size)
{
	size_t org = ksize(ptr);

	kfree(ptr);
	void *ret_val = kalloc(size);
	memcpy(ret_val, ptr, org);
	return ret_val;
}
示例#8
0
    int
    process(const tendrils&, const tendrils&, const cv::Mat& input, cv::Mat& output)
    {

      int kernel = *kernel_;
      cv::Size ksize(2*kernel+1,2*kernel+1); //only odd sizes.
      cv::Mat element = cv::getStructuringElement(*morph_, ksize);
      cv::erode(input,output, element);
      return ecto::OK;
    }
示例#9
0
void kzfree(const void *p)
{
	size_t ks;
	void *mem = (void *)p;

	if (unlikely(ZERO_OR_NULL_PTR(mem)))
		return;
	ks = ksize(mem);
	memset(mem, 0, ks);
	kfree(mem);
}
示例#10
0
文件: km_cdev_dri.c 项目: shijith/lab
static int set_device_buff_size(void *data)
{

	if(BUFF_SIZE)
		kfree(kbuff);
	sscanf((char *)data, "%d", &BUFF_SIZE);
	if(BUFF_SIZE <= 0)
		BUFF_SIZE = 32;
	kbuff = kmalloc(BUFF_SIZE, GFP_KERNEL);
	if(kbuff) {
		printk(KERN_INFO "allocated memory of size %zu\n", ksize(kbuff));
		memset(kbuff, 0, ksize(kbuff));
	} else {
		printk(KERN_WARNING "error allocating memory of size %d\n", BUFF_SIZE);
		BUFF_SIZE = 0;
		return -ENOMEM;
	}

	return BUFF_SIZE;
}
示例#11
0
  bool BlurBlock::run(bool oneShot){
    Mat imgSrc = _myInputs["BLOCK__BLUR_IN_IMG"].get<cv::Mat>(),
      imgOut;

    switch (_myInputs["BLOCK__BLUR_IN_METHOD"].get<int>())
    {
    case 0://Mean
    {
      blur(imgSrc, imgOut, 
        cv::Size(_mySubParams["BLOCK__BLUR_IN_METHOD.Mean.kernel size X"].get<int>(),
        _mySubParams["BLOCK__BLUR_IN_METHOD.Mean.kernel size Y"].get<int>()),
        cv::Point(_mySubParams["BLOCK__BLUR_IN_METHOD.Mean.anchor point X"].get<int>(),
        _mySubParams["BLOCK__BLUR_IN_METHOD.Mean.anchor point Y"].get<int>()),
        cv::BORDER_DEFAULT);
      break;
    }
    case 1://Gaussian
    {
      cv::Size ksize(_mySubParams["BLOCK__BLUR_IN_METHOD.Gaussian.kernel size X"].get<int>(),
        _mySubParams["BLOCK__BLUR_IN_METHOD.Gaussian.kernel size Y"].get<int>());
      if (ksize.width <= 0) ksize.width = 1;
      if (ksize.width % 2 == 0) ksize.width += 1;
      if (ksize.height <= 0) ksize.height = 1;
      if (ksize.height % 2 == 0) ksize.height += 1;

      GaussianBlur(imgSrc, imgOut, ksize,
        _mySubParams["BLOCK__BLUR_IN_METHOD.Gaussian.Sigma X"].get<double>(),
        _mySubParams["BLOCK__BLUR_IN_METHOD.Gaussian.Sigma Y"].get<double>(),
        cv::BORDER_DEFAULT);
      break;
    }
    case 2://Median
    {
      int medianSize = _mySubParams["BLOCK__BLUR_IN_METHOD.Median.kernel size"].get<int>();
      if (medianSize % 2 != 1)
        medianSize += 1;
      medianBlur(imgSrc, imgOut, medianSize);
      break;
    }
    case 3://Bilateral
    {
      bilateralFilter(imgSrc, imgOut, _mySubParams["BLOCK__BLUR_IN_METHOD.Bilateral.Diameter"].get<int>(),
        _mySubParams["BLOCK__BLUR_IN_METHOD.Bilateral.Sigma color"].get<double>(),
        _mySubParams["BLOCK__BLUR_IN_METHOD.Bilateral.Sigma space"].get<double>());
      break;
    }
    default:
      return false;//nothing to do as we don't support this type of operation
      break;
    }
    _myOutputs["BLOCK__BLUR_OUT_IMAGE"] = imgOut;

    return true;
  };
示例#12
0
int ub_core_run(void)
{
	int res;

	struct request_state* req = kmalloc(sizeof(struct request_state), 
		GFP_KERNEL);
	allow_signal(SIGKILL | SIGSTOP);

	if (!req
#ifdef __KERNEL__
		|| ksize(req) < sizeof(struct request_state)
#endif
		)
		return -ENOMEM;
	memset(req, 0, sizeof(struct request_state));
	
	req->len_recvbuf = 4096;
	req->recvbuf = (char*) kmalloc(req->len_recvbuf, GFP_KERNEL);
	if (ksize(req->recvbuf) < req->len_recvbuf)
	{
		printk(KERN_WARNING 
			"[Unbuckle] Asked for a receive buffer of %lu, but got %lu.\n",
			req->len_recvbuf, ksize(req->recvbuf)
		);
		req->len_recvbuf = ksize(req->recvbuf);
	}

	do_kernel_rx_worker(req);

	if (req)
	{
		if (req->recvbuf)
			kfree(req->recvbuf);
		kfree(req);
		req = NULL;
	}
	res = 0;
	return res;
}
/*static bool allocateTuiBuffer(tuiDciMsg_ptr pDci); */
static bool allocateTuiBuffer(tuiDciMsg_ptr pDci)
{
	bool ret = false;
	uint32_t requestedSize = 0;

	if (!pDci) {
		pr_debug("%s(%d): pDci is null\n", __func__, __LINE__);
		return false;
	}

	requestedSize = pDci->cmdNwd.payload.allocSize;
	pr_debug("%s(%d): Requested size=%u\n", __func__, __LINE__,
			requestedSize);

	if (0 == requestedSize) {
		pr_debug("TUI frame buffer: nothing to allocate.");
		ret = true;
	} else {
		tuiFrameBuffer = kmalloc(requestedSize, GFP_KERNEL);

		if (!tuiFrameBuffer) {
			pr_err("Could not allocate TUI frame buffer");
			ret = false;
		} else if (ksize(tuiFrameBuffer) < requestedSize) {
			pr_err("TUI frame buffer allocated size is smaller than required: %d iso %d",
					ksize(tuiFrameBuffer), requestedSize);
			kfree(tuiFrameBuffer);
			ret = false;
		} else {
			pDci->nwdRsp.allocBuffer.pa =
				(void *) virt_to_phys(tuiFrameBuffer);

			pDci->nwdRsp.allocBuffer.size = ksize(tuiFrameBuffer);
			ret = true;
		}
	}

	return ret;
}
示例#14
0
static int expand_corename(struct core_name *cn, int size)
{
	char *corename = krealloc(cn->corename, size, GFP_KERNEL);

	if (!corename)
		return -ENOMEM;

	if (size > core_name_size) /* racy but harmless */
		core_name_size = size;

	cn->size = ksize(corename);
	cn->corename = corename;
	return 0;
}
示例#15
0
文件: mempool.c 项目: 19Dan01/linux
static void poison_element(mempool_t *pool, void *element)
{
	/* Mempools backed by slab allocator */
	if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc)
		__poison_element(element, ksize(element));

	/* Mempools backed by page allocator */
	if (pool->alloc == mempool_alloc_pages) {
		int order = (int)(long)pool->pool_data;
		void *addr = kmap_atomic((struct page *)element);

		__poison_element(addr, 1UL << (PAGE_SHIFT + order));
		kunmap_atomic(addr);
	}
}
示例#16
0
文件: mempool.c 项目: 19Dan01/linux
static void check_element(mempool_t *pool, void *element)
{
	/* Mempools backed by slab allocator */
	if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
		__check_element(pool, element, ksize(element));

	/* Mempools backed by page allocator */
	if (pool->free == mempool_free_pages) {
		int order = (int)(long)pool->pool_data;
		void *addr = kmap_atomic((struct page *)element);

		__check_element(pool, addr, 1UL << (PAGE_SHIFT + order));
		kunmap_atomic(addr);
	}
}
示例#17
0
 void MedianBlurTest::testManual1()
 {
     m_operator->setParameter(MedianBlur::DATA_FLOW, runtime::Enum(MedianBlur::MANUAL));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src(new cvsupport::Image("lenna.jpg", cvsupport::Image::GRAYSCALE));
     runtime::UInt32 ksize(5);
     
     m_operator->setInputData(MedianBlur::SRC, src);
     m_operator->setInputData(MedianBlur::DST, src);
     m_operator->setParameter(MedianBlur::KSIZE, ksize);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(MedianBlur::DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("MedianBlurTest_testManual1_dst.png", dstAccess.get<runtime::Image>());
 }
示例#18
0
static noinline void __init ksize_unpoisons_memory(void)
{
	char *ptr;
	size_t size = 123, real_size = size;

	pr_info("ksize() unpoisons the whole allocated chunk\n");
	ptr = kmalloc(size, GFP_KERNEL);
	if (!ptr) {
		pr_err("Allocation failed\n");
		return;
	}
	real_size = ksize(ptr);
	/* This access doesn't trigger an error. */
	ptr[size] = 'x';
	/* This one does. */
	ptr[real_size] = 'y';
	kfree(ptr);
}
示例#19
0
static __always_inline void *__do_krealloc(const void *p, size_t new_size,
					   gfp_t flags)
{
	void *ret;
	size_t ks = 0;

	if (p)
		ks = ksize(p);

	if (ks >= new_size)
		return (void *)p;

	ret = kmalloc_track_caller(new_size, flags);
	if (ret && p)
		memcpy(ret, p, ks);

	return ret;
}
int __init kcalloc_init(void)
{
    mem_spvm = (char *)kcalloc(2, MEM_VMALLOC_SIZE, GFP_KERNEL);

    if(mem_spvm == NULL )
        printk("<0>kcalloc failed!\n");
    else
    {
        //输出起始地址
        printk("<0>kcalloc successfully! addr = 0x%lx\n",(unsigned long)mem_spvm);
        //输出内存空间大小
        printk("<0>the actual allocated size is : %d\n",(unsigned int)ksize(mem_spvm));
        //输出地址偏移为10的内容
        printk("<0>the content of mem_spvm+10 is : %d\n",*(mem_spvm+10));
        //输出地址偏移为1000的内容
        printk("<0>the content of mem_spvm+1000 is : %d\n",*(mem_spvm+1000));
    }
    return 0;
}
示例#21
0
void *__krealloc(const void *p, size_t new_size, gfp_t flags)
{
	void *ret;
	size_t ks = 0;

	if (unlikely(!new_size))
		return ZERO_SIZE_PTR;

	if (p)
		ks = ksize(p);

	if (ks >= new_size)
		return (void *)p;

	ret = kmalloc_track_caller(new_size, flags);
	if (ret && p)
		memcpy(ret, p, ks);

	return ret;
}
示例#22
0
static ssize_t diag_dbgfs_read_mempool(struct file *file, char __user *ubuf,
						size_t count, loff_t *ppos)
{
	char *buf = NULL;
	int ret = 0;
	unsigned int buf_size;

	buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
	if (ZERO_OR_NULL_PTR(buf)) {
		pr_err("diag: %s, Error allocating memory\n", __func__);
		return -ENOMEM;
	}

	buf_size = ksize(buf);
	ret = scnprintf(buf, buf_size,
		"POOL_TYPE_COPY: [0x%p : 0x%p] count = %d\n"
		"POOL_TYPE_HDLC: [0x%p : 0x%p] count = %d\n"
		"POOL_TYPE_USER: [0x%p : 0x%p] count = %d\n"
		"POOL_TYPE_WRITE_STRUCT: [0x%p : 0x%p] count = %d\n"
		"POOL_TYPE_DCI: [0x%p : 0x%p] count = %d\n",
		driver->diagpool,
		diag_pools_array[POOL_COPY_IDX],
		driver->count,
		driver->diag_hdlc_pool,
		diag_pools_array[POOL_HDLC_IDX],
		driver->count_hdlc_pool,
		driver->diag_user_pool,
		diag_pools_array[POOL_USER_IDX],
		driver->count_user_pool,
		driver->diag_write_struct_pool,
		diag_pools_array[POOL_WRITE_STRUCT_IDX],
		driver->count_write_struct_pool,
		driver->diag_dci_pool,
		diag_pools_array[POOL_DCI_IDX],
		driver->count_dci_pool);

	ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);

	kfree(buf);
	return ret;
}
示例#23
0
文件: main.c 项目: joelding/LDD3
static int kmalloc_init(void)
{
        void *ptr;
	int i;

        printk("kmalloc driver installed.\n");
	/* allocate 10 bytes */
        memptr = ptr = kmalloc(10, GFP_KERNEL);
        printk("ptr %p\n", ptr);

	if (memptr == NULL) {
		printk("failed kmalloc\n");
		return -1;
	}

	printk("before memset\n");
	for (i = 0; i < 10; ++i)
		printk("0x%02x\n", *(unsigned char *)(ptr + i));

	memset(ptr, 0, 10);

	printk("after memset\n");
	for (i = 0; i < 10; ++i)
		printk("0x%02x\n", *(unsigned char *)(ptr + i));

	kfree(ptr);
	memptr = ptr = kzalloc(10, GFP_KERNEL);
	if (memptr == NULL) {
		printk("failed kzalloc\n");
		return -1;
	
	}

	printk("kzalloc\n");
	for (i = 0; i < 10; ++i)
		printk("0x%02x\n", *(unsigned char *)(ptr + i));

	printk("ksize=%d\n", ksize(memptr));

        return 0;
}
示例#24
0
int ub_core_run(void)
{
	int res;
	
	struct request_state* req = (struct request_state*) 
		ALLOCMEM(sizeof(struct request_state), GFP_KERNEL);
#ifdef __KERNEL__
	allow_signal(SIGKILL | SIGSTOP);
#endif
	if (!req
#ifdef __KERNEL__
		|| ksize(req) < sizeof(struct request_state)
#endif
		)
		return -ENOMEM;
	memset(req, 0, sizeof(struct request_state));

	if ((res = udpserver_start(req)) < 0)
	{
#ifdef DEBUG
		PRINTARGS(
#ifdef __KERNEL__
		KERN_ERR 
#endif
		"Something went wrong starting the UDP server %d\n", res);
#endif
		FREEMEM(req);
		return res;
	}
	res = process_slowpath(req);

	udpserver_exit();

	if (req)
	{
		FREEMEM(req);
		req = NULL;
	}

	return res;
}
示例#25
0
文件: util.c 项目: cilynx/dd-wrt
/**
 * krealloc - reallocate memory. The contents will remain unchanged.
 * @p: object to reallocate memory for.
 * @new_size: how many bytes of memory are required.
 * @flags: the type of memory to allocate.
 *
 * The contents of the object pointed to are preserved up to the
 * lesser of the new and old sizes.  If @p is %NULL, krealloc()
 * behaves exactly like kmalloc().  If @size is 0 and @p is not a
 * %NULL pointer, the object pointed to is freed.
 */
void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
	void *ret;
	size_t ks;

	if (unlikely(!new_size)) {
		kfree(p);
		return ZERO_SIZE_PTR;
	}

	ks = ksize(p);
	if (ks >= new_size)
		return (void *)p;

	ret = kmalloc_track_caller(new_size, flags);
	if (ret) {
		memcpy(ret, p, min(new_size, ks));
		kfree(p);
	}
	return ret;
}
示例#26
0
文件: scan.c 项目: 3bsa/linux
static void
iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm *mvm,
				       struct iwl_scan_req_unified_lmac *cmd,
				       struct iwl_mvm_scan_params *params)
{
	memset(cmd, 0, ksize(cmd));
	cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
	cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
	if (params->passive_fragmented)
		cmd->fragmented_dwell =
				params->dwell[IEEE80211_BAND_2GHZ].fragmented;
	cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
	cmd->max_out_time = cpu_to_le32(params->max_out_time);
	cmd->suspend_time = cpu_to_le32(params->suspend_time);
	cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
	cmd->iter_num = cpu_to_le32(1);

	if (iwl_mvm_rrm_scan_needed(mvm))
		cmd->scan_flags |=
			cpu_to_le32(IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED);
}
示例#27
0
文件: nommu.c 项目: rochecr/linux
/*
 * Return the total memory allocated for this pointer, not
 * just what the caller asked for.
 *
 * Doesn't have to be accurate, i.e. may have races.
 */
unsigned int kobjsize(const void *objp)
{
	struct page *page;

	/*
	 * If the object we have should not have ksize performed on it,
	 * return size of 0
	 */
	if (!objp || !virt_addr_valid(objp))
		return 0;

	page = virt_to_head_page(objp);

	/*
	 * If the allocator sets PageSlab, we know the pointer came from
	 * kmalloc().
	 */
	if (PageSlab(page))
		return ksize(objp);

	/*
	 * If it's not a compound page, see if we have a matching VMA
	 * region. This test is intentionally done in reverse order,
	 * so if there's no VMA, we still fall through and hand back
	 * PAGE_SIZE for 0-order pages.
	 */
	if (!PageCompound(page)) {
		struct vm_area_struct *vma;

		vma = find_vma(current->mm, (unsigned long)objp);
		if (vma)
			return vma->vm_end - vma->vm_start;
	}

	/*
	 * The ksize() function is only guaranteed to work for pointers
	 * returned by kmalloc(). So handle arbitrary pointers here.
	 */
	return PAGE_SIZE << compound_order(page);
}
示例#28
0
 void SobelTest::testAllocate0()
 {
     m_operator->setParameter(Sobel::PARAMETER_DATA_FLOW, runtime::Enum(Sobel::ALLOCATE));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src(new cvsupport::Image("lenna.jpg"));
     runtime::Enum ddepth(0);
     runtime::UInt32 dy(2);
     runtime::UInt32 ksize(5);
     runtime::Float64 scale(2);
     
     m_operator->setInputData(Sobel::INPUT_SRC, src);
     m_operator->setParameter(Sobel::PARAMETER_DDEPTH, ddepth);
     m_operator->setParameter(Sobel::PARAMETER_DY, dy);
     m_operator->setParameter(Sobel::PARAMETER_KSIZE, ksize);
     m_operator->setParameter(Sobel::PARAMETER_SCALE, scale);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Sobel::OUTPUT_DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("SobelTest_testAllocate0_dst.png", dstAccess.get<runtime::Image>());
 }
示例#29
0
static ssize_t diag_dbgfs_read_power(struct file *file, char __user *ubuf,
				     size_t count, loff_t *ppos)
{
	char *buf;
	int ret;
	unsigned int buf_size;

	buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
	if (!buf) {
		pr_err("diag: %s, Error allocating memory\n", __func__);
		return -ENOMEM;
	}

	buf_size = ksize(buf);
	ret = scnprintf(buf, buf_size,
		"DCI reference count: %d\n"
		"DCI copy count: %d\n"
		"DCI Client Count: %d\n\n"
		"Memory Device reference count: %d\n"
		"Memory Device copy count: %d\n"
		"Logging mode: %d\n\n"
		"Wakeup source active count: %lu\n"
		"Wakeup source relax count: %lu\n\n",
		driver->dci_ws.ref_count,
		driver->dci_ws.copy_count,
		driver->num_dci_client,
		driver->md_ws.ref_count,
		driver->md_ws.copy_count,
		driver->logging_mode,
		driver->diag_dev->power.wakeup->active_count,
		driver->diag_dev->power.wakeup->relax_count);

	ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);

	kfree(buf);
	return ret;
}
void time_gaussian( const std::vector<carp::record_t>& pool, const std::vector<int>& sizes )
{
    carp::Timing timing("gaussian blur");

    for ( auto & size : sizes ) {
        cv::Size ksize(size, size+4);

        double gaussX = 7.;
        double gaussY = 9.;

        for ( auto & item : pool ) {
            cv::Mat cpu_gray;

            cv::cvtColor( item.cpuimg(), cpu_gray, CV_RGB2GRAY );
            cpu_gray.convertTo( cpu_gray, CV_32F, 1.0/255. );

            cv::Mat cpu_result, gpu_result, pen_result;
            std::chrono::duration<double> elapsed_time_cpu, elapsed_time_gpu_p_copy, elapsed_time_gpu_nocopy, elapsed_time_pencil;

            {
                const auto cpu_start = std::chrono::high_resolution_clock::now();
                cv::GaussianBlur( cpu_gray, cpu_result, ksize, gaussX, gaussY, cv::BORDER_REPLICATE );
                const auto cpu_end = std::chrono::high_resolution_clock::now();
                elapsed_time_cpu = cpu_end - cpu_start;
                //Free up resources
            }
            {
                const auto gpu_copy_start = std::chrono::high_resolution_clock::now();
                cv::ocl::oclMat src(cpu_gray);
                cv::ocl::oclMat dst;
                const auto gpu_start = std::chrono::high_resolution_clock::now();
                cv::ocl::GaussianBlur( src, dst, ksize, gaussX, gaussY, cv::BORDER_REPLICATE );
                const auto gpu_end = std::chrono::high_resolution_clock::now();
                gpu_result = dst;
                const auto gpu_copy_end = std::chrono::high_resolution_clock::now();
                elapsed_time_gpu_p_copy = gpu_copy_end - gpu_copy_start;
                elapsed_time_gpu_nocopy = gpu_end      - gpu_start;
                //Free up resources
            }
            {
                cv::Mat kernel_x = cv::getGaussianKernel(ksize.width , gaussX, CV_32F);
                cv::Mat kernel_y = cv::getGaussianKernel(ksize.height, gaussY, CV_32F);

                pen_result.create( cpu_gray.size(), CV_32F );

                const auto pencil_start = std::chrono::high_resolution_clock::now();
                pencil_gaussian( cpu_gray.rows, cpu_gray.cols, cpu_gray.step1(), cpu_gray.ptr<float>()
                               , kernel_x.rows, kernel_x.ptr<float>()
                               , kernel_y.rows, kernel_y.ptr<float>()
                               , pen_result.ptr<float>()
                               );
                const auto pencil_end = std::chrono::high_resolution_clock::now();
                elapsed_time_pencil = pencil_end - pencil_start;
                //Free up resources
            }
            // Verifying the results
            if ( (cv::norm( cpu_result - gpu_result ) > 0.01) ||
                 (cv::norm( cpu_result - pen_result) > 0.01) )
            {
                cv::Mat gpu_result8;
                cv::Mat cpu_result8;
                cv::Mat pen_result8;
                cv::Mat diff8;

                gpu_result.convertTo( gpu_result8, CV_8UC1, 255. );
                cpu_result.convertTo( cpu_result8, CV_8UC1, 255. );
                pen_result.convertTo( pen_result8, CV_8UC1, 255. );
                cv::Mat absdiff = cv::abs(pen_result - cpu_result);
                absdiff.convertTo( diff8, CV_8UC1, 255. );

                cv::imwrite( "gpu_gaussian.png", gpu_result8 );
                cv::imwrite( "cpu_gaussian.png", cpu_result8 );
                cv::imwrite( "pencil_gaussian.png", pen_result8 );
                cv::imwrite( "diff_gaussian.png", diff8 );

                throw std::runtime_error("The GPU results are not equivalent with the CPU results.");
            }

            timing.print( elapsed_time_cpu, elapsed_time_gpu_p_copy, elapsed_time_gpu_nocopy, elapsed_time_pencil );
        }
    }
}