Exemplo n.º 1
0
/*
   DESCRIPTION
     Constructor for the EnvImpl class.

   PARAMETERS:
     drvName                driver name
     charset                charset id
     ncharset               ncharset id

   RETURNS:
     nothing

   NOTES:

*/
EnvImpl::EnvImpl( const string &drvName,
                  unsigned int charset,
                  unsigned int ncharset )

try : envh_(NULL), poolMax_(kPoolMax), poolMin_(kPoolMin),
      poolIncrement_(kPoolIncrement), poolTimeout_(kPoolTimeout),
      externalAuth_(false),  stmtCacheSize_(kStmtCacheSize), drvName_(drvName),
      charset_ ( charset ), ncharset_ ( ncharset )
{

  sword rc = OCIEnvNlsCreate (&envh_, OCI_THREADED | OCI_OBJECT, NULL, NULL,
                              NULL, NULL, 0, NULL, charset, ncharset);

  if (rc)
  {
    if (envh_)
      ociCallEnv(rc, envh_);
    else
      throw ExceptionImpl(DpiErrNoEnv);
  }

  DateTimeArrayImpl::initBaseDate ( envh_ ) ;
}

catch (...)
{
  cleanup();
  throw;
}
EnvImpl::EnvImpl()

try : envh_(NULL), poolMax_(kPoolMax), poolMin_(kPoolMin),
      poolIncrement_(kPoolIncrement), poolTimeout_(kPoolTimeout),
      externalAuth_(false),  stmtCacheSize_(kStmtCacheSize)
{

  sword rc = OCIEnvNlsCreate (&envh_, OCI_THREADED | OCI_OBJECT, NULL, NULL,
                              NULL, NULL, 0, NULL, DPI_AL32UTF8, DPI_AL32UTF8);

  if (rc)
  {
    if (envh_)
      ociCallEnv(rc, envh_);
    else
      throw ExceptionImpl(DpiErrNoEnv);
  }

  DateTimeArrayImpl::initBaseDate ( envh_ ) ;
}

catch (...)
{
  cleanup();
  throw;
}
Exemplo n.º 3
0
	void HlbvhStrategy::QueryOcclusion(std::uint32_t queueidx, Calc::Buffer const* rays, Calc::Buffer const* numrays, std::uint32_t maxrays, Calc::Buffer* hits, Calc::Event const* waitevent, Calc::Event** event) const
	{
		// Check if we can allocate enough stack memory
		if (maxrays >= kMaxBatchSize)
		{
			throw ExceptionImpl("hlbvh accelerator max batch size exceeded");
		}

		auto& func = m_gpudata->occlude_indirect_func;

		// Set args
		int arg = 0;
		int offset = 0;

		func->SetArg(arg++, m_bvh->GetGpuData().nodes);
		func->SetArg(arg++, m_bvh->GetGpuData().sorted_bounds);
		func->SetArg(arg++, m_gpudata->vertices);
		func->SetArg(arg++, m_gpudata->faces);
		func->SetArg(arg++, m_gpudata->shapes);
		func->SetArg(arg++, rays);
		func->SetArg(arg++, sizeof(offset), &offset);
		func->SetArg(arg++, numrays);
		func->SetArg(arg++, hits);
		func->SetArg(arg++, m_gpudata->stack);

		size_t localsize = kWorkGroupSize;
		size_t globalsize = ((maxrays + kWorkGroupSize - 1) / kWorkGroupSize) * kWorkGroupSize;

		m_device->Execute(func, queueidx, globalsize, localsize, event);
	}
