Skip to content

Thread safety - #1706

Merged
umar456 merged 90 commits into
arrayfire:develfrom
9prady9:thread_safety
May 17, 2017
Merged

umar456 merged 90 commits into
arrayfire:develfrom
9prady9:thread_safety

Conversation

@9prady9

@9prady9 9prady9 commented Jan 10, 2017 •

Copy link
Copy Markdown
Member

Fixes #907
Fixes #1728
Fixes #1754

  • Remove boost::shared_mutex usage in favor of thread local storage for cache management objects.
  • Implement thread_local alternative for OSX Platform Making XCode 8.0 the minimum requirement, which has thread_local support.
  • Change kernel cache management to be thread local storage.
  • Change fft plan caches to use per thread local storage.
  • Maintain per thread active device
  • Unit tests

@pavanky pavanky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having file names as fooManager is a bit weird even if their class names are that way (even weirder when their class names are different).

I suggest simplyfing the naming mechanism and keeping the file names simple. For example:

  • memoryManager.* should just be part of memory.*.
  • interopManager.* should just be graphics.*
  • GfxInteropManager should just be GraphicsManager
  • cublasManager.* should just be cublas.*
  • same with cufft, cusolverDn, cusolverSn, clfft, clblas.

Comment thread src/backend/cpu/platform.cpp Outdated
mVendorId = "Unkown, probably ARM";
cout<< "Unexpected vendor id" <<endl;
mVendorId = "Unkown";
std::cout<< "Unexpected vendor id" << std::endl;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be printed out ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A left over i think, i will remove it.

bool isDoubleSupported(int device)
{
return true;
return DeviceManager::IS_DOUBLE_SUPPORTED;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change from true?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved all(possible) hard coded constants into single location(static data members of DeviceManager class).

flag = true;
}
return 0;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably consider returning number of devices == number of threads.


friend queue& getQueue(int device);

CPUInfo getCPUInfo() const;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where else (outside of platform.cpp) is getCPUInfo going to be used?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably nowhere else. But i can't say we wont in future, may be while checking SSE support availability in hardware when specialising CPU kernels for respective hardware.


IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_MWAITXINTRIN_H_INCLUDED -D_FORCE_INLINES")
ENDIF()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if this is required for gcc 4.x ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment thread src/backend/cuda/cusparseManager.cpp Outdated
: handle(0)
{
CUSPARSE_CHECK(cusparseCreate(&handle));
CUSPARSE_CHECK(cusparseSetStream(handle, cuda::getStream(cuda::getActiveDeviceId())));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be have a function called getActiveStream() so we don't have to repeatedly do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Comment thread src/backend/cuda/memoryManager.cpp Outdated
}
}

}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this split from memory.cpp ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to use the memory manager classes for variable declaration in DeviceManager class, i moved the class declaration into hpp file. Also, I thought it would be consistent with other managers being in their own source files already - *Managers.[hpp|cpp].

Comment thread src/backend/cuda/memoryManager.hpp Outdated
}
};

}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this split from memory.hpp?

Comment thread src/backend/cuda/platform.cpp Outdated
{
cusparseHandles[device].reset(new cusparse::cusparseHandle());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why unique pointers? There's no reason for any of them to be unique pointers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will go through them again. The sections of code that was managing sparse, solve and blas handles was using boost::scoped_ptr earlier, which i replaced with it's std equivalent unique_ptr.

Comment thread src/backend/cuda/platform.hpp Outdated

std::unique_ptr<cusolver::cusolverDnHandle> cusolverHandles[MAX_DEVICES];

std::unique_ptr<cusparse::cusparseHandle> cusparseHandles[MAX_DEVICES];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some unique_ptr while others are not?

@9prady9 9prady9 Jan 10, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases, the respective resource manager class itself uses some information that is initialised during the creation of DeviceManager class which is causing infinite loop. Therefore, for such cases, i am lazily initialising them using unique_ptrs.

9prady9 added 3 commits April 26, 2017 09:58
Add a memory manager stress test.
Also, fixes memory leaks in medfilt and morph unit tests
Disable memory management stress test for CPU backend.
@umar456

umar456 commented Apr 30, 2017

Copy link
Copy Markdown
Member

build arrayfire windows ci

@umar456

umar456 commented Apr 30, 2017 •

Copy link
Copy Markdown
Member

@9prady9 Looks like there are a couple of failures on Windows. Can you check it out?

Edit: Fixed it

@9prady9 9prady9 changed the title [WIP]: Thread safety Thread safety May 1, 2017
@pavanky

pavanky commented May 1, 2017

Copy link
Copy Markdown
Member

build arrayfire windows ci

@pavanky

pavanky commented May 1, 2017

Copy link
Copy Markdown
Member

@umar456 @9prady9 windows is still broken.

@9prady9

9prady9 commented May 1, 2017 •

Copy link
Copy Markdown
Member Author

@pavanky I believe canny's narrowing error is still present in this branch.

Edit: I will look at the other errors.

@pavanky

pavanky commented May 1, 2017

Copy link
Copy Markdown
Member

@9prady9 can you merge from devel?

@9prady9

9prady9 commented May 1, 2017 •

Copy link
Copy Markdown
Member Author

@pavanky Will do and push along with other Windows fixes.
Edit: @umar456 is taking care of it apparently.

@umar456

umar456 commented May 1, 2017

Copy link
Copy Markdown
Member

build arrayfire windows ci

@umar456

umar456 commented May 7, 2017

Copy link
Copy Markdown
Member

build arrayfire linux ci
build arrayfire osx ci
build arrayfire windows ci

@umar456

umar456 commented May 17, 2017

Copy link
Copy Markdown
Member

build arrayfire windows ci

@umar456
umar456 merged commit 2ff37fc into arrayfire:devel May 17, 2017
@mlloreda mlloreda added this to the v3.5.0 milestone May 22, 2017
@9prady9
9prady9 deleted the thread_safety branch June 23, 2017 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants