Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
clfMemory.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include <Base/Common/BIASpragma.hh>
26 #include <OpenCLFramework/clfMemory.hh>
27 #include <OpenCLFramework/clfException.hh>
28 
29 namespace BIAS {
30 
31  clfMemory::clfMemory(cl::Context *context, cl::CommandQueue *queue) {
32  context_ = context;
33  queue_ = queue;
34  size_ = 0;
35  initialized_ = false;
36  sharedGL_ = false;
37  glid_ = 0;
38  }
39 
41  }
42 
43  cl::Memory& clfMemory::memory() {
44  return (cl::Memory&)buffer_;
45  }
46 
47  unsigned int clfMemory::GLId() {
48  if (!sharedGL_) {
49  THROW_CL_EXCEPTION(cl::Error(-100, "This is not a gl shared buffer"));
50  }
51  return glid_;
52  }
53 
54  void clfMemory::UnMap(void *data) {
55  try {
56  queue_->enqueueUnmapMemObject(memory(), data);
57  } catch (cl::Error &error) {
58  THROW_CL_EXCEPTION(error);
59  }
60  }
61 
63  cl_mem_flags data;
64  buffer_.getInfo(CL_MEM_FLAGS, &data);
65  return data & CL_MEM_READ_ONLY;
66  }
68  cl_mem_flags data;
69  buffer_.getInfo(CL_MEM_FLAGS, &data);
70  return data & CL_MEM_WRITE_ONLY;
71  }
72 
73  int clfMemory::DetermineMemFlags_(bool readonly, bool writeonly, const void *hostptr, bool copy) {
74  int cl_mem_flags = 0;
75  if (readonly && writeonly) {
76  BIASWARN("trying to create buffer read-only and write-only. fail");
77  } else if (readonly) {
78  cl_mem_flags |= CL_MEM_READ_ONLY;
79  } else if (writeonly) {
80  cl_mem_flags |= CL_MEM_WRITE_ONLY;
81  } else {
82  cl_mem_flags |= CL_MEM_READ_WRITE;
83  }
84  if (hostptr != NULL) {
85  if (copy) {
86  cl_mem_flags |= CL_MEM_COPY_HOST_PTR;
87  } else {
88  cl_mem_flags |= CL_MEM_USE_HOST_PTR;
89  }
90  }
91  return cl_mem_flags;
92  }
93 
94 
95 }
clfMemory(cl::Context *context, cl::CommandQueue *queue)
Definition: clfMemory.cpp:31
unsigned int glid_
Definition: clfMemory.hh:61
void UnMap(void *data)
Definition: clfMemory.cpp:54
int DetermineMemFlags_(bool readonly, bool writeonly, const void *hostptr=NULL, bool copy=false)
Definition: clfMemory.cpp:73
cl::Context * context_
Definition: clfMemory.hh:54
cl::CommandQueue * queue_
Definition: clfMemory.hh:55
bool IsWriteOnly()
Definition: clfMemory.cpp:67
unsigned int GLId()
Definition: clfMemory.cpp:47
bool IsReadOnly()
Definition: clfMemory.cpp:62
virtual ~clfMemory()
Definition: clfMemory.cpp:40
cl::Memory & memory()
Definition: clfMemory.cpp:43
cl::Memory buffer_
Definition: clfMemory.hh:56
unsigned int size_
Definition: clfMemory.hh:58