Exemplo n.º 4
0
/*
  DESCRIPTION
    To obtain Oracle Client Library (OCI) version

  PARAMETERS
    majorv
    minorv
    patchv
    portv
    portUpdv

  RETURNS
    -NONE-

  NOTES:
    The values will map as Oracle Version like 12.1.0.2.0 - five component
    version of Oracle Client Library
*/
void Common::clientVersion ( int *majorv, int *minorv, int *patchv,
                                int *portv, int *portUpdv )
{
  if ( !majorv || !minorv || !patchv || !portv || !portUpdv )
    throw ExceptionImpl ( DpiErrNullValue );

  OCIClientVersion ( majorv, minorv, patchv, portv, portUpdv );
}
Exemplo n.º 5
0
/*
  NAME
    getDateTimeArray

  DESCRIPTION
    To obtain an DPI class which represents date/timestamp as descriptor
    array

  RETURNS:
    DateTimeArray *  -

  NOTE:
    DatetimeArray uses error object created in StmtImpl instead of creating
    separate one, this is ok, as the date/timestamp will be part of SQL
    statement execution only.
*/
DateTimeArray* EnvImpl::getDateTimeArray (OCIError *errh) const
{

  DateTimeArray *dtmarr = new DateTimeArrayImpl ( envh_, errh, this ) ;
  if( !dtmarr )
  {
    throw ExceptionImpl ( DpiErrMemAllocFail ) ;
  }
  return dtmarr;
}
Exemplo n.º 6
0
static void ociCallCommon(sword rc, void *handle, ub4 errType)
{
  if (!rc)
    return;

  OraText ociErrorMsg[OCI_ERROR_MAXMSG_SIZE];
  sb4     ociErrorNo = 0;
  memset(ociErrorMsg, 0, OCI_ERROR_MAXMSG_SIZE);

  rc = OCIErrorGet(handle, 1, NULL, &ociErrorNo, ociErrorMsg,
                   OCI_ERROR_MAXMSG_SIZE-1, errType);
  if (rc)
    throw ExceptionImpl(DpiErrUnkOciError);
  else
  {
    ociErrorMsg[strlen((char*)ociErrorMsg)-1]=0; //strip off newline
    throw ExceptionImpl("ORA", ociErrorNo, (const char *)ociErrorMsg);
  }
}
Exemplo n.º 7
0
const char *StringPimpl::c_str() const throw(Exception &)
{
	try
	{
		return m_pimpl->proxy.c_str();
	}
	catch(Exception &e)
	{
		throw ExceptionImpl(e.what());
	}
}
Exemplo n.º 8
0
bool StringPimpl::empty() const throw(Exception &) 
{
	try
	{
		return m_pimpl->proxy.empty();
	}
	catch(std::exception &e)
	{
		throw ExceptionImpl(e.what());
	}
}
Exemplo n.º 9
0
StringPimpl::StringPimpl(const StringPimpl& stringPimpl)
	: m_pimpl(0)
{	
	try
	{
		init(stringPimpl.c_str());
	}
	catch(std::exception &e)
	{
		throw ExceptionImpl(e.what());
	}
}
Exemplo n.º 10
0
StringPimpl::StringPimpl(const char * const stringPimpl) throw(Exception &)
	: m_pimpl(0)
{
	try
	{
		init(stringPimpl);
	}
	catch(std::exception &e)
	{
		throw ExceptionImpl(e.what());
	}
}
Exemplo n.º 11
0
StringPimpl::StringPimpl() throw(Exception &)
	: m_pimpl(0)
{
	try
	{
		m_pimpl = new StringPrivate;
	}
	catch(std::exception &e)
	{
		throw ExceptionImpl(e.what());
	}
}
Exemplo n.º 12
0
void StringPimpl::init(const char * const stringPimpl)
{
	if(stringPimpl == 0)
	{
		logging("Error trying to put 0 into a string");
		throw ExceptionImpl("Error in StringPimpl::init, trying to put 0 into a string");
	}
	else
	{
		delete m_pimpl;
		m_pimpl = new StringPrivate;
		m_pimpl->proxy = stringPimpl;
	}
}
    Mesh::Mesh(float const* vertices, int vnum, int vstride,
        int const* vidx, int vistride,
        int const* nfaceverts,
        int nfaces)
        : puretriangle_(true)
    {
        // Handle vertices
        // Allocate space in advance
        vertices_.resize(vnum);
        // Calculate vertex stride, assume dense packing if non passed
        vstride = (vstride == 0) ? (3 * sizeof(float)) : vstride;
        // Allocate space for faces
        faces_.resize(nfaces);

        // Load vertices
#pragma omp parallel for
        for (int i = 0; i < vnum; ++i)
        {
            float const* current = (float const*)((char*)vertices + i*vstride);

            float3 temp;
            temp.x = current[0];
            temp.y = current[1];
            temp.z = current[2];

            vertices_[i] = temp;
        }

        // If mesh consists of triangles only apply parallel loading
        if (nfaceverts == nullptr)
        {
            puretriangle_ = true;

            int istride = (vistride == 0) ? (3 * sizeof(int)) : vistride;

#pragma omp parallel for
            for (int i = 0; i < nfaces; ++i)
            {
                faces_[i].i0 = *((int const*)((char const*)vidx + i * istride));
                faces_[i].i1 = *((int const*)((char const*)vidx + i * istride + sizeof(int)));
                faces_[i].i2 = *((int const*)((char const*)vidx + i * istride + 2 * sizeof(int)));
                faces_[i].type_ = FaceType::TRIANGLE;
            }
        }
        // Otherwise execute serially
        else
        {
            char const* vidxptr = (char const*)vidx;

            for (int i = 0; i < nfaces; ++i)
            {
                // Triangle case
                if (nfaceverts[i] == 3)
                {
                    faces_[i].i0 = *((int const*)(vidxptr));
                    faces_[i].i1 = *((int const*)(vidxptr + sizeof(int)));
                    faces_[i].i2 = *((int const*)(vidxptr + 2 * sizeof(int)));
                    faces_[i].type_ = FaceType::TRIANGLE;

                    // Goto next primitive
                    vidxptr += (vistride == 0) ? (3 * sizeof(int)) : vistride;
                }
                // Quad case
                else if (nfaceverts[i] == 4)
                {
                    faces_[i].i0 = *((int const*)(vidxptr));
                    faces_[i].i1 = *((int const*)(vidxptr + sizeof(int)));
                    faces_[i].i2 = *((int const*)(vidxptr + 2 * sizeof(int)));
                    faces_[i].i3 = *((int const*)(vidxptr + 3 * sizeof(int)));
                    faces_[i].type_ = FaceType::QUAD;

                    puretriangle_ = false;

                    // Goto next primitive
                    vidxptr += (vistride == 0) ? (4 * sizeof(int)) : vistride;
                }
                else
                {
                    throw ExceptionImpl("Wrong number of vertices per face");
                }
            }
        }
    }
    void IntersectorShortStack::Process(World const& world)
    {

        // If something has been changed we need to rebuild BVH
        if (!m_bvh || world.has_changed() || world.GetStateChange() != ShapeImpl::kStateChangeNone)
        {
            if (m_bvh)
            {
                m_device->DeleteBuffer(m_gpudata->bvh);
                m_device->DeleteBuffer(m_gpudata->vertices);
            }

            // Check if we can allocate enough stack memory
            Calc::DeviceSpec spec;
            m_device->GetSpec(spec);
            if (spec.max_alloc_size <= kMaxBatchSize * kMaxStackSize * sizeof(int))
            {
                throw ExceptionImpl("fatbvh accelerator can't allocate enough stack memory, try using bvh instead");
            }

            int numshapes = (int)world.shapes_.size();
            int numvertices = 0;
            int numfaces = 0;

            // This buffer tracks mesh start index for next stage as mesh face indices are relative to 0
            std::vector<int> mesh_vertices_start_idx(numshapes);
            std::vector<int> mesh_faces_start_idx(numshapes);

            auto builder = world.options_.GetOption("bvh.builder");
            auto splits = world.options_.GetOption("bvh.sah.use_splits");
            auto maxdepth = world.options_.GetOption("bvh.sah.max_split_depth");
            auto overlap = world.options_.GetOption("bvh.sah.min_overlap");
            auto tcost = world.options_.GetOption("bvh.sah.traversal_cost");
            auto node_budget = world.options_.GetOption("bvh.sah.extra_node_budget");
            auto nbins = world.options_.GetOption("bvh.sah.num_bins");

            bool use_sah = false;
            bool use_splits = false;
            int max_split_depth = maxdepth ? (int)maxdepth->AsFloat() : 10;
            int num_bins = nbins ? (int)nbins->AsFloat() : 64;
            float min_overlap = overlap ? overlap->AsFloat() : 0.05f;
            float traversal_cost = tcost ? tcost->AsFloat() : 10.f;
            float extra_node_budget = node_budget ? node_budget->AsFloat() : 0.5f;

            if (builder && builder->AsString() == "sah")
            {
                use_sah = true;
            }

            if (splits && splits->AsFloat() > 0.f)
            {
                use_splits = true;
            }

            m_bvh.reset(use_splits ?
                new SplitBvh(traversal_cost, num_bins, max_split_depth, min_overlap, extra_node_budget) :
                new Bvh(traversal_cost, num_bins, use_sah)
            );

            // Partition the array into meshes and instances
            std::vector<Shape const*> shapes(world.shapes_);

            auto firstinst = std::partition(shapes.begin(), shapes.end(),
                [&](Shape const* shape)
            {
                return !static_cast<ShapeImpl const*>(shape)->is_instance();
            });

            // Count the number of meshes
            int nummeshes = (int)std::distance(shapes.begin(), firstinst);
            // Count the number of instances
            int numinstances = (int)std::distance(firstinst, shapes.end());

            for (int i = 0; i < nummeshes; ++i)
            {
                Mesh const* mesh = static_cast<Mesh const*>(shapes[i]);

                mesh_faces_start_idx[i] = numfaces;
                mesh_vertices_start_idx[i] = numvertices;

                numfaces += mesh->num_faces();
                numvertices += mesh->num_vertices();
            }

            for (int i = nummeshes; i < nummeshes + numinstances; ++i)
            {
                Instance const* instance = static_cast<Instance const*>(shapes[i]);
                Mesh const* mesh = static_cast<Mesh const*>(instance->GetBaseShape());

                mesh_faces_start_idx[i] = numfaces;
                mesh_vertices_start_idx[i] = numvertices;

                numfaces += mesh->num_faces();
                numvertices += mesh->num_vertices();
            }


            // We can't avoild allocating it here, since bounds aren't stored anywhere
            std::vector<bbox> bounds(numfaces);

            // We handle meshes first collecting their world space bounds
#pragma omp parallel for
            for (int i = 0; i < nummeshes; ++i)
            {
                Mesh const* mesh = static_cast<Mesh const*>(shapes[i]);

                for (int j = 0; j < mesh->num_faces(); ++j)
                {
                    // Here we directly get world space bounds
                    mesh->GetFaceBounds(j, false, bounds[mesh_faces_start_idx[i] + j]);
                }
            }

            // Then we handle instances. Need to flatten them into actual geometry.
#pragma omp parallel for
            for (int i = nummeshes; i < nummeshes + numinstances; ++i)
            {
                Instance const* instance = static_cast<Instance const*>(shapes[i]);
                Mesh const* mesh = static_cast<Mesh const*>(instance->GetBaseShape());

                // Instance is using its own transform for base shape geometry
                // so we need to get object space bounds and transform them manually
                matrix m, minv;
                instance->GetTransform(m, minv);

                for (int j = 0; j < mesh->num_faces(); ++j)
                {
                    bbox tmp;
                    mesh->GetFaceBounds(j, true, tmp);
                    bounds[mesh_faces_start_idx[i] + j] = transform_bbox(tmp, m);
                }
            }

            m_bvh->Build(&bounds[0], numfaces);

#ifdef RR_PROFILE
            m_bvh->PrintStatistics(std::cout);
#endif

            // Check if the tree height is reasonable
            if (m_bvh->GetHeight() >= kMaxStackSize)
            {
                m_bvh.reset(nullptr);
                throw ExceptionImpl("fatbvh accelerator can cause stack overflow for this scene, try using bvh instead");
            }

            FatNodeBvhTranslator translator;
            translator.Process(*m_bvh);

            // Update GPU data

            // Create vertex buffer
            {
                // Vertices
                m_gpudata->vertices = m_device->CreateBuffer(numvertices * sizeof(float3), Calc::BufferType::kRead);

                // Get the pointer to mapped data
                float3* vertexdata = nullptr;
                Calc::Event* e = nullptr;

                m_device->MapBuffer(m_gpudata->vertices, 0, 0, numvertices * sizeof(float3), Calc::MapType::kMapWrite, (void**)&vertexdata, &e);

                e->Wait();
                m_device->DeleteEvent(e);

                // Here we need to put data in world space rather than object space
                // So we need to get the transform from the mesh and multiply each vertex
                matrix m, minv;

#pragma omp parallel for
                for (int i = 0; i < nummeshes; ++i)
                {
                    // Get the mesh
                    Mesh const* mesh = static_cast<Mesh const*>(shapes[i]);
                    // Get vertex buffer of the current mesh
                    float3 const* myvertexdata = mesh->GetVertexData();
                    // Get mesh transform
                    mesh->GetTransform(m, minv);

                    //#pragma omp parallel for
                    // Iterate thru vertices multiply and append them to GPU buffer
                    for (int j = 0; j < mesh->num_vertices(); ++j)
                    {
                        vertexdata[mesh_vertices_start_idx[i] + j] = transform_point(myvertexdata[j], m);
                    }
                }

#pragma omp parallel for
                for (int i = nummeshes; i < nummeshes + numinstances; ++i)
                {
                    Instance const* instance = static_cast<Instance const*>(shapes[i]);
                    // Get the mesh
                    Mesh const* mesh = static_cast<Mesh const*>(instance->GetBaseShape());
                    // Get vertex buffer of the current mesh
                    float3 const* myvertexdata = mesh->GetVertexData();
                    // Get mesh transform
                    instance->GetTransform(m, minv);

                    //#pragma omp parallel for
                    // Iterate thru vertices multiply and append them to GPU buffer
                    for (int j = 0; j < mesh->num_vertices(); ++j)
                    {
                        vertexdata[mesh_vertices_start_idx[i] + j] = transform_point(myvertexdata[j], m);
                    }
                }

                m_device->UnmapBuffer(m_gpudata->vertices, 0, vertexdata, &e);
                e->Wait();
                m_device->DeleteEvent(e);
            }

            // Create face buffer
            {
                
                // This number is different from the number of faces for some BVHs 
                auto numindices = m_bvh->GetNumIndices();
                std::vector<FatNodeBvhTranslator::Face> facedata(numindices);

                // Here the point is to add mesh starting index to actual index contained within the mesh,
                // getting absolute index in the buffer.
                // Besides that we need to permute the faces accorningly to BVH reordering, whihc
                // is contained within bvh.primids_
                int const* reordering = m_bvh->GetIndices();
                for (int i = 0; i < numindices; ++i)
                {
                    int indextolook4 = reordering[i];

                    // We need to find a shape corresponding to current face
                    auto iter = std::upper_bound(mesh_faces_start_idx.cbegin(), mesh_faces_start_idx.cend(), indextolook4);

                    // Find the index of the shape
                    int shapeidx = static_cast<int>(std::distance(mesh_faces_start_idx.cbegin(), iter) - 1);

                    // Get the mesh directly or out of instance
                    Mesh const* mesh = nullptr;
                    if (shapeidx < nummeshes)
                    {
                        mesh = static_cast<Mesh const*>(shapes[shapeidx]);
                    }
                    else
                    {
                        mesh = static_cast<Mesh const*>(static_cast<Instance const*>(shapes[shapeidx])->GetBaseShape());
                    }

                    // Get vertex buffer of the current mesh
                    Mesh::Face const* myfacedata = mesh->GetFaceData();
                    // Find face idx
                    int faceidx = indextolook4 - mesh_faces_start_idx[shapeidx];
                    // Find mesh start idx
                    int mystartidx = mesh_vertices_start_idx[shapeidx];

                    // Copy face data to GPU buffer
                    facedata[i].idx[0] = myfacedata[faceidx].idx[0] + mystartidx;
                    facedata[i].idx[1] = myfacedata[faceidx].idx[1] + mystartidx;
                    facedata[i].idx[2] = myfacedata[faceidx].idx[2] + mystartidx;

                    facedata[i].shapeidx = shapes[shapeidx]->GetId();
                    facedata[i].shape_mask = shapes[shapeidx]->GetMask();
                    facedata[i].id = faceidx;
                }

                translator.InjectIndices(&facedata[0]);
            }

            // Copy translated nodes first
            m_gpudata->bvh = m_device->CreateBuffer(translator.nodes_.size() * sizeof(FatNodeBvhTranslator::Node), Calc::BufferType::kRead, &translator.nodes_[0]);

            // Stack
            m_gpudata->stack = m_device->CreateBuffer(kMaxBatchSize*kMaxStackSize, Calc::BufferType::kWrite);

            // Make sure everything is commited
            m_device->Finish(0);
        }
    }
Exemplo n.º 15
0
void TestCases::conductTesting()
{
	if(m_testFileAdded && m_aimlFileAdded && m_aimlGraphCreated)
	{
		try 
		{
			if(m_testValidation && (!m_testSchema.empty()))
			{
				string SchemaLoc = "http://alicebot.org/2001/AIML-1.0.1 " + m_testSchema;

				m_testParser->setDoSchema(true);
				//m_testParser->setDoValidation(true);    // optional.
				m_testParser->setDoNamespaces(true);    // optional
				m_testParser->setExternalSchemaLocation(SchemaLoc.c_str());
			}
			else
			{
				m_testParser->setDoSchema(false);
				//m_testParser->setDoValidation(false);    // optional.
				m_testParser->setDoNamespaces(false);    // optional
			}

			typedef map<string, bool>::iterator I;

			for(I i = m_filesGraphed.begin(); i != m_filesGraphed.end(); ++i)
			{
				if(i->second == false)
				{
					cout << i->first << " has not been added to graph yet"; 
					m_testParser->parse((i->first).c_str());
					i->second = true;
				}
				else
				{	//Do nothing
					cout << i->first << " has been added to the graph already";
					cout << "Just returning, without doing anything";
				}
			}
		}
		catch (const XMLException& toCatch) 
		{
			Transcode message(toCatch.getMessage());
			string msg("XMLException: " + message.getString());
			cout << msg << endl;
			throw ExceptionImpl(msg.c_str());
		}
		catch (const SAXParseException& toCatch) 
		{
			Transcode message(toCatch.getMessage());
			string msg("SAXParseException: " + message.getString());
			cout << msg << endl;
			throw ExceptionImpl(msg.c_str());
		}
		
	}
	else
	{
		throw ExceptionImpl("You need to add a test file, at least one aiml File,"
			                " and create the aiml graph");
	}

